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.IOException;
8   import java.io.InputStream;
9   import java.io.OutputStream;
10  
11  import org.jastacry.JastacryException;
12  import org.jastacry.test.utils.Tooling;
13  import org.junit.jupiter.api.AfterEach;
14  import org.junit.jupiter.api.Assertions;
15  import org.junit.jupiter.api.BeforeEach;
16  import org.junit.jupiter.api.Test;
17  
18  /**
19   * Test of Rotate Layer.
20   *
21   * @author Kai Kretschmann
22   *
23   */
24  public class TestLayerReverse
25  {
26      /**
27       * Test data to play with.
28       */
29      private final String testdata = "The quick brown fox jumps over the lazy dog.";
30  
31      /**
32       * The layer to test.
33       */
34      private Layer layer = null;
35  
36      /**
37       * Test Before method.
38       *
39       * @throws Exception
40       *             in case of error
41       */
42      @BeforeEach
43      public void setUp() throws Exception
44      {
45          layer = new ReverseLayer();
46      }
47  
48      /**
49       * Test After method.
50       *
51       * @throws Exception
52       *             in case of error
53       */
54      @AfterEach
55      public void tearDown() throws Exception
56      {
57          layer = null;
58      }
59  
60      /**
61       * Test case testEncDecStream.
62       *
63       * @throws JastacryException
64       *             in case of error
65       */
66      @Test
67      public void testEncDecStream() throws JastacryException
68      {
69          byte[] buf = testdata.getBytes();
70          final InputStream isEncode = new ByteArrayInputStream(buf);
71          final ByteArrayOutputStream osEncode = new ByteArrayOutputStream();
72          layer.encStream(isEncode, osEncode);
73          buf = osEncode.toByteArray();
74  
75          final InputStream isDecode = new ByteArrayInputStream(buf);
76          final OutputStream osDecode = new ByteArrayOutputStream();
77          layer.decStream(isDecode, osDecode);
78          assertEquals("decoding differs", testdata, osDecode.toString());
79      }
80  
81      /**
82       * Test case testToString.
83       */
84      @Test
85      public void testToString()
86      {
87          assertEquals("Layer name mismatch", ReverseLayer.LAYERNAME, layer.toString());
88      }
89  
90      /**
91       * Testcase testEncStream Exceptions.
92       *
93       * @throws JastacryException
94       *             in case of error
95       * @throws IOException will be thrown in test
96       */
97      @Test
98      public void testEncStreamException() throws JastacryException, IOException
99      {
100         Toolingg.html#Tooling">Tooling tool = new Tooling();
101         Assertions.assertThrows(JastacryException.class, () -> {
102             tool.mockupInputOutputEncStreams(layer);
103         });
104     }
105 
106     /**
107      * Testcase testDecStream Exceptions.
108      *
109      * @throws JastacryException
110      *             in case of error
111      * @throws IOException will be thrown in test
112      */
113     @Test
114     public void testDecStreamException() throws JastacryException, IOException
115     {
116         Toolingg.html#Tooling">Tooling tool = new Tooling();
117         Assertions.assertThrows(JastacryException.class, () -> {
118             tool.mockupInputOutputDecStreams(layer);
119         });
120     }
121 
122     /**
123      * Testcase equals.
124      */
125     @Test
126     public void testEquals()
127     {
128         ReverseLayer l1 = new ReverseLayer();
129         ReverseLayer l2 = new ReverseLayer();
130         assertEquals("Layer object equal", l1, l2);
131     }
132 
133     /**
134      * Testcase equals.
135      */
136     @Test
137     public void testEqualsSame()
138     {
139         ReverseLayer l1 = new ReverseLayer();
140         assertEquals("Layer object same", l1, l1);
141     }
142 
143     /**
144      * Testcase equals.
145      */
146     @Test
147     public void testNotEqualsNull()
148     {
149         ReverseLayer l1 = new ReverseLayer();
150         Object o = null;
151         assertEquals("Layer object null unequal", l1.equals(o), false);
152     }
153 
154     /**
155      * Testcase equals.
156      */
157     @Test
158     public void testNotEqualsWrongclass()
159     {
160         ReverseLayer l1 = new ReverseLayer();
161         Object o = new Object();
162         assertEquals("Layer object wrong class unequal", l1.equals(o), false);
163     }
164 
165     /**
166      * Testcase hashcode.
167      */
168     @Test
169     public void testHashcode()
170     {
171         ReverseLayer l1 = new ReverseLayer();
172         ReverseLayer l2 = new ReverseLayer();
173         assertEquals("Layer hash equal", l1.hashCode(), l2.hashCode());
174     }
175 }