1 package com.atlassian.vcache.marshallers;
2
3 import com.atlassian.vcache.Marshaller;
4 import com.atlassian.vcache.MarshallerException;
5 import org.junit.Test;
6
7 import static org.hamcrest.Matchers.is;
8 import static org.hamcrest.Matchers.notNullValue;
9 import static org.junit.Assert.assertThat;
10
11 public class JavaSerializationMarshallerTest {
12 @Test(expected = MarshallerException.class)
13 public void testClassCast() throws MarshallerException {
14 final Marshaller<String> stringie = MarshallerFactory.serializableMarshaller(String.class);
15 final Marshaller<Long> longie = MarshallerFactory.serializableMarshaller(Long.class);
16
17 final byte[] strData = stringie.marshall("Art Vs Science");
18 final String revived = stringie.unmarshall(strData);
19
20 assertThat(revived, is("Art Vs Science"));
21
22 longie.unmarshall(strData);
23 }
24
25 @Test
26 public void other_classloader() throws MarshallerException {
27 final Marshaller<Long> longie =
28 MarshallerFactory.serializableMarshaller(Long.class, Thread.currentThread().getContextClassLoader());
29
30 final byte[] longData = longie.marshall(666L);
31
32 assertThat(longData, notNullValue());
33
34 final Long revived = longie.unmarshall(longData);
35
36 assertThat(revived, is(666L));
37 }
38 }