Modified: poi/trunk/src/testcases/org/apache/poi/util/TestBitField.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestBitField.java?rev=1872041&r1=1872040&r2=1872041&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/util/TestBitField.java (original) +++ poi/trunk/src/testcases/org/apache/poi/util/TestBitField.java Fri Dec 27 23:00:13 2019 @@ -17,18 +17,20 @@ package org.apache.poi.util; -import junit.framework.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; /** * Class to test BitField functionality - * - * @author Marc Johnson - * @author Glen Stampoultzis (gst...@iprimus.com.au) */ -public final class TestBitField extends TestCase { +public final class TestBitField { private static BitField bf_multi = BitFieldFactory.getInstance(0x3F80); private static BitField bf_single = BitFieldFactory.getInstance(0x4000); + @Test public void testGetValue() { assertEquals(bf_multi.getValue(-1), 127); assertEquals(bf_multi.getValue(0), 0); @@ -36,6 +38,7 @@ public final class TestBitField extends assertEquals(bf_single.getValue(0), 0); } + @Test public void testGetShortValue() { assertEquals(bf_multi.getShortValue(( short ) -1), ( short ) 127); assertEquals(bf_multi.getShortValue(( short ) 0), ( short ) 0); @@ -43,6 +46,7 @@ public final class TestBitField extends assertEquals(bf_single.getShortValue(( short ) 0), ( short ) 0); } + @Test public void testGetRawValue() { assertEquals(bf_multi.getRawValue(-1), 0x3F80); assertEquals(bf_multi.getRawValue(0), 0); @@ -50,6 +54,7 @@ public final class TestBitField extends assertEquals(bf_single.getRawValue(0), 0); } + @Test public void testGetShortRawValue() { assertEquals(bf_multi.getShortRawValue(( short ) -1), ( short ) 0x3F80); @@ -59,6 +64,7 @@ public final class TestBitField extends assertEquals(bf_single.getShortRawValue(( short ) 0), ( short ) 0); } + @Test public void testIsSet() { assertFalse(bf_multi.isSet(0)); for (int j = 0x80; j <= 0x3F80; j += 0x80) @@ -69,6 +75,7 @@ public final class TestBitField extends assertTrue(bf_single.isSet(0x4000)); } + @Test public void testIsAllSet() { for (int j = 0; j < 0x3F80; j += 0x80) { @@ -79,6 +86,7 @@ public final class TestBitField extends assertTrue(bf_single.isAllSet(0x4000)); } + @Test public void testSetValue() { for (int j = 0; j < 128; j++) { @@ -98,6 +106,7 @@ public final class TestBitField extends assertEquals(bf_single.setValue(0x4000, 2), 0); } + @Test public void testSetShortValue() { for (int j = 0; j < 128; j++) { @@ -125,6 +134,7 @@ public final class TestBitField extends ( short ) 0); } + @Test public void testByte() { assertEquals(1, BitFieldFactory.getInstance(1).setByteBoolean(( byte ) 0, true)); assertEquals(2, BitFieldFactory.getInstance(2).setByteBoolean(( byte ) 0, true)); @@ -151,26 +161,31 @@ public final class TestBitField extends assertFalse(BitFieldFactory.getInstance(0x40).isSet(clearedBit)); } + @Test public void testClear() { assertEquals(bf_multi.clear(-1), 0xFFFFC07F); assertEquals(bf_single.clear(-1), 0xFFFFBFFF); } + @Test public void testClearShort() { assertEquals(bf_multi.clearShort(( short ) -1), ( short ) 0xC07F); assertEquals(bf_single.clearShort(( short ) -1), ( short ) 0xBFFF); } + @Test public void testSet() { assertEquals(bf_multi.set(0), 0x3F80); assertEquals(bf_single.set(0), 0x4000); } + @Test public void testSetShort() { assertEquals(bf_multi.setShort(( short ) 0), ( short ) 0x3F80); assertEquals(bf_single.setShort(( short ) 0), ( short ) 0x4000); } + @Test public void testSetBoolean() { assertEquals(bf_multi.set(0), bf_multi.setBoolean(0, true)); assertEquals(bf_single.set(0), bf_single.setBoolean(0, true)); @@ -178,6 +193,7 @@ public final class TestBitField extends assertEquals(bf_single.clear(-1), bf_single.setBoolean(-1, false)); } + @Test public void testSetShortBoolean() { assertEquals(bf_multi.setShort(( short ) 0), bf_multi.setShortBoolean(( short ) 0, true)); @@ -188,7 +204,8 @@ public final class TestBitField extends assertEquals(bf_single.clearShort(( short ) -1), bf_single.setShortBoolean(( short ) -1, false)); } - + + @Test public void testSetLargeValues() { final BitField bf1 = new BitField(0xF), bf2 = new BitField(0xF0000000); int a = 0;
Modified: poi/trunk/src/testcases/org/apache/poi/util/TestByteField.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestByteField.java?rev=1872041&r1=1872040&r2=1872041&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/util/TestByteField.java (original) +++ poi/trunk/src/testcases/org/apache/poi/util/TestByteField.java Fri Dec 27 23:00:13 2019 @@ -18,73 +18,58 @@ package org.apache.poi.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.IOException; -import junit.framework.TestCase; +import org.junit.Test; /** - * Title: Unit test for ByteField class - * Description: Unit test for ByteField class - * @author Marc Johnson (mjohnson at apache dot org) + * Unit test for ByteField class */ -public final class TestByteField extends TestCase { +public final class TestByteField { - private static final byte[] _test_array = - { + private static final byte[] _test_array = { Byte.MIN_VALUE, ( byte ) -1, ( byte ) 0, ( byte ) 1, Byte.MAX_VALUE }; + @Test public void testConstructors() { - try - { + try { new ByteField(-1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } ByteField field = new ByteField(2); assertEquals(( byte ) 0, field.get()); - try - { + try { new ByteField(-1, ( byte ) 1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new ByteField(2, ( byte ) 3); assertEquals(( byte ) 3, field.get()); byte[] array = new byte[ 3 ]; - try - { + try { new ByteField(-1, ( byte ) 1, array); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new ByteField(2, ( byte ) 4, array); assertEquals(( byte ) 4, field.get()); assertEquals(( byte ) 4, array[ 2 ]); array = new byte[ 2 ]; - try - { + try { new ByteField(2, ( byte ) 5, array); fail("should have gotten ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } for (byte b : _test_array) { @@ -94,12 +79,12 @@ public final class TestByteField extends } } + @Test public void testSet() { ByteField field = new ByteField(0); byte[] array = new byte[ 1 ]; - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { field.set(_test_array[ j ]); assertEquals("testing _1 " + j, _test_array[ j ], field.get()); field = new ByteField(0); @@ -109,29 +94,26 @@ public final class TestByteField extends } } + @Test public void testReadFromBytes() { ByteField field = new ByteField(1); byte[] array = new byte[ 1 ]; - try - { + try { field.readFromBytes(array); fail("should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new ByteField(0); - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { array[ 0 ] = _test_array[ j ]; field.readFromBytes(array); assertEquals("testing " + j, _test_array[ j ], field.get()); } } + @Test public void testReadFromStream() throws IOException { ByteField field = new ByteField(0); byte[] buffer = new byte[ _test_array.length ]; @@ -139,13 +121,13 @@ public final class TestByteField extends System.arraycopy(_test_array, 0, buffer, 0, buffer.length); ByteArrayInputStream stream = new ByteArrayInputStream(buffer); - for (int j = 0; j < buffer.length; j++) - { + for (int j = 0; j < buffer.length; j++) { field.readFromStream(stream); assertEquals("Testing " + j, _test_array[ j ], field.get()); } } + @Test public void testWriteToBytes() { ByteField field = new ByteField(0); byte[] array = new byte[ 1 ]; Modified: poi/trunk/src/testcases/org/apache/poi/util/TestIntegerField.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestIntegerField.java?rev=1872041&r1=1872040&r2=1872041&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/util/TestIntegerField.java (original) +++ poi/trunk/src/testcases/org/apache/poi/util/TestIntegerField.java Fri Dec 27 23:00:13 2019 @@ -17,32 +17,28 @@ package org.apache.poi.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.IOException; -import junit.framework.TestCase; +import org.junit.Test; /** * Test IntegerField code - * - * @author Marc Johnson (mjohnson at apache dot org) */ -public final class TestIntegerField extends TestCase { +public final class TestIntegerField { - private static final int[] _test_array = - { - Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE - }; + private static final int[] _test_array = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE}; + @Test public void testConstructors() { try { new IntegerField(-1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } IntegerField field = new IntegerField(2); @@ -52,10 +48,7 @@ public final class TestIntegerField exte { new IntegerField(-1, 1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new IntegerField(2, 0x12345678); @@ -66,10 +59,7 @@ public final class TestIntegerField exte { new IntegerField(-1, 1, array); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new IntegerField(2, 0x12345678, array); @@ -83,10 +73,7 @@ public final class TestIntegerField exte { new IntegerField(2, 5, array); fail("should have gotten ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } for (int element : _test_array) { @@ -96,12 +83,12 @@ public final class TestIntegerField exte } } + @Test public void testSet() { IntegerField field = new IntegerField(0); byte[] array = new byte[ 4 ]; - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { field.set(_test_array[ j ]); assertEquals("testing _1 " + j, _test_array[ j ], field.get()); field = new IntegerField(0); @@ -121,23 +108,19 @@ public final class TestIntegerField exte } } + @Test public void testReadFromBytes() { IntegerField field = new IntegerField(1); byte[] array = new byte[ 4 ]; - try - { + try { field.readFromBytes(array); fail("should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new IntegerField(0); - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { array[ 0 ] = ( byte ) (_test_array[ j ] % 256); array[ 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256); array[ 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256); @@ -147,12 +130,12 @@ public final class TestIntegerField exte } } + @Test public void testReadFromStream() throws IOException { IntegerField field = new IntegerField(0); byte[] buffer = new byte[ _test_array.length * 4 ]; - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { buffer[ (j * 4) + 0 ] = ( byte ) (_test_array[ j ] % 256); buffer[ (j * 4) + 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256); buffer[ (j * 4) + 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256); @@ -160,13 +143,13 @@ public final class TestIntegerField exte } ByteArrayInputStream stream = new ByteArrayInputStream(buffer); - for (int j = 0; j < buffer.length / 4; j++) - { + for (int j = 0; j < buffer.length / 4; j++) { field.readFromStream(stream); assertEquals("Testing " + j, _test_array[ j ], field.get()); } } + @Test public void testWriteToBytes() { IntegerField field = new IntegerField(0); byte[] array = new byte[ 4 ]; Modified: poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java?rev=1872041&r1=1872040&r2=1872041&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java (original) +++ poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java Fri Dec 27 23:00:13 2019 @@ -18,43 +18,47 @@ package org.apache.poi.util; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; /** * Class to test {@link LittleEndianInputStream} and {@link LittleEndianOutputStream} - * - * @author Josh Micich */ -public final class TestLittleEndianStreams extends TestCase { +public final class TestLittleEndianStreams { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test public void testRead() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - LittleEndianOutput leo = new LittleEndianOutputStream(baos); - leo.writeInt(12345678); - leo.writeShort(12345); - leo.writeByte(123); - leo.writeShort(40000); - leo.writeByte(200); - leo.writeLong(1234567890123456789L); - leo.writeDouble(123.456); - ((LittleEndianOutputStream)leo).close(); - - LittleEndianInput lei = new LittleEndianInputStream(new ByteArrayInputStream(baos.toByteArray())); - - assertEquals(12345678, lei.readInt()); - assertEquals(12345, lei.readShort()); - assertEquals(123, lei.readByte()); - assertEquals(40000, lei.readUShort()); - assertEquals(200, lei.readUByte()); - assertEquals(1234567890123456789L, lei.readLong()); - assertEquals(123.456, lei.readDouble(), 0.0); - ((LittleEndianInputStream)lei).close(); + try (LittleEndianOutputStream leo = new LittleEndianOutputStream(baos)) { + leo.writeInt(12345678); + leo.writeShort(12345); + leo.writeByte(123); + leo.writeShort(40000); + leo.writeByte(200); + leo.writeLong(1234567890123456789L); + leo.writeDouble(123.456); + } + + try (LittleEndianInputStream lei = new LittleEndianInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(12345678, lei.readInt()); + assertEquals(12345, lei.readShort()); + assertEquals(123, lei.readByte()); + assertEquals(40000, lei.readUShort()); + assertEquals(200, lei.readUByte()); + assertEquals(1234567890123456789L, lei.readLong()); + assertEquals(123.456, lei.readDouble(), 0.0); + } } /** @@ -62,6 +66,7 @@ public final class TestLittleEndianStrea * had an error which resulted in the data being read and written back to the source byte * array. */ + @Test public void testReadFully() { byte[] srcBuf = HexRead.readFromString("99 88 77 66 55 44 33"); LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf); @@ -72,9 +77,8 @@ public final class TestLittleEndianStrea byte[] actBuf = new byte[4]; lei.readFully(actBuf); - if (actBuf[0] == 0x00 && srcBuf[0] == 0x77 && srcBuf[3] == 0x44) { - throw new AssertionFailedError("Identified bug in readFully() - source buffer was modified"); - } + assertFalse("Identified bug in readFully() - source buffer was modified", + actBuf[0] == 0x00 && srcBuf[0] == 0x77 && srcBuf[3] == 0x44); byte[] expBuf = HexRead.readFromString("77 66 55 44"); assertArrayEquals(actBuf, expBuf); @@ -82,6 +86,7 @@ public final class TestLittleEndianStrea assertEquals(0, lei.available()); } + @Test public void testBufferOverrun() { byte[] srcBuf = HexRead.readFromString("99 88 77"); LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf); @@ -90,37 +95,30 @@ public final class TestLittleEndianStrea assertEquals(0x8899, lei.readUShort()); // only one byte left, so this should fail - try { - lei.readFully(new byte[4]); - fail("Should catch exception here"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains("Buffer overrun")); - } + thrown.expect(RuntimeException.class); + thrown.expectMessage("Buffer overrun"); + lei.readFully(new byte[4]); } + @Test public void testBufferOverrunStartOffset() { byte[] srcBuf = HexRead.readFromString("99 88 77 88 99"); LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf, 2); // only one byte left, so this should fail - try { - lei.readFully(new byte[4]); - fail("Should catch exception here"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains("Buffer overrun")); - } + thrown.expect(RuntimeException.class); + thrown.expectMessage("Buffer overrun"); + lei.readFully(new byte[4]); } + @Test public void testBufferOverrunStartOffset2() { byte[] srcBuf = HexRead.readFromString("99 88 77 88 99"); LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf, 2, 2); // only one byte left, so this should fail - try { - lei.readFully(new byte[4]); - fail("Should catch exception here"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains("Buffer overrun")); - } + thrown.expect(RuntimeException.class); + thrown.expectMessage("Buffer overrun"); + lei.readFully(new byte[4]); } } Modified: poi/trunk/src/testcases/org/apache/poi/util/TestLongField.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestLongField.java?rev=1872041&r1=1872040&r2=1872041&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/util/TestLongField.java (original) +++ poi/trunk/src/testcases/org/apache/poi/util/TestLongField.java Fri Dec 27 23:00:13 2019 @@ -17,59 +17,50 @@ package org.apache.poi.util; -import junit.framework.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.junit.Test; /** * Test LongField code - * - * @author Marc Johnson (mjohnson at apache dot org) */ -public final class TestLongField extends TestCase { +public final class TestLongField { static private final long[] _test_array = { Long.MIN_VALUE, -1L, 0L, 1L, Long.MAX_VALUE }; - public void testConstructors() - { - try - { + @Test + public void testConstructors() { + try { new LongField(-1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } LongField field = new LongField(2); assertEquals(0L, field.get()); - try - { + try { new LongField(-1, 1L); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new LongField(2, 0x123456789ABCDEF0L); assertEquals(0x123456789ABCDEF0L, field.get()); byte[] array = new byte[ 10 ]; - try - { + try { new LongField(-1, 1L, array); fail("Should have caught ArrayIndexOutOfBoundsException"); } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new LongField(2, 0x123456789ABCDEF0L, array); @@ -83,14 +74,10 @@ public final class TestLongField extends assertEquals(( byte ) 0x34, array[ 8 ]); assertEquals(( byte ) 0x12, array[ 9 ]); array = new byte[ 9 ]; - try - { + try { new LongField(2, 5L, array); fail("should have gotten ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } for (long element : _test_array) { @@ -100,13 +87,12 @@ public final class TestLongField extends } } - public void testSet() - { + @Test + public void testSet() { LongField field = new LongField(0); byte[] array = new byte[ 8 ]; - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { field.set(_test_array[ j ]); assertEquals("testing _1 " + j, _test_array[ j ], field.get()); field = new LongField(0); @@ -138,24 +124,19 @@ public final class TestLongField extends } } - public void testReadFromBytes() - { + @Test + public void testReadFromBytes() { LongField field = new LongField(1); byte[] array = new byte[ 8 ]; - try - { + try { field.readFromBytes(array); fail("should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new LongField(0); - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { array[ 0 ] = ( byte ) (_test_array[ j ] % 256); array[ 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256); array[ 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256); @@ -169,15 +150,13 @@ public final class TestLongField extends } } - public void testReadFromStream() - throws IOException - { + @Test + public void testReadFromStream() throws IOException { LongField field = new LongField(0); byte[] buffer = new byte[ _test_array.length * 8 ]; - for (int j = 0; j < _test_array.length; j++) - { - buffer[ (j * 8) + 0 ] = ( byte ) ((_test_array[ j ] >> 0) % 256); + for (int j = 0; j < _test_array.length; j++) { + buffer[ (j * 8) ] = ( byte ) ((_test_array[ j ] ) % 256); buffer[ (j * 8) + 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256); buffer[ (j * 8) + 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256); buffer[ (j * 8) + 3 ] = ( byte ) ((_test_array[ j ] >> 24) % 256); @@ -188,15 +167,14 @@ public final class TestLongField extends } ByteArrayInputStream stream = new ByteArrayInputStream(buffer); - for (int j = 0; j < buffer.length / 8; j++) - { + for (int j = 0; j < buffer.length / 8; j++) { field.readFromStream(stream); assertEquals("Testing " + j, _test_array[ j ], field.get()); } } - public void testWriteToBytes() - { + @Test + public void testWriteToBytes() { LongField field = new LongField(0); byte[] array = new byte[ 8 ]; Modified: poi/trunk/src/testcases/org/apache/poi/util/TestPOILogFactory.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestPOILogFactory.java?rev=1872041&r1=1872040&r2=1872041&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/util/TestPOILogFactory.java (original) +++ poi/trunk/src/testcases/org/apache/poi/util/TestPOILogFactory.java Fri Dec 27 23:00:13 2019 @@ -17,19 +17,15 @@ package org.apache.poi.util; -import junit.framework.TestCase; +import org.junit.Test; -/** - * @author Marc Johnson (mjohnson at apache dot org) - * @author Glen Stampoultzis (glens at apache.org) - * @author Nicola Ken Barozzi (nicolaken at apache.org) - */ -public final class TestPOILogFactory extends TestCase { +public final class TestPOILogFactory { /** * test log creation */ + @Test public void testLog() { //NKB Testing only that logging classes use gives no exception // Since logging can be disabled, no checking of logging Modified: poi/trunk/src/testcases/org/apache/poi/util/TestShortField.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestShortField.java?rev=1872041&r1=1872040&r2=1872041&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/util/TestShortField.java (original) +++ poi/trunk/src/testcases/org/apache/poi/util/TestShortField.java Fri Dec 27 23:00:13 2019 @@ -17,59 +17,46 @@ package org.apache.poi.util; -import junit.framework.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.junit.Test; /** * Test ShortField code - * - * @author Marc Johnson (mjohnson at apache dot org) */ -public final class TestShortField extends TestCase { +public final class TestShortField { - private static final short[] _test_array = - { - Short.MIN_VALUE, ( short ) -1, ( short ) 0, ( short ) 1, - Short.MAX_VALUE - }; + private static final short[] _test_array = {Short.MIN_VALUE, -1, 0, 1, Short.MAX_VALUE}; + @Test public void testConstructors() { - try - { + try { new ShortField(-1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } ShortField field = new ShortField(2); assertEquals(0, field.get()); - try - { + try { new ShortField(-1, ( short ) 1); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new ShortField(2, ( short ) 0x1234); assertEquals(0x1234, field.get()); byte[] array = new byte[ 4 ]; - try - { + try { new ShortField(-1, ( short ) 1, array); fail("Should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new ShortField(2, ( short ) 0x1234, array); @@ -77,14 +64,10 @@ public final class TestShortField extend assertEquals(( byte ) 0x34, array[ 2 ]); assertEquals(( byte ) 0x12, array[ 3 ]); array = new byte[ 3 ]; - try - { + try { new ShortField(2, ( short ) 5, array); fail("should have gotten ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } for (short element : _test_array) { @@ -94,12 +77,12 @@ public final class TestShortField extend } } + @Test public void testSet() { ShortField field = new ShortField(0); byte[] array = new byte[ 2 ]; - for (int j = 0; j < _test_array.length; j++) - { + for (int j = 0; j < _test_array.length; j++) { field.set(_test_array[ j ]); assertEquals("testing _1 " + j, _test_array[ j ], field.get()); field = new ShortField(0); @@ -113,18 +96,15 @@ public final class TestShortField extend } } + @Test public void testReadFromBytes() { ShortField field = new ShortField(1); byte[] array = new byte[ 2 ]; - try - { + try { field.readFromBytes(array); fail("should have caught ArrayIndexOutOfBoundsException"); - } - catch (ArrayIndexOutOfBoundsException ignored_e) - { - + } catch (ArrayIndexOutOfBoundsException ignored_e) { // as expected } field = new ShortField(0); @@ -137,13 +117,14 @@ public final class TestShortField extend } } + @Test public void testReadFromStream() throws IOException { ShortField field = new ShortField(0); byte[] buffer = new byte[ _test_array.length * 2 ]; for (int j = 0; j < _test_array.length; j++) { - buffer[ (j * 2) + 0 ] = ( byte ) (_test_array[ j ] % 256); + buffer[ (j * 2) ] = ( byte ) (_test_array[ j ] % 256); buffer[ (j * 2) + 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256); } ByteArrayInputStream stream = new ByteArrayInputStream(buffer); @@ -155,6 +136,7 @@ public final class TestShortField extend } } + @Test public void testWriteToBytes() { ShortField field = new ShortField(0); byte[] array = new byte[ 2 ]; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org