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.layer.RotateLayer;
13 import org.jastacry.test.utils.Tooling;
14
15 import org.junit.jupiter.api.AfterEach;
16 import org.junit.jupiter.api.Assertions;
17 import org.junit.jupiter.api.BeforeEach;
18 import org.junit.jupiter.api.Test;
19
20
21
22
23
24
25
26 public class TestLayerRotate
27 {
28
29
30
31 private final String testdata = "The quick brown fox jumps over the lazy dog.";
32
33
34
35
36 private RotateLayer layer = null;
37
38
39
40
41 private static final String SHIFTSMALL = "2";
42
43
44
45
46 private static final String SHIFTWIDE = "250";
47
48
49
50
51
52
53
54 @BeforeEach
55 public void setUp() throws Exception
56 {
57 layer = new RotateLayer();
58 }
59
60
61
62
63
64
65
66 @AfterEach
67 public void tearDown() throws Exception
68 {
69 layer = null;
70 }
71
72
73
74
75
76
77
78 @Test
79 public void testEncDecStream() throws JastacryException
80 {
81 layer.init(SHIFTSMALL);
82 byte[] buf = testdata.getBytes();
83 final InputStream isEncode = new ByteArrayInputStream(buf);
84 final ByteArrayOutputStream osEncode = new ByteArrayOutputStream();
85 layer.encStream(isEncode, osEncode);
86 buf = osEncode.toByteArray();
87
88 final InputStream isDecode = new ByteArrayInputStream(buf);
89 final OutputStream osDecode = new ByteArrayOutputStream();
90 layer.decStream(isDecode, osDecode);
91 assertEquals("decoding differs", testdata, osDecode.toString());
92 }
93
94
95
96
97
98
99
100 @Test
101 public void testEncDecStreamWide() throws JastacryException
102 {
103 layer.init(SHIFTWIDE);
104 byte[] buf = testdata.getBytes();
105 final InputStream isEncode = new ByteArrayInputStream(buf);
106 final ByteArrayOutputStream osEncode = new ByteArrayOutputStream();
107 layer.encStream(isEncode, osEncode);
108 buf = osEncode.toByteArray();
109
110 final InputStream isDecode = new ByteArrayInputStream(buf);
111 final OutputStream osDecode = new ByteArrayOutputStream();
112 layer.decStream(isDecode, osDecode);
113 assertEquals("decoding differs", testdata, osDecode.toString());
114 }
115
116
117
118
119 @Test
120 public void testToString()
121 {
122 assertEquals("Layer name mismatch", RotateLayer.LAYERNAME, layer.toString());
123 }
124
125
126
127
128
129 @Test
130
131 public void testUnsupported() throws JastacryException
132 {
133 byte[] buf = testdata.getBytes();
134 final InputStream isEncode = new ByteArrayInputStream(buf);
135 final ByteArrayOutputStream osEncode = new ByteArrayOutputStream();
136 Assertions.assertThrows(UnsupportedOperationException.class, () -> {
137 layer.encodeAndDecode(isEncode, osEncode);
138 });
139 }
140
141
142
143
144
145
146
147
148 @Test
149 public void testEncStreamException() throws JastacryException, IOException
150 {
151 Toolingg.html#Tooling">Tooling tool = new Tooling();
152 Assertions.assertThrows(JastacryException.class, () -> {
153 tool.mockupInputOutputEncStreams(layer);
154 });
155 }
156
157
158
159
160
161
162
163
164 @Test
165 public void testDecStreamException() throws JastacryException, IOException
166 {
167 Toolingg.html#Tooling">Tooling tool = new Tooling();
168 Assertions.assertThrows(JastacryException.class, () -> {
169 tool.mockupInputOutputDecStreams(layer);
170 });
171 }
172
173
174
175
176 @Test
177 public void testEquals()
178 {
179 RotateLayer l1 = new RotateLayer();
180 RotateLayer l2 = new RotateLayer();
181 l1.init(SHIFTSMALL);
182 l2.init(SHIFTSMALL);
183 assertEquals("Layer object equal", true, l1.equals(l2));
184 }
185
186
187
188
189 @Test
190 public void testNotEquals()
191 {
192 RotateLayer l1 = new RotateLayer();
193 RotateLayer l2 = new RotateLayer();
194 l1.init(SHIFTSMALL);
195 l2.init(SHIFTWIDE);
196 assertEquals("Layer object not equal", false, l1.equals(l2));
197 }
198
199
200
201
202 @Test
203 public void testEqualsSame()
204 {
205 RotateLayer l1 = new RotateLayer();
206 l1.init(SHIFTSMALL);
207 assertEquals("Layer object same", true, l1.equals(l1));
208 }
209
210
211
212
213 @Test
214 public void testNotEqualsNull()
215 {
216 RotateLayer l1 = new RotateLayer();
217 Object o = null;
218 l1.init(SHIFTSMALL);
219 assertEquals("Layer object null unequal", false, l1.equals(o));
220 }
221
222
223
224
225 @Test
226 public void testNotEqualsWrongclass()
227 {
228 RotateLayer l1 = new RotateLayer();
229 Object o = new Object();
230 l1.init(SHIFTSMALL);
231 assertEquals("Layer object type unequal", false, l1.equals(o));
232 }
233
234
235
236
237 @Test
238 public void testHashcode()
239 {
240 RotateLayer l1 = new RotateLayer();
241 RotateLayer l2 = new RotateLayer();
242 l1.init(SHIFTSMALL);
243 l2.init(SHIFTSMALL);
244 assertEquals("Layer hash equal", l1.hashCode(), l2.hashCode());
245 }
246
247 }