View Javadoc
1   package org.jastacry.test;
2   
3   import java.io.IOException;
4   import java.io.InputStream;
5   import java.io.OutputStream;
6   import java.util.concurrent.CountDownLatch;
7   
8   import org.jastacry.layer.ReadWriteLayer;
9   
10  import org.junit.jupiter.api.AfterEach;
11  import org.junit.jupiter.api.BeforeEach;
12  import org.junit.jupiter.api.Test;
13  
14  /**
15   * Test of IOException.
16   *
17   * @author Kai Kretschmann
18   *
19   */
20  public class TestInputOutput
21  {
22  
23      /**
24       * The layer to test.
25       */
26      private ReadWriteLayer layer = null;
27  
28      /**
29       * Needed for the thread countdown.
30       */
31      private CountDownLatch endController;
32  
33      /**
34       * Test before method.
35       *
36       * @throws Exception
37       *             in case of error
38       */
39      @BeforeEach
40      public void setUp() throws Exception
41      {
42          layer = new ReadWriteLayer();
43          endController = new CountDownLatch(1);
44          layer.setEndController(endController);
45      }
46  
47      /**
48       * Test After method.
49       *
50       * @throws Exception
51       *             in case of error
52       */
53      @AfterEach
54      public void tearDown() throws Exception
55      {
56          layer = null;
57      }
58  
59      /**
60       * Testcase testIOException.
61       *
62       */
63      @Test
64      public void testIoException()
65      {
66          InputStream sInput;
67          OutputStream sOutput;
68          sInput = new InputStream()
69          {
70              @Override
71              public int read() throws IOException
72              {
73                  throw new IOException("Expected as a test");
74              }
75          };
76          sOutput = new OutputStream()
77          {
78              @Override
79              public void write(int i) throws IOException
80              {
81                  throw new IOException("Expected as a test");
82              }
83          };
84  
85          layer.setInputStream(sInput);
86          layer.setOutputStream(sOutput);
87  //        Assertions.assertThrows(IOException.class, () -> {
88              layer.run();
89  //        });
90      }
91  
92  }