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