[Plexus-svn] SF.net SVN: plexus:[897] trunk/plexus-graph/src/test/java/com/phoenixst/ plexus/Defau
Status: Alpha
Brought to you by:
rconner
From: <rc...@us...> - 2010-09-16 17:00:28
|
Revision: 897 http://plexus.svn.sourceforge.net/plexus/?rev=897&view=rev Author: rconner Date: 2010-09-16 17:00:19 +0000 (Thu, 16 Sep 2010) Log Message: ----------- migrate to matcher idiom for tests Modified Paths: -------------- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java Modified: trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java =================================================================== --- trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java 2010-09-16 16:38:05 UTC (rev 896) +++ trunk/plexus-graph/src/test/java/com/phoenixst/plexus/DefaultGraphTest.java 2010-09-16 17:00:19 UTC (rev 897) @@ -15,7 +15,9 @@ package com.phoenixst.plexus; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -59,12 +61,18 @@ setNotPresentEdges( setup.badEdges.toArray( EMPTY_EDGE_ARRAY ) ); } + private static < T > Set< T > toSet( final T ... elements ) + { + return new HashSet< T >( Arrays.asList( elements ) ); + } + @Test public void testDeserialization() throws IOException, ClassNotFoundException { // Make sure we're not being tested inappropriately. - assertEquals( DefaultGraph.class, getGraph().getClass() ); + assertThat( "Graph is not a DefaultGraph; this test has been improperly initialized.", + getGraph(), instanceOf( DefaultGraph.class ) ); // Tests serialize->deserialize, and then compares with the original. ByteArrayOutputStream bos = new ByteArrayOutputStream( 2048 ); @@ -78,14 +86,14 @@ Object copy = in.readObject(); in.close(); - assertEquals( DefaultGraph.class, copy.getClass() ); + assertThat( "Deserialized copy is not a DefaultGraph.", copy, instanceOf( DefaultGraph.class ) ); // Run the copy through the same setup, so we can use // present/notPresentNodes/Edges to test equality. GraphSetup setup = new GraphSetup( (Graph) copy ); - assertEquals( new HashSet< Object >( Arrays.asList( getPresentNodes() ) ), setup.goodNodes ); - assertEquals( new HashSet< Edge >( Arrays.asList( getPresentEdges() ) ), setup.goodEdges ); - assertEquals( new HashSet< Edge >( Arrays.asList( getNotPresentEdges() ) ), setup.badEdges ); + assertThat( "Deserialized nodes not equal.", setup.goodNodes, is( toSet( getPresentNodes() ) ) ); + assertThat( "Deserialized edges not equal.", setup.goodEdges, is( toSet( getPresentEdges() ) ) ); + assertThat( "Deserialized absent edges not equal.", setup.badEdges, is( toSet( getNotPresentEdges() ) ) ); } private static class GraphSetup This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |