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