Author: philharveyonline Date: Fri Mar 22 09:37:07 2013 New Revision: 1459686
URL: http://svn.apache.org/r1459686 Log: PROTON-215: reformatted to adhere to Qpid code conventions Modified: qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java Modified: qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java?rev=1459686&r1=1459685&r2=1459686&view=diff ============================================================================== --- qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java (original) +++ qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java Fri Mar 22 09:37:07 2013 @@ -23,10 +23,6 @@ import org.apache.qpid.proton.ProtonFact import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.amqp.DescribedType; import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.UnsignedByte; -import org.apache.qpid.proton.amqp.UnsignedInteger; -import org.apache.qpid.proton.amqp.UnsignedLong; -import org.apache.qpid.proton.amqp.UnsignedShort; import org.apache.qpid.proton.amqp.messaging.AmqpValue; import org.apache.qpid.proton.message.Message; import org.apache.qpid.proton.message.MessageFactory; @@ -34,160 +30,183 @@ import org.apache.qpid.proton.message.Me import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertArrayEquals; import org.junit.Test; -import org.junit.Ignore; import java.lang.System; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Vector; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; -public class InteropTest { +public class InteropTest +{ - static private File findTestsInteropDir() { - File f = new File(System.getProperty("user.dir")); - while (f != null && !f.getName().equals("tests")) - f = f.getParentFile(); - if (f != null && f.isDirectory()) - return new File(f,"interop"); - else - throw new Error("Cannot find tests/interop directory"); + static private File findTestsInteropDir() + { + File f = new File(System.getProperty("user.dir")); + while (f != null && !f.getName().equals("tests")) + f = f.getParentFile(); + if (f != null && f.isDirectory()) + return new File(f, "interop"); + else + throw new Error("Cannot find tests/interop directory"); } static File testsInteropDir = findTestsInteropDir(); - byte[] getBytes(String name) throws IOException { - File f = new File(testsInteropDir, name+".amqp"); - byte[] data = new byte[(int)f.length()]; - FileInputStream fi = new FileInputStream(f); - assertEquals(f.length(), fi.read(data)); - fi.close(); - return data; + byte[] getBytes(String name) throws IOException + { + File f = new File(testsInteropDir, name + ".amqp"); + byte[] data = new byte[(int) f.length()]; + FileInputStream fi = new FileInputStream(f); + assertEquals(f.length(), fi.read(data)); + fi.close(); + return data; } - Message decodeMessage(String name) throws IOException { - byte[] data = getBytes(name); - MessageFactory mf = - new ProtonFactoryLoader<MessageFactory>(MessageFactory.class).loadFactory(); - Message m = mf.createMessage(); - m.decode(data, 0, data.length); - return m; + Message decodeMessage(String name) throws IOException + { + byte[] data = getBytes(name); + MessageFactory mf = new ProtonFactoryLoader<MessageFactory>(MessageFactory.class).loadFactory(); + Message m = mf.createMessage(); + m.decode(data, 0, data.length); + return m; } - TestDecoder createDecoder(byte[] data) { - TestDecoder td = new TestDecoder(data); - return td; + TestDecoder createDecoder(byte[] data) + { + TestDecoder td = new TestDecoder(data); + return td; } @Test - public void testMessage() throws IOException { - Message m = decodeMessage("message"); - Binary b = (Binary)(((AmqpValue)m.getBody()).getValue()); - String s = createDecoder(b.getArray()).readString(); - assertEquals("hello", s); + public void testMessage() throws IOException + { + Message m = decodeMessage("message"); + Binary b = (Binary) (((AmqpValue) m.getBody()).getValue()); + String s = createDecoder(b.getArray()).readString(); + assertEquals("hello", s); } @Test - public void testPrimitives() throws IOException { - TestDecoder d = createDecoder(getBytes("primitives")); - assertEquals(true, d.readBoolean()); - assertEquals(false, d.readBoolean()); - assertEquals(d.readUnsignedByte().intValue(), 42); - assertEquals(42, d.readUnsignedShort().intValue()); - assertEquals(-42, d.readShort().intValue()); - assertEquals(12345, d.readUnsignedInteger().intValue()); - assertEquals(-12345, d.readInteger().intValue()); - assertEquals(12345, d.readUnsignedLong().longValue()); - assertEquals(-12345, d.readLong().longValue()); - assertEquals(0.125, d.readFloat().floatValue(), 0e-10); - assertEquals(0.125, d.readDouble().doubleValue(), 0e-10); + public void testPrimitives() throws IOException + { + TestDecoder d = createDecoder(getBytes("primitives")); + assertEquals(true, d.readBoolean()); + assertEquals(false, d.readBoolean()); + assertEquals(d.readUnsignedByte().intValue(), 42); + assertEquals(42, d.readUnsignedShort().intValue()); + assertEquals(-42, d.readShort().intValue()); + assertEquals(12345, d.readUnsignedInteger().intValue()); + assertEquals(-12345, d.readInteger().intValue()); + assertEquals(12345, d.readUnsignedLong().longValue()); + assertEquals(-12345, d.readLong().longValue()); + assertEquals(0.125, d.readFloat().floatValue(), 0e-10); + assertEquals(0.125, d.readDouble().doubleValue(), 0e-10); } @Test - public void testStrings() throws IOException { - TestDecoder d = createDecoder(getBytes("strings")); - assertEquals(new Binary("abc\0defg".getBytes("UTF-8")), d.readBinary()); - assertEquals("abcdefg", d.readString()); - assertEquals(Symbol.valueOf("abcdefg"), d.readSymbol()); - assertEquals(new Binary(new byte[0]), d.readBinary()); - assertEquals("", d.readString()); - assertEquals(Symbol.valueOf(""), d.readSymbol()); + public void testStrings() throws IOException + { + TestDecoder d = createDecoder(getBytes("strings")); + assertEquals(new Binary("abc\0defg".getBytes("UTF-8")), d.readBinary()); + assertEquals("abcdefg", d.readString()); + assertEquals(Symbol.valueOf("abcdefg"), d.readSymbol()); + assertEquals(new Binary(new byte[0]), d.readBinary()); + assertEquals("", d.readString()); + assertEquals(Symbol.valueOf(""), d.readSymbol()); } @Test - public void testDescribed() throws IOException { - TestDecoder d = createDecoder(getBytes("described")); - DescribedType dt = (DescribedType)(d.readObject()); - assertEquals(Symbol.valueOf("foo-descriptor"), dt.getDescriptor()); - assertEquals("foo-value", dt.getDescribed()); + public void testDescribed() throws IOException + { + TestDecoder d = createDecoder(getBytes("described")); + DescribedType dt = (DescribedType) (d.readObject()); + assertEquals(Symbol.valueOf("foo-descriptor"), dt.getDescriptor()); + assertEquals("foo-value", dt.getDescribed()); - dt = (DescribedType)(d.readObject()); - assertEquals(12, dt.getDescriptor()); - assertEquals(13, dt.getDescribed()); + dt = (DescribedType) (d.readObject()); + assertEquals(12, dt.getDescriptor()); + assertEquals(13, dt.getDescribed()); } @Test - public void testDescribedArray() throws IOException { + public void testDescribedArray() throws IOException + { TestDecoder d = createDecoder(getBytes("described_array")); - DescribedType a[] = (DescribedType[])(d.readArray()); - for (int i = 0; i < 10; ++i) { - assertEquals(Symbol.valueOf("int-array"), a[i].getDescriptor()); - assertEquals(i, a[i].getDescribed()); - } + DescribedType a[] = (DescribedType[]) (d.readArray()); + for (int i = 0; i < 10; ++i) + { + assertEquals(Symbol.valueOf("int-array"), a[i].getDescriptor()); + assertEquals(i, a[i].getDescribed()); + } } @Test - public void testArrays() throws IOException { + public void testArrays() throws IOException + { TestDecoder d = createDecoder(getBytes("arrays")); - // int array - Vector<Integer> ints = new Vector<Integer>(); - for (int i = 0; i < 100; ++i) ints.add(new Integer(i)); - assertArrayEquals(ints.toArray(), d.readArray()); - - // String array - String strings[] = { "a", "b", "c" }; - assertArrayEquals(strings, d.readArray()); + // int array + Vector<Integer> ints = new Vector<Integer>(); + for (int i = 0; i < 100; ++i) + ints.add(new Integer(i)); + assertArrayEquals(ints.toArray(), d.readArray()); + + // String array + String strings[] = + { "a", "b", "c" }; + assertArrayEquals(strings, d.readArray()); - // Empty array + // Empty array assertArrayEquals(new Integer[0], d.readArray()); } @Test - public void testLists() throws IOException { + public void testLists() throws IOException + { TestDecoder d = createDecoder(getBytes("lists")); - List<Object> l = new ArrayList<Object>() {{ - add(new Integer(32)); - add("foo"); - add(new Boolean(true)); - }}; - assertEquals(l, d.readList()); - l.clear(); - assertEquals(l, d.readList()); + List<Object> l = new ArrayList<Object>() + { + { + add(new Integer(32)); + add("foo"); + add(new Boolean(true)); + } + }; + assertEquals(l, d.readList()); + l.clear(); + assertEquals(l, d.readList()); } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Test - public void testMaps() throws IOException { + public void testMaps() throws IOException + { TestDecoder d = createDecoder(getBytes("maps")); - Map map = new HashMap() {{ - put("one", 1); - put("two", 2); - put("three", 3); - }}; - assertEquals(map, d.readMap()); - - map = new HashMap() {{ - put(1, "one"); - put(2, "two"); - put(3, "three"); - }}; - assertEquals(map, d.readMap()); + Map map = new HashMap() + { + { + put("one", 1); + put("two", 2); + put("three", 3); + } + }; + assertEquals(map, d.readMap()); + + map = new HashMap() + { + { + put(1, "one"); + put(2, "two"); + put(3, "three"); + } + }; + assertEquals(map, d.readMap()); - map = new HashMap(); - assertEquals(map, d.readMap()); + map = new HashMap(); + assertEquals(map, d.readMap()); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
