Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java36
1 files changed, 20 insertions, 16 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java
index 576a8ec4d..caa1a8272 100644
--- a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 compeople AG and others.
+ * Copyright (c) 2007, 2018 compeople AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,16 +10,18 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.sar;
+import static org.junit.Assert.*;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
-import junit.framework.TestCase;
import org.eclipse.equinox.internal.p2.sar.DirectByteArrayOutputStream;
+import org.junit.Test;
/**
* Test the <code>DirectByteArrayOutputStream</code>
*/
-public class DirectByteArrayOutputStreamTest extends TestCase {
+public class DirectByteArrayOutputStreamTest {
private static final String JUST11BYTES = "just11bytes";
private static final int ELEVEN = JUST11BYTES.getBytes().length;
@@ -29,19 +31,21 @@ public class DirectByteArrayOutputStreamTest extends TestCase {
*
* @throws IOException
*/
+ @Test
public void testDBAOSConstraints() throws IOException {
- DirectByteArrayOutputStream out = new DirectByteArrayOutputStream(1024);
- out.write(JUST11BYTES.getBytes());
- assertEquals(ELEVEN, out.getBufferLength());
- assertEquals(ELEVEN, out.toByteArray().length);
- assertNotSame(out.toByteArray(), out.getBuffer());
- assertEquals(1024, out.getBuffer().length);
- assertEquals(JUST11BYTES, new String(out.getBuffer(), 0, out.getBufferLength()));
- ByteArrayInputStream in = out.getInputStream();
- assertEquals(ELEVEN, in.available());
- byte[] elevenBytes = new byte[ELEVEN];
- in.read(elevenBytes);
- assertTrue(Arrays.equals(JUST11BYTES.getBytes(), elevenBytes));
- assertEquals(-1, in.read());
+ try (DirectByteArrayOutputStream out = new DirectByteArrayOutputStream(1024)) {
+ out.write(JUST11BYTES.getBytes());
+ assertEquals(ELEVEN, out.getBufferLength());
+ assertEquals(ELEVEN, out.toByteArray().length);
+ assertNotSame(out.toByteArray(), out.getBuffer());
+ assertEquals(1024, out.getBuffer().length);
+ assertEquals(JUST11BYTES, new String(out.getBuffer(), 0, out.getBufferLength()));
+ ByteArrayInputStream in = out.getInputStream();
+ assertEquals(ELEVEN, in.available());
+ byte[] elevenBytes = new byte[ELEVEN];
+ in.read(elevenBytes);
+ assertTrue(Arrays.equals(JUST11BYTES.getBytes(), elevenBytes));
+ assertEquals(-1, in.read());
+ }
}
}

Back to the top