Hi
> In fact the annotation can cause a test to succeed when it should fail. > If the NPE occurs too early in the test, the test will be marked as > successful. > If you want to ensure that the NPE only occurs in the last statement > of the test case, then drop the expected qualifier and use the fail() > call at the end of the test case. Ok to avoid that I modified all tests that use annotation. I wrapped the code that precedes the invocation to method under test with a try-catch block and I thrown a fail assertion if there are some NPE. In that way I'm sure that the NPE is thown from the method under test. Thanks for suggestion Ciao -- Marco Speranza <marcosperanza@ <marco.speranz...@gmail.com>apache.org> Google Code: http://code.google.com/u/marco.speranza79/ 2012/2/15 sebb <seb...@gmail.com> > On 14 February 2012 22:42, <marcospera...@apache.org> wrote: > > Author: marcosperanza > > Date: Tue Feb 14 22:42:19 2012 > > New Revision: 1244252 > > > > URL: http://svn.apache.org/viewvc?rev=1244252&view=rev > > Log: > > fixed english mistakes > > fixed format error > > upgraded developer section > > > > Modified: > > commons/sandbox/graph/trunk/pom.xml > > > > commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java > > > > commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java > > > > commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/AStarTestCase.java > > > > commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/BellmannFordTestCase.java > > > > commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java > > > > commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/FloydWarshallTestCase.java > > > > Modified: commons/sandbox/graph/trunk/pom.xml > > URL: > http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/pom.xml?rev=1244252&r1=1244251&r2=1244252&view=diff > > > ============================================================================== > > --- commons/sandbox/graph/trunk/pom.xml (original) > > +++ commons/sandbox/graph/trunk/pom.xml Tue Feb 14 22:42:19 2012 > > @@ -53,6 +53,11 @@ > > <email>jason AT zenplex DOT com</email> > > </developer> > > <developer> > > + <name>Marco Speranza</name> > > + <id>marcosperanza</id> > > + <email>marcosperanza AT apache DOT org</email> > > + </developer> > > + <developer> > > <name>Oliver Heger</name> > > <id>oheger</id> > > <email>oheger AT apache DOT org</email> > > @@ -74,10 +79,6 @@ > > <email>squarcel AT dia DOT uniroma3 DOT it</email> > > </contributor> > > <contributor> > > - <name>Marco Speranza</name> > > - <email>marco DOT speranza79 AT gmail DOT com</email> > > - </contributor> > > - <contributor> > > <name>Matteo Moci</name> > > <email>mox601 AT gmail DOT com</email> > > </contributor> > > > > Modified: > commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java > > URL: > http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java?rev=1244252&r1=1244251&r2=1244252&view=diff > > > ============================================================================== > > --- > commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java > (original) > > +++ > commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/DefaultTargetSourceSelector.java > Tue Feb 14 22:42:19 2012 > > @@ -105,10 +105,13 @@ final class DefaultTargetSourceSelector< > > { > > if ( !source.equals( target ) ) > > { > > - try{ > > + try > > + { > > WeightedPath<V, WE, W> weightedPath = > predecessors.buildPath( source, target ); > > allVertexPairsShortestPath.addShortestPath( source, > target, weightedPath ); > > - }catch (PathNotFoundException e) { > > + } > > + catch ( PathNotFoundException e ) > > + { > > continue; > > } > > } > > > > Modified: > commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java > > URL: > http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java?rev=1244252&r1=1244251&r2=1244252&view=diff > > > ============================================================================== > > --- > commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java > (original) > > +++ > commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/flow/EdmondsKarpTestCase.java > Tue Feb 14 22:42:19 2012 > > @@ -49,7 +49,7 @@ public class EdmondsKarpTestCase > > > > // actual max flow > > findMaxFlow( (DirectedMutableWeightedGraph<Vertex, > WeightedEdge<Integer>, Integer>) null ).from( a ).to( g > ).applyingEdmondsKarp( new IntegerWeight() ); > > - fail( "Null Pointer Exception not catched" ); > > + fail( "Null Pointer Exception not caught" ); > > Surely that should be something like: > > fail( "NullPointerException not thrown" ); > > or > > fail( "expected NullPointerException" ); > > == > > Many of the tests also use the annotation: > > @Test( expected = NullPointerException.class ) > > which is not needed if fail() is used. > > In fact the annotation can cause a test to succeed when it should fail. > If the NPE occurs too early in the test, the test will be marked as > successful. > > If you want to ensure that the NPE only occurs in the last statement > of the test case, then drop the expected qualifier and use the fail() > call at the end of the test case. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > >