use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testEnum.
/**
* Tests Dataserializing an Enum
*/
@Test
public void testEnum() throws Exception {
DAY_OF_WEEK e = DAY_OF_WEEK.SUN;
MONTH m = MONTH.FEB;
DataOutputStream out = getDataOutput();
DataSerializer.writeEnum(e, out);
DataSerializer.writeEnum(m, out);
try {
DataSerializer.writeEnum(null, out);
fail("Expected exception not thrown");
} catch (NullPointerException ex) {
}
out.flush();
DataInput in = getDataInput();
Class c = null;
try {
DataSerializer.readEnum(c, in);
fail("Expected exception not thrown");
} catch (NullPointerException ex) {
}
c = Foo.class;
try {
DataSerializer.readEnum(c, in);
fail("Expected exception not thrown");
} catch (IllegalArgumentException ex) {
}
DAY_OF_WEEK e2 = DataSerializer.readEnum(DAY_OF_WEEK.class, in);
MONTH m2 = DataSerializer.readEnum(MONTH.class, in);
assertEquals(e, e2);
assertEquals(m, m2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testByteObject.
/**
* Tests data serializing a {@link Byte} using {@link DataSerializer#writeObject}.
*/
@Test
public void testByteObject() throws Exception {
Byte value = new Byte((byte) getRandom().nextInt());
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(value, out);
out.flush();
DataInput in = getDataInput();
Byte value2 = (Byte) DataSerializer.readObject(in);
assertEquals(value, value2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testDateObject.
/**
* Tests data serializing a {@link Date} using {@link DataSerializer#writeObject}.
*/
@Test
public void testDateObject() throws Exception {
Date date = new Date();
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(date, out);
out.flush();
DataInput in = getDataInput();
Date date2 = (Date) DataSerializer.readObject(in);
assertEquals(date, date2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testByteArrayObject.
/**
* Tests data serializing a <code>byte</code> array using {@link DataSerializer#writeObject}.
*/
@Test
public void testByteArrayObject() throws Exception {
byte[] array = new byte[] { (byte) 4, (byte) 5, (byte) 6 };
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(array, out);
out.flush();
DataInput in = getDataInput();
byte[] array2 = (byte[]) DataSerializer.readObject(in);
assertEquals(array.length, array2.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], array2[i]);
}
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testTreeMap.
/**
* Tests data serializing an {@link TreeMap}
*/
@Test
public void testTreeMap() throws Exception {
Random random = getRandom();
TreeMap map = new TreeMap();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
Object key = new Long(random.nextLong());
Object value = String.valueOf(random.nextLong());
map.put(key, value);
}
DataOutputStream out = getDataOutput();
DataSerializer.writeTreeMap(null, out);
DataSerializer.writeTreeMap(new TreeMap(), out);
DataSerializer.writeTreeMap(map, out);
out.flush();
DataInput in = getDataInput();
assertEquals(null, DataSerializer.readTreeMap(in));
assertEquals(new TreeMap(), DataSerializer.readTreeMap(in));
TreeMap map2 = DataSerializer.readTreeMap(in);
assertEquals(map, map2);
}
Aggregations