1 package com.atlassian.vcache.internal.legacy;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.ByteArrayOutputStream;
5 import java.io.IOException;
6 import java.io.ObjectInputStream;
7 import java.io.ObjectOutputStream;
8
9 import static org.hamcrest.Matchers.is;
10 import static org.hamcrest.Matchers.notNullValue;
11 import static org.junit.Assert.assertThat;
12
13 public class IdentifiedDataBytesTest
14 {
15 @org.junit.Test
16 public void the_basics() throws Exception
17 {
18 final IdentifiedDataBytes isFirst = new IdentifiedDataBytes(new byte[]{1, 2});
19
20 assertThat(isFirst, notNullValue());
21 assertThat(isFirst.getBytes(), is(new byte[]{1, 2}));
22 assertThat(isFirst.equals(isFirst), is(true));
23
24 final IdentifiedDataBytes ibSecond = new IdentifiedDataBytes(new byte[]{1, 2});
25
26 assertThat(ibSecond, notNullValue());
27 assertThat(ibSecond.getBytes(), is(new byte[]{1, 2}));
28 assertThat(isFirst.getBytes(), is(ibSecond.getBytes()));
29 assertThat(ibSecond.equals(ibSecond), is(true));
30 assertThat(isFirst.equals(ibSecond), is(false));
31 assertThat(ibSecond.equals(isFirst), is(false));
32 }
33
34 @org.junit.Test
35 public void serialize_works() throws IOException, ClassNotFoundException
36 {
37 final IdentifiedDataBytes before = new IdentifiedDataBytes(new byte[]{1, 7});
38
39 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
40 final ObjectOutputStream oos = new ObjectOutputStream(baos);
41
42 oos.writeObject(before);
43
44 oos.flush();
45 oos.close();
46
47 final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
48 final ObjectInputStream ois = new ObjectInputStream(bais);
49
50 final IdentifiedDataBytes after = (IdentifiedDataBytes) ois.readObject();
51
52 ois.close();
53
54 assertThat(before.equals(after), is(true));
55 assertThat(after.equals(before), is(true));
56 }
57 }