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.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   * Test of Layer Transparent.
22   *
23   * @author Kai Kretschmann
24   *
25   */
26  public class TestLayerTransparent
27  {
28      /**
29       * Test data to play with.
30       */
31      private final String testdata = "The quick brown fox jumps over the lazy dog.";
32  
33      /**
34       * The layer to test.
35       */
36      private TransparentLayer layer = null;
37  
38      /**
39       * Test Before method.
40       *
41       * @throws Exception
42       *             in case of error
43       */
44      @BeforeEach
45      public void setUp() throws Exception
46      {
47          layer = new TransparentLayer();
48          layer.init("");
49      }
50  
51      /**
52       * Test After method.
53       *
54       * @throws Exception
55       *             in case of error
56       */
57      @AfterEach
58      public void tearDown() throws Exception
59      {
60          layer = null;
61      }
62  
63      /**
64       * Test method for {@link org.jastacry.layer.TransparentLayer#encStream(java.io.InputStream, java.io.OutputStream)} .
65       *
66       * @throws JastacryException
67       *             in case of error.
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       * Test method for {@link org.jastacry.layer.TransparentLayer#decStream(java.io.InputStream, java.io.OutputStream)} .
81       *
82       * @throws JastacryException
83       *             in case of error.
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       * Test method for {@link org.jastacry.layer.TransparentLayer#toString()}.
97       */
98      @Test
99      public void testToString()
100     {
101         assertEquals("Layer name mismatch", TransparentLayer.LAYERNAME, layer.toString());
102     }
103 
104     /**
105      * Testcase testEncStream Exceptions.
106      *
107      * @throws JastacryException
108      *             in case of error
109      * @throws IOException will be thrown in test
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      * Testcase testDecStream Exceptions.
122      *
123      * @throws JastacryException
124      *             in case of error
125      * @throws IOException will be thrown in test
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      * Testcase equals.
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      * Testcase equals.
149      */
150     @Test
151     public void testEqualsSame()
152     {
153         TransparentLayer l1 = new TransparentLayer();
154         assertEquals("Layer object same", l1, l1);
155     }
156 
157     /**
158      * Testcase equals.
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      * Testcase equals.
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      * Testcase hashcode.
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 }