X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aaf%2Fauthz.git;a=blobdiff_plain;f=misc%2Fenv%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fmisc%2Fenv%2Futil%2FJU_StringBuilderOutputStreamTest.java;h=b55e2545ee331cda3c69b7409e742655d8f502f9;hp=377a2891bc96d2b31a9fcf867a9c5f7c88ca4f3f;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderOutputStreamTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderOutputStreamTest.java index 377a2891..b55e2545 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderOutputStreamTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderOutputStreamTest.java @@ -31,105 +31,105 @@ import org.junit.Test; public class JU_StringBuilderOutputStreamTest { - StringBuilderOutputStream streamBuilder; - - StringBuilder builder = new StringBuilder(); - - @Before - public void setUp() throws Exception { - streamBuilder = new StringBuilderOutputStream(builder); - } - - @Test - public void testWriteIntAndReset() { - streamBuilder.write(123); - - assertEquals("123", streamBuilder.toString()); - streamBuilder.reset(); - assertEquals("", streamBuilder.toString()); - } - - @Test - public void testWriteByteArrayWithoutException() throws IOException { - byte[] bytes = { 1, 2, 3, 4 }; - streamBuilder.write(bytes); - assertEquals(4, streamBuilder.getBuffer().length()); - - streamBuilder.write(bytes, 1, 2); - assertEquals(6, streamBuilder.getBuffer().length()); - - streamBuilder.write(bytes, 1, 0); - assertEquals(6, streamBuilder.getBuffer().length()); - - streamBuilder.append(bytes[0]); - assertEquals(7, streamBuilder.getBuffer().length()); - } - - @Test - public void testWriteByteArrayWithIndexOutOfBoundException() { - byte[] bytes = { 1, 2, 3, 4 }; - - try { - streamBuilder.write(bytes, -1, 2); - fail("This is supposed to throw IndexOutOfBounds Excetpion"); - } catch (IndexOutOfBoundsException e) { - } catch (Exception e) { - fail("This should throw only IndexOutOfBounds Exception"); - } - assertEquals(0, streamBuilder.getBuffer().length()); - - } - - @Test - public void testDefaultConstructor() throws IOException { - StringBuilderOutputStream stream = new StringBuilderOutputStream(); - - assertNotNull(stream.getBuffer()); - stream.close(); - } - - @Test - public void testConstructorWithPositiveDefaultCapacity() throws IOException { - StringBuilderOutputStream stream = new StringBuilderOutputStream(10); - - assertNotNull(stream.getBuffer()); - assertEquals(10, stream.getBuffer().capacity()); - stream.close(); - } - - @Test - public void testConstructorWithNegativeCapacityException() { - try { - StringBuilderOutputStream stream = new StringBuilderOutputStream(-1); - fail("This should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } catch (Exception e) { - fail("This should throw only IllegalArgumentException"); - } - } - - @Test - public void testWriteString() { - streamBuilder.write("1234"); - - assertEquals("1234", streamBuilder.toString()); - - streamBuilder.write("1234", 1, 2); - assertEquals("12342", streamBuilder.toString()); - } - - @Test - public void testAppendCharSequence() { - streamBuilder.append("1234"); - assertEquals("1234", streamBuilder.toString()); - - streamBuilder.append(null); - assertEquals("1234null", streamBuilder.toString()); - - streamBuilder.append("1234", 1, 2); - assertEquals("1234null2", streamBuilder.toString()); - - streamBuilder.append(null, 1, 2); - assertEquals("1234null2u", streamBuilder.toString()); - } + StringBuilderOutputStream streamBuilder; + + StringBuilder builder = new StringBuilder(); + + @Before + public void setUp() throws Exception { + streamBuilder = new StringBuilderOutputStream(builder); + } + + @Test + public void testWriteIntAndReset() { + streamBuilder.write(123); + + assertEquals("123", streamBuilder.toString()); + streamBuilder.reset(); + assertEquals("", streamBuilder.toString()); + } + + @Test + public void testWriteByteArrayWithoutException() throws IOException { + byte[] bytes = { 1, 2, 3, 4 }; + streamBuilder.write(bytes); + assertEquals(4, streamBuilder.getBuffer().length()); + + streamBuilder.write(bytes, 1, 2); + assertEquals(6, streamBuilder.getBuffer().length()); + + streamBuilder.write(bytes, 1, 0); + assertEquals(6, streamBuilder.getBuffer().length()); + + streamBuilder.append(bytes[0]); + assertEquals(7, streamBuilder.getBuffer().length()); + } + + @Test + public void testWriteByteArrayWithIndexOutOfBoundException() { + byte[] bytes = { 1, 2, 3, 4 }; + + try { + streamBuilder.write(bytes, -1, 2); + fail("This is supposed to throw IndexOutOfBounds Excetpion"); + } catch (IndexOutOfBoundsException e) { + } catch (Exception e) { + fail("This should throw only IndexOutOfBounds Exception"); + } + assertEquals(0, streamBuilder.getBuffer().length()); + + } + + @Test + public void testDefaultConstructor() throws IOException { + StringBuilderOutputStream stream = new StringBuilderOutputStream(); + + assertNotNull(stream.getBuffer()); + stream.close(); + } + + @Test + public void testConstructorWithPositiveDefaultCapacity() throws IOException { + StringBuilderOutputStream stream = new StringBuilderOutputStream(10); + + assertNotNull(stream.getBuffer()); + assertEquals(10, stream.getBuffer().capacity()); + stream.close(); + } + + @Test + public void testConstructorWithNegativeCapacityException() { + try { + StringBuilderOutputStream stream = new StringBuilderOutputStream(-1); + fail("This should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + } catch (Exception e) { + fail("This should throw only IllegalArgumentException"); + } + } + + @Test + public void testWriteString() { + streamBuilder.write("1234"); + + assertEquals("1234", streamBuilder.toString()); + + streamBuilder.write("1234", 1, 2); + assertEquals("12342", streamBuilder.toString()); + } + + @Test + public void testAppendCharSequence() { + streamBuilder.append("1234"); + assertEquals("1234", streamBuilder.toString()); + + streamBuilder.append(null); + assertEquals("1234null", streamBuilder.toString()); + + streamBuilder.append("1234", 1, 2); + assertEquals("1234null2", streamBuilder.toString()); + + streamBuilder.append(null, 1, 2); + assertEquals("1234null2u", streamBuilder.toString()); + } }