View Javadoc
1   package org.jastacry.layer;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import java.io.ByteArrayInputStream;
6   import java.io.ByteArrayOutputStream;
7   import java.io.InputStream;
8   
9   import org.jastacry.JastacryException;
10  
11  import org.junit.jupiter.api.AfterEach;
12  import org.junit.jupiter.api.Assertions;
13  import org.junit.jupiter.api.BeforeEach;
14  import org.junit.jupiter.api.Test;
15  
16  /**
17   * Test of Rotate Layer.
18   *
19   * @author Kai Kretschmann
20   *
21   */
22  public class TestLayerReadWrite
23  {
24      /**
25       * Testdata to play with.
26       */
27      private final String testdata = "The quick brown fox jumps over the lazy dog.";
28  
29      /**
30       * The layer to test.
31       */
32      private ReadWriteLayer layer = null;
33  
34      /**
35       * Test Before method.
36       *
37       * @throws Exception
38       *             in case of error
39       */
40      @BeforeEach
41      public void setUp() throws Exception
42      {
43          layer = new ReadWriteLayer();
44      }
45  
46      /**
47       * Test After method.
48       *
49       * @throws Exception
50       *             in case of error
51       */
52      @AfterEach
53      public void tearDown() throws Exception
54      {
55          layer = null;
56      }
57  
58      /**
59       * Testcase testToString.
60       */
61      @Test
62      public void testToString()
63      {
64          assertEquals("Layer name mismatch", ReadWriteLayer.LAYERNAME, layer.toString());
65      }
66  
67      /**
68       * Testcase unsupported exception.
69       * @throws JastacryException on error
70       */
71      @Test
72      public void testUnsupported() throws JastacryException
73      {
74          byte[] buf = testdata.getBytes();
75          final InputStream isEncode = new ByteArrayInputStream(buf);
76          final ByteArrayOutputStream osEncode = new ByteArrayOutputStream();
77          Assertions.assertThrows(UnsupportedOperationException.class, () -> {
78              layer.encodeAndDecode(isEncode, osEncode);
79          });
80      }
81  
82      /**
83       * Testcase testInit.
84       */
85      @Test
86      public void testInit()
87      {
88          layer.init("");
89      }
90  
91      /**
92       * Testcase equals.
93       */
94      @Test
95      public void testEquals()
96      {
97          ReadWriteLayer l1 = new ReadWriteLayer();
98          ReadWriteLayer l2 = new ReadWriteLayer();
99          assertEquals("Layer object equal", l1, l2);
100     }
101 
102     /**
103      * Testcase equals.
104      */
105     @Test
106     public void testEqualsSame()
107     {
108         ReadWriteLayer l1 = new ReadWriteLayer();
109         assertEquals("Layer object same", l1, l1);
110     }
111 
112     /**
113      * Testcase equals.
114      */
115     @Test
116     public void testNotEqualsNull()
117     {
118         ReadWriteLayer l1 = new ReadWriteLayer();
119         Object o = null;
120         assertEquals("Layer object null unequal", l1.equals(o), false);
121     }
122 
123     /**
124      * Testcase equals.
125      */
126     @Test
127     public void testNotEqualsWrongclass()
128     {
129         ReadWriteLayer l1 = new ReadWriteLayer();
130         Object o = new Object();
131         assertEquals("Layer object wrong class unequal", l1.equals(o), false);
132     }
133 
134     /**
135      * Testcase hashcode.
136      */
137     @Test
138     public void testHashcode()
139     {
140         ReadWriteLayer l1 = new ReadWriteLayer();
141         ReadWriteLayer l2 = new ReadWriteLayer();
142         assertEquals("Layer hash equal", l1.hashCode(), l2.hashCode());
143     }
144 
145 }