Author: peter_firmstone Date: Fri Mar 1 12:22:25 2013 New Revision: 1451572
URL: http://svn.apache.org/r1451572 Log: Unit test updates Modified: river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java Modified: river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java?rev=1451572&r1=1451571&r2=1451572&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java Fri Mar 1 12:22:25 2013 @@ -39,25 +39,45 @@ public class DistributedObjectOutputStre */ @Test public void testCreate() throws Exception { - System.out.println("create"); + System.out.println("create: test constructor, static method and object method"); DistributedObject expResult = new DistributedObject("Testing"); ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream outst = DistributedObjectOutputStream.create(out); outst.writeObject(expResult); - ObjectInputStream in = new DistributedObjectInputStream(new ByteArrayInputStream(out.toByteArray())); + ObjectInputStream in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); Object result = in.readObject(); assertEquals(expResult.toString(), result.toString()); out = new ByteArrayOutputStream(); outst = DistributedObjectOutputStream.create(out); expResult = new DistributedObject("Testing", 1); outst.writeObject(expResult); - in = new DistributedObjectInputStream(new ByteArrayInputStream(out.toByteArray())); + in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); result = in.readObject(); assertEquals(expResult.toString(), result.toString()); expResult = new DistributedObject("Testing", 2); outst.writeObject(expResult); - in = new DistributedObjectInputStream(new ByteArrayInputStream(out.toByteArray())); + in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); result = in.readObject(); assertEquals(expResult.toString(), result.toString()); } + + @Test + public void testPrimitives() throws Exception { + System.out.println("create: test constructor, static method and object method"); + DistributedObject expResult = new DistributedObject(Boolean.TRUE); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ObjectOutputStream outst = DistributedObjectOutputStream.create(out); + outst.writeObject(expResult); + ObjectInputStream in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); + Object result = in.readObject(); + assertEquals(expResult.toString(), result.toString()); + out = new ByteArrayOutputStream(); + outst = DistributedObjectOutputStream.create(out); + expResult = new DistributedObject(true); + outst.writeObject(expResult); + in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); + result = in.readObject(); + assertEquals(expResult.toString(), result.toString()); + + } } Modified: river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java?rev=1451572&r1=1451571&r2=1451572&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java Fri Mar 1 12:22:25 2013 @@ -31,9 +31,11 @@ public class DistributedObject implement } private final String testString; - /* 0 - constructor + /* 0 - constructor(String) * 1 - static factory method * 2 - builder + * 3 - constructor(Boolean) + * 4 - constructor(Character) */ private final int method; @@ -42,6 +44,26 @@ public class DistributedObject implement method = 0; } + public DistributedObject(Number num){ + testString = num.toString(); + method = 5; + } + + public DistributedObject(Character ch){ + testString = ch.toString(); + method = 4; + } + + public DistributedObject(Boolean b){ + testString = b.toString(); + method = 3; + } + + public DistributedObject(boolean b){ + testString = Boolean.toString(b); + method = 6; + } + public DistributedObject(String str, int method){ testString = str; this.method = method; @@ -51,19 +73,32 @@ public class DistributedObject implement Class[] signature = new Class[1]; Object[] parameters = new Object[1]; parameters[0] = testString; - if (method == 0){ - signature[0] = String.class; - return new SerialFactory(this.getClass(), null, signature, parameters ); - } - if (method == 1){ - signature[0] = String.class; - return new SerialFactory(this.getClass(), "create", signature, parameters); - } - if (method == 2){ - Builder builder = new Builder().setString(testString); - return new SerialFactory(builder, "build", null, null); + switch (method){ + case 0: signature[0] = String.class; + return new SerialFactory(this.getClass(), null, signature, parameters ); + + case 1 : + signature[0] = String.class; + return new SerialFactory(this.getClass(), "create", signature, parameters); + + case 2: + Builder builder = new Builder().setString(testString); + return new SerialFactory(builder, "build", null, null); + case 3: + signature[0] = Boolean.class; + parameters[0] = Boolean.valueOf(testString); + return new SerialFactory(this.getClass(), null, signature, parameters); + case 4: + signature[0] = Character.class; + parameters[0] = Character.valueOf(testString.charAt(0)); + return new SerialFactory(this.getClass(), null, signature, parameters); + case 6: + signature[0] = Boolean.TYPE; + parameters[0] = Boolean.valueOf(testString); + return new SerialFactory(this.getClass(), null, signature, parameters); + default: + return null; } - return null; } public String toString(){
