Skip to content

Commit

Permalink
Better code usability and clear errors
Browse files Browse the repository at this point in the history
  • Loading branch information
eskatos committed Feb 7, 2011
1 parent a046798 commit 751517e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/codeartisans/junit/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
* This class extends org.junit.Assert and augments provided static assertions.
*/
public final class Assert
extends org.junit.Assert
{

public static interface PostSerializationAssertions<T extends Serializable>
Expand All @@ -37,6 +41,10 @@ public static interface PostSerializationAssertions<T extends Serializable>
public static <T extends Serializable> void assertSerializable( T tested, PostSerializationAssertions<T> assertions )
throws IOException, ClassNotFoundException
{
if ( tested == null ) {
throw new IllegalArgumentException( "Assert.assertSerializable tested argument was null" );
}

// Serialize
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( out );
Expand All @@ -48,6 +56,7 @@ public static <T extends Serializable> void assertSerializable( T tested, PostSe
InputStream in = new ByteArrayInputStream( pickled );
ObjectInputStream ois = new ObjectInputStream( in );
Object o = ois.readObject();
assertNotNull( o );
// Cast
@SuppressWarnings( "unchecked" )
T copy = ( T ) o;
Expand Down

0 comments on commit 751517e

Please sign in to comment.