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