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.TransparentLayer;
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 TestLayerTransparent
27 {
28
29
30
31 private final String testdata = "The quick brown fox jumps over the lazy dog.";
32
33
34
35
36 private TransparentLayer layer = null;
37
38
39
40
41
42
43
44 @BeforeEach
45 public void setUp() throws Exception
46 {
47 layer = new TransparentLayer();
48 layer.init("");
49 }
50
51
52
53
54
55
56
57 @AfterEach
58 public void tearDown() throws Exception
59 {
60 layer = null;
61 }
62
63
64
65
66
67
68
69 @Test
70 public void testEncStream() throws JastacryException
71 {
72 final byte[] buf = testdata.getBytes();
73 final InputStream is = new ByteArrayInputStream(buf);
74 final OutputStream os = new ByteArrayOutputStream();
75 layer.encStream(is, os);
76 assertEquals("encoding differs", testdata, os.toString());
77 }
78
79
80
81
82
83
84
85 @Test
86 public void testDecStream() throws JastacryException
87 {
88 final byte[] buf = testdata.getBytes();
89 final InputStream is = new ByteArrayInputStream(buf);
90 final OutputStream os = new ByteArrayOutputStream();
91 layer.decStream(is, os);
92 assertEquals("decoding differs", testdata, os.toString());
93 }
94
95
96
97
98 @Test
99 public void testToString()
100 {
101 assertEquals("Layer name mismatch", TransparentLayer.LAYERNAME, layer.toString());
102 }
103
104
105
106
107
108
109
110
111 @Test
112 public void testEncStreamException() throws JastacryException, IOException
113 {
114 Toolingg.html#Tooling">Tooling tool = new Tooling();
115 Assertions.assertThrows(JastacryException.class, () -> {
116 tool.mockupInputOutputEncStreams(layer);
117 });
118 }
119
120
121
122
123
124
125
126
127 @Test
128 public void testDecStreamException() throws JastacryException, IOException
129 {
130 Toolingg.html#Tooling">Tooling tool = new Tooling();
131 Assertions.assertThrows(JastacryException.class, () -> {
132 tool.mockupInputOutputDecStreams(layer);
133 });
134 }
135
136
137
138
139 @Test
140 public void testEquals()
141 {
142 TransparentLayer l1 = new TransparentLayer();
143 TransparentLayer l2 = new TransparentLayer();
144 assertEquals("Layer object equal", l1, l2);
145 }
146
147
148
149
150 @Test
151 public void testEqualsSame()
152 {
153 TransparentLayer l1 = new TransparentLayer();
154 assertEquals("Layer object same", l1, l1);
155 }
156
157
158
159
160 @Test
161 public void testNotEqualsNull()
162 {
163 TransparentLayer l1 = new TransparentLayer();
164 assertEquals("Layer object null unequal", l1.equals(null), false);
165 }
166
167
168
169
170 @Test
171 public void testNotEqualsWrongclass()
172 {
173 TransparentLayer l1 = new TransparentLayer();
174 Object o = new Object();
175 assertEquals("Layer object null unequal", l1.equals(o), false);
176 }
177
178
179
180
181 @Test
182 public void testHashcode()
183 {
184 TransparentLayer l1 = new TransparentLayer();
185 TransparentLayer l2 = new TransparentLayer();
186 assertEquals("Layer hash equal", l1.hashCode(), l2.hashCode());
187 }
188
189 }