@Test public void testBytes() throws Exception { EntityMarshaller<Bytes> marshaller = createEntityMarshaller(Bytes.class); Json.Object object = marshaller.marshall( new Bytes() { { this.literal = 8; this.object = 5; this.nativeArray = new byte[] {0, -128}; this.objectArray = new Byte[] {127, null}; } }); assertJsonObjectWellFormed( object, number(8), number(5), number(0), number(-128), number(127), NULL); Bytes instance = marshaller.unmarshall(object); assertEquals((byte) 8, instance.literal); assertEquals(Byte.valueOf((byte) 5), instance.object); assertEquals(2, instance.nativeArray.length); assertEquals((byte) 0, instance.nativeArray[0]); assertEquals((byte) -128, instance.nativeArray[1]); assertEquals(2, instance.objectArray.length); assertEquals(Byte.valueOf((byte) 127), instance.objectArray[0]); assertNull(instance.objectArray[1]); }
@Test public void testDouble() throws Exception { EntityMarshaller<Double> marshaller = createEntityMarshaller(Double.class); Json.Object object = marshaller.marshall( new Double() { { this.literal = 1.0; this.object = 2.0; this.nativeArray = new double[] {3, 4}; this.objectArray = new java.lang.Double[] {5.0, 6.0}; } }); assertJsonObjectWellFormed(object); Double instance = marshaller.unmarshall(object); assertEquals(1.0, instance.literal); assertEquals(2.0, instance.object); assertEquals(2, instance.nativeArray.length); assertEquals(3.0, instance.nativeArray[0]); assertEquals(4.0, instance.nativeArray[1]); assertEquals(2, instance.objectArray.length); assertEquals(5.0, instance.objectArray[0]); assertEquals(6.0, instance.objectArray[1]); }
@Test public void testInt() throws Exception { EntityMarshaller<Int> marshaller = createEntityMarshaller(Int.class); Json.Object object = marshaller.marshall( new Int() { { this.literal = 1; this.object = 2; this.nativeArray = new int[] {3, 4}; this.objectArray = new Integer[] {5, 6}; } }); assertJsonObjectWellFormed(object); assertEquals("1", object.get(string("literal")).toString()); Int instance = marshaller.unmarshall(object); assertEquals(1, instance.literal); assertEquals(2, instance.object); assertEquals(2, instance.nativeArray.length); assertEquals(3, instance.nativeArray[0]); assertEquals(4, instance.nativeArray[1]); assertEquals(2, instance.objectArray.length); assertEquals(5, instance.objectArray[0]); assertEquals(6, instance.objectArray[1]); }
@Test public void testBool() throws Exception { EntityMarshaller<Bool> marshaller = createEntityMarshaller(Bool.class); Json.Object object = marshaller.marshall( new Bool() { { this.literal = true; this.object = false; this.nativeArray = new boolean[] {true, false}; this.objectArray = new Boolean[] {true, false}; } }); assertJsonObjectWellFormed(object, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE); Bool instance = marshaller.unmarshall(object); assertEquals(true, instance.literal); assertEquals(false, instance.object); assertEquals(2, instance.nativeArray.length); assertEquals(true, instance.nativeArray[0]); assertEquals(false, instance.nativeArray[1]); assertEquals(2, instance.objectArray.length); assertEquals(true, instance.objectArray[0]); assertEquals(false, instance.objectArray[1]); }
@Test public void testChar() throws Exception { EntityMarshaller<Char> marshaller = createEntityMarshaller(Char.class); Json.Object object = marshaller.marshall( new Char() { { this.literal = 'a'; this.object = 'b'; this.nativeArray = new char[] {'c', 'd'}; this.objectArray = new Character[] {'e', 'f'}; } }); assertJsonObjectWellFormed( object, string("a"), string("b"), string("c"), string("d"), string("e"), string("f")); Char instance = marshaller.unmarshall(object); assertEquals('a', instance.literal); assertEquals('b', instance.object); assertEquals(2, instance.nativeArray.length); assertEquals('c', instance.nativeArray[0]); assertEquals('d', instance.nativeArray[1]); assertEquals(2, instance.objectArray.length); assertEquals('e', instance.objectArray[0]); assertEquals('f', instance.objectArray[1]); }
@Test public void testLong() throws Exception { EntityMarshaller<Long> marshaller = createEntityMarshaller(Long.class); Json.Object object = marshaller.marshall( new Long() { { this.literal = 1L; this.object = 2L; this.nativeArray = new long[] {3, 4}; this.objectArray = new java.lang.Long[] {5L, 6L}; } }); assertJsonObjectWellFormed(object); assertEquals("1", object.get(string("literal")).toString()); Long instance = marshaller.unmarshall(object); assertEquals(1, instance.literal); assertEquals(2.0, instance.object); assertEquals(2, instance.nativeArray.length); assertEquals(3, instance.nativeArray[0]); assertEquals(4, instance.nativeArray[1]); assertEquals(2, instance.objectArray.length); assertEquals(5, instance.objectArray[0]); assertEquals(6, instance.objectArray[1]); }
@Test public void testFloat() throws Exception { EntityMarshaller<Float> marshaller = createEntityMarshaller(Float.class); Json.Object object = marshaller.marshall( new Float() { { this.literal = 1f; this.object = 2f; this.nativeArray = new float[] {3f, 4f}; this.objectArray = new java.lang.Float[] {5f, null}; } }); assertJsonObjectWellFormed(object, number(1), number(2), number(3), number(4), number(5), NULL); Float instance = marshaller.unmarshall(object); assertEquals(1f, instance.literal); assertEquals(2f, instance.object); assertEquals(2, instance.nativeArray.length); assertEquals(3f, instance.nativeArray[0]); assertEquals(4f, instance.nativeArray[1]); assertEquals(2, instance.objectArray.length); assertEquals(5f, instance.objectArray[0]); assertNull(instance.objectArray[1]); assertEquals(0f, marshaller.unmarshall(object()).literal); try { marshaller.unmarshall(object(string("nativeArray"), array(NULL))); fail("expected NPE"); } catch (NullPointerException e) { } }