View Javadoc

1   package com.atlassian.vcache.internal.core.service;
2   
3   import com.atlassian.marshalling.api.MarshallingPair;
4   import com.atlassian.marshalling.jdk.JavaSerializationMarshalling;
5   import com.atlassian.marshalling.jdk.OptionalMarshalling;
6   import com.atlassian.marshalling.jdk.StringMarshalling;
7   import com.atlassian.vcache.Marshaller;
8   import com.atlassian.vcache.MarshallerException;
9   import org.junit.Test;
10  
11  import static com.atlassian.vcache.marshallers.MarshallerFactory.optionalMarshaller;
12  import static com.atlassian.vcache.marshallers.MarshallerFactory.serializableMarshaller;
13  import static com.atlassian.vcache.marshallers.MarshallerFactory.stringMarshaller;
14  import static org.hamcrest.CoreMatchers.is;
15  import static org.junit.Assert.assertThat;
16  
17  @SuppressWarnings("deprecation")
18  public class AbstractVCacheServiceTest {
19      private static final Marshaller<Integer> CUSTOM_LEGACY_MARSHALLER = new Marshaller<Integer>() {
20          @Override
21          public byte[] marshall(Integer obj) throws MarshallerException {
22              return new byte[0];
23          }
24  
25          @Override
26          public Integer unmarshall(byte[] raw) throws MarshallerException {
27              return 1;
28          }
29      };
30  
31      private static final MarshallingPair<Integer> CUSTOM_MARSHALLING_PAIR =
32              new MarshallingPair<>(integer -> new byte[0], bytes -> 1);
33  
34      @Test
35      public void isValueSerializable_legacy() {
36          assertThat(AbstractVCacheService.isValueSerializable(stringMarshaller()), is(true));
37          assertThat(AbstractVCacheService.isValueSerializable(serializableMarshaller(Long.class)), is(true));
38          assertThat(
39                  AbstractVCacheService.isValueSerializable(optionalMarshaller(stringMarshaller())),
40                  is(false));
41          assertThat(AbstractVCacheService.isValueSerializable(CUSTOM_LEGACY_MARSHALLER), is(false));
42      }
43  
44      @Test
45      public void isValueSerializable_marshalling_jdk() {
46          assertThat(AbstractVCacheService.isValueSerializable(StringMarshalling.pair()), is(true));
47          assertThat(AbstractVCacheService.isValueSerializable(JavaSerializationMarshalling.pair(Long.class)), is(true));
48          assertThat(AbstractVCacheService.isValueSerializable(OptionalMarshalling.pair(StringMarshalling.pair())), is(false));
49          assertThat(AbstractVCacheService.isValueSerializable(CUSTOM_MARSHALLING_PAIR), is(false));
50      }
51  }