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 Layer Transparent.
20   *
21   * @author Kai Kretschmann
22   *
23   */
24  public class TestLayerTransparent
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 TransparentLayer 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 TransparentLayer();
46          layer.init("");
47      }
48  
49      /**
50       * Test After method.
51       *
52       * @throws Exception
53       *             in case of error
54       */
55      @AfterEach
56      public void tearDown() throws Exception
57      {
58          layer = null;
59      }
60  
61      /**
62       * Test method for {@link org.jastacry.layer.TransparentLayer#encStream(java.io.InputStream, java.io.OutputStream)} .
63       *
64       * @throws JastacryException
65       *             in case of error.
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       * Test method for {@link org.jastacry.layer.TransparentLayer#decStream(java.io.InputStream, java.io.OutputStream)} .
79       *
80       * @throws JastacryException
81       *             in case of error.
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       * Test method for {@link org.jastacry.layer.TransparentLayer#toString()}.
95       */
96      @Test
97      public void testToString()
98      {
99          assertEquals("Layer name mismatch", TransparentLayer.LAYERNAME, layer.toString());
100     }
101 
102     /**
103      * Testcase testEncStream Exceptions.
104      *
105      * @throws JastacryException
106      *             in case of error
107      * @throws IOException will be thrown in test
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      * Testcase testDecStream Exceptions.
120      *
121      * @throws JastacryException
122      *             in case of error
123      * @throws IOException will be thrown in test
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      * Testcase equals.
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      * Testcase equals.
147      */
148     @Test
149     public void testEqualsSame()
150     {
151         TransparentLayer l1 = new TransparentLayer();
152         assertEquals("Layer object same", l1, l1);
153     }
154 
155     /**
156      * Testcase equals.
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      * Testcase equals.
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      * Testcase hashcode.
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 }