1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.internal

File LineWrapperOutputStreamTest.java

 

Code metrics

0
26
4
1
79
51
4
0.15
6.5
4
1

Classes

Class Line # Actions
LineWrapperOutputStreamTest 29 26 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.crypto.internal;
21   
22    import java.io.ByteArrayOutputStream;
23   
24    import org.junit.Test;
25   
26    import static org.hamcrest.CoreMatchers.equalTo;
27    import static org.junit.Assert.assertThat;
28   
 
29    public class LineWrapperOutputStreamTest
30    {
31    /** New line bytes used to wrap lines */
32    private static final String NEWLINE = System.getProperty("line.separator", "\n");
33   
 
34  1 toggle @Test
35    public void testAvoidWrapping() throws Exception
36    {
37  1 ByteArrayOutputStream baos = new ByteArrayOutputStream();
38  1 LineWrapperOutputStream lwos = new LineWrapperOutputStream(baos, 10);
39  1 lwos.write("12345".getBytes());
40  1 lwos.write("1234567890".getBytes(),5,4);
41  1 lwos.close();
42  1 assertThat(baos.toString(), equalTo("123456789"));
43    }
44   
 
45  1 toggle @Test
46    public void testExactWrapping() throws Exception
47    {
48  1 ByteArrayOutputStream baos = new ByteArrayOutputStream();
49  1 LineWrapperOutputStream lwos = new LineWrapperOutputStream(baos, 10);
50  1 lwos.write("789012345".getBytes(),4,5);
51  1 lwos.write("67890".getBytes());
52  1 lwos.close();
53  1 assertThat(baos.toString(), equalTo("1234567890" + NEWLINE));
54    }
55   
 
56  1 toggle @Test
57    public void testMultilineWrapping() throws Exception
58    {
59  1 ByteArrayOutputStream baos = new ByteArrayOutputStream();
60  1 LineWrapperOutputStream lwos = new LineWrapperOutputStream(baos, 10);
61  1 lwos.write("12345".getBytes());
62  1 lwos.write("3456789012345678".getBytes(),3,10);
63  1 lwos.write("6789012345".getBytes(),0,7);
64  1 lwos.close();
65  1 assertThat(baos.toString(), equalTo("1234567890" + NEWLINE + "1234567890" + NEWLINE + "12"));
66    }
67   
 
68  1 toggle @Test
69    public void testOnByteWrapping() throws Exception
70    {
71  1 ByteArrayOutputStream baos = new ByteArrayOutputStream();
72  1 LineWrapperOutputStream lwos = new LineWrapperOutputStream(baos, 10);
73  1 lwos.write("123456789".getBytes());
74  1 lwos.write("0".getBytes()[0]);
75  1 lwos.write("12345".getBytes());
76  1 lwos.close();
77  1 assertThat(baos.toString(), equalTo("1234567890" + NEWLINE + "12345"));
78    }
79    }