View Javadoc

1   package io.atlassian.fugue;
2   
3   import org.junit.Test;
4   
5   import java.io.IOException;
6   import java.io.NotSerializableException;
7   
8   import static io.atlassian.fugue.Serializer.toBytes;
9   import static io.atlassian.fugue.Serializer.toObject;
10  import static org.hamcrest.Matchers.equalTo;
11  import static org.junit.Assert.assertThat;
12  
13  public class EitherSerializationTest {
14    @Test public void serializeLeft() throws IOException {
15      final Either<Integer, String> e = Either.left(1);
16      assertThat(Serializer.<Either<Integer, String>> toObject(toBytes(e)), equalTo(e));
17    }
18  
19    @Test public void serializeRight() throws IOException {
20      final Either<String, Integer> e = Either.right(1);
21      assertThat(Serializer.<Either<String, Integer>> toObject(toBytes(e)), equalTo(e));
22    }
23  
24    @Test(expected = NotSerializableException.class) public void serializeLeftNonSerializable() throws IOException {
25      toObject(toBytes(Either.left(Serializer.Unserializable.instance())));
26    }
27  
28    @Test(expected = NotSerializableException.class) public void serializeRightNonSerializable() throws IOException {
29      toObject(toBytes(Either.right(Serializer.Unserializable.instance())));
30    }
31  }