Permalink
Browse files

Simplify of the SimpleMsgTest.

* Make use @Before to prepare PrintStream and OutputStream for each test.
* Shortening the names used in the tests
  • Loading branch information...
1 parent b877bbf commit 4da3acd39560b99dcdb10a6a9339e43bdbe250f2 @gwieczorek gwieczorek committed May 8, 2014
Showing with 61 additions and 55 deletions.
  1. +1 −0 CREDITS
  2. +60 −55 jpos/src/test/java/org/jpos/util/SimpleMsgTest.java
View
@@ -87,6 +87,7 @@ Pugazhendhi T <pugazhendhiobs@gmail.com>
Juan Pablo Torres <torresj@cabal.coop>
Bjarne Henriksen <bjarne.henriksen@gmail.com>
Michał Wiercioch <michal.wiercioch@gmail.com>
+Grzegorz Wieczorek <grw1@wp.pl>
Contributors from other OpenSource projects
-------------------------------------------
@@ -19,153 +19,158 @@
package org.jpos.util;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import org.jpos.iso.ISOUtil;
+import org.junit.Before;
import org.junit.Test;
public class SimpleMsgTest {
+ PrintStream p;
+ ByteArrayOutputStream os;
+ private static final String NL = System.getProperty("line.separator");
+
+ @Before
+ public void setUp() {
+ os = new ByteArrayOutputStream();
+ try {
+ p = new PrintStream(os, true, ISOUtil.ENCODING);
+ } catch (UnsupportedEncodingException ex) {
+ fail(ex.getMessage());
+ }
+ }
+
@Test
public void testConstructor() throws Throwable {
- SimpleMsg simpleMsg = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", true);
+ SimpleMsg simpleMsg = new SimpleMsg("tag", "Some Name", true);
assertEquals("simpleMsg.msgContent", Boolean.TRUE, simpleMsg.msgContent);
- assertEquals("simpleMsg.tagName", "testSimpleMsgTagName", simpleMsg.tagName);
- assertEquals("simpleMsg.msgName", "testSimpleMsgMsgName", simpleMsg.msgName);
+ assertEquals("simpleMsg.tagName", "tag", simpleMsg.tagName);
+ assertEquals("simpleMsg.msgName", "Some Name", simpleMsg.msgName);
}
@Test
public void testConstructor1() throws Throwable {
- SimpleMsg simpleMsg = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", "testString");
+ SimpleMsg simpleMsg = new SimpleMsg("tag", "Some Name", "testString");
assertEquals("simpleMsg.msgContent", "testString", simpleMsg.msgContent);
- assertEquals("simpleMsg.tagName", "testSimpleMsgTagName", simpleMsg.tagName);
- assertEquals("simpleMsg.msgName", "testSimpleMsgMsgName", simpleMsg.msgName);
+ assertEquals("simpleMsg.tagName", "tag", simpleMsg.tagName);
+ assertEquals("simpleMsg.msgName", "Some Name", simpleMsg.msgName);
}
@Test
public void testConstructor2() throws Throwable {
- SimpleMsg simpleMsg = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", 100L);
- assertEquals("simpleMsg.msgContent", Long.valueOf(100L), simpleMsg.msgContent);
- assertEquals("simpleMsg.tagName", "testSimpleMsgTagName", simpleMsg.tagName);
- assertEquals("simpleMsg.msgName", "testSimpleMsgMsgName", simpleMsg.msgName);
+ SimpleMsg simpleMsg = new SimpleMsg("tag", "Some Name", 100L);
+ assertEquals("simpleMsg.msgContent", 100L, simpleMsg.msgContent);
+ assertEquals("simpleMsg.tagName", "tag", simpleMsg.tagName);
+ assertEquals("simpleMsg.msgName", "Some Name", simpleMsg.msgName);
}
@Test
public void testConstructor3() throws Throwable {
- SimpleMsg simpleMsg = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", 100);
- assertEquals("simpleMsg.msgContent", Integer.valueOf(100), simpleMsg.msgContent);
- assertEquals("simpleMsg.tagName", "testSimpleMsgTagName", simpleMsg.tagName);
- assertEquals("simpleMsg.msgName", "testSimpleMsgMsgName", simpleMsg.msgName);
+ SimpleMsg simpleMsg = new SimpleMsg("tag", "Some Name", 100);
+ assertEquals("simpleMsg.msgContent", 100, simpleMsg.msgContent);
+ assertEquals("simpleMsg.tagName", "tag", simpleMsg.tagName);
+ assertEquals("simpleMsg.msgName", "Some Name", simpleMsg.msgName);
}
@Test
public void testConstructor4() throws Throwable {
- SimpleMsg simpleMsg = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", (short) 100);
- assertEquals("simpleMsg.msgContent", Short.valueOf((short) 100), simpleMsg.msgContent);
- assertEquals("simpleMsg.tagName", "testSimpleMsgTagName", simpleMsg.tagName);
- assertEquals("simpleMsg.msgName", "testSimpleMsgMsgName", simpleMsg.msgName);
+ SimpleMsg simpleMsg = new SimpleMsg("tag", "Some Name", (short) 100);
+ assertEquals("simpleMsg.msgContent", (short) 100, simpleMsg.msgContent);
+ assertEquals("simpleMsg.tagName", "tag", simpleMsg.tagName);
+ assertEquals("simpleMsg.msgName", "Some Name", simpleMsg.msgName);
}
@Test
public void testConstructor5() throws Throwable {
byte[] msgContent = new byte[0];
- SimpleMsg simpleMsg = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", msgContent);
+ SimpleMsg simpleMsg = new SimpleMsg("tag", "Some Name", msgContent);
assertEquals("simpleMsg.msgContent", "", simpleMsg.msgContent);
- assertEquals("simpleMsg.tagName", "testSimpleMsgTagName", simpleMsg.tagName);
- assertEquals("simpleMsg.msgName", "testSimpleMsgMsgName", simpleMsg.msgName);
+ assertEquals("simpleMsg.tagName", "tag", simpleMsg.tagName);
+ assertEquals("simpleMsg.msgName", "Some Name", simpleMsg.msgName);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testConstructorThrowsNullPointerException() throws Throwable {
- try {
- new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", (byte[]) null);
- fail("Expected NullPointerException to be thrown");
- } catch (NullPointerException ex) {
- assertNull("ex.getMessage()", ex.getMessage());
- }
+ new SimpleMsg("tag", "Some Name", (byte[]) null);
}
@Test
public void testDump() throws Throwable {
- PrintStream p = new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1");
- new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName",
- 100L)).dump(p, "testSimpleMsgIndent");
+ new SimpleMsg("tag", "Some Name", new SimpleMsg("inner-tag", "Inner Name",
+ 100L)).dump(p, "--||--");
assertTrue("Test completed without Exception", true);
}
@Test
public void testDump1() throws Throwable {
SimpleMsg[] msgContent = new SimpleMsg[0];
- SimpleMsg simpleMsg = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", msgContent);
+ SimpleMsg simpleMsg = new SimpleMsg("inner-tag", "Inner Name", msgContent);
SimpleMsg[] msgContent2 = new SimpleMsg[2];
msgContent2[0] = simpleMsg;
msgContent2[1] = simpleMsg;
- PrintStream p = new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1");
- new SimpleMsg("testSimpleMsgTagName1", "testSimpleMsgMsgName1", msgContent2).dump(p, "testSimpleMsgIndent");
+ new SimpleMsg("tag", "Some Name", msgContent2).dump(p, "--||--");
assertTrue("Test completed without Exception", true);
}
@Test
public void testDump2() throws Throwable {
SimpleMsg[] msgContent = new SimpleMsg[0];
SimpleMsg[] msgContent2 = new SimpleMsg[3];
- msgContent2[0] = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", "~@%&|K}Id]+l\\");
- msgContent2[1] = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", (short) 100);
- msgContent2[2] = new SimpleMsg("testSimpleMsgTagName1", "testSimpleMsgMsgName1", msgContent);
- PrintStream p = new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1");
- new SimpleMsg("testSimpleMsgTagName2", "testSimpleMsgMsgName2", msgContent2).dump(p, "testSimpleMsgIndent");
+ msgContent2[0] = new SimpleMsg("inner-tag1", "Inner Name1", "~@%&|K}Id]+l\\");
+ msgContent2[1] = new SimpleMsg("inner-tag2", "Inner Name2", (short) 100);
+ msgContent2[2] = new SimpleMsg("inner-tag3", "Inner Name3", msgContent);
+ new SimpleMsg("tag", "Some Name", msgContent2).dump(p, "--||--");
assertTrue("Test completed without Exception", true);
}
@Test
public void testDump3() throws Throwable {
- PrintStream p = new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1");
- new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", "~@%&|K}Id]+l\\").dump(p, "testSimpleMsgIndent");
+ new SimpleMsg("tag", "Some Name", "~@%&|K}Id]+l\\").dump(p, "--||--");
assertTrue("Test completed without Exception", true);
}
@Test
public void testDump4() throws Throwable {
- PrintStream p = new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1");
SimpleMsg[] msgContent = new SimpleMsg[0];
- new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", msgContent).dump(p, "testSimpleMsgIndent");
+ new SimpleMsg("tag", "Some Name", msgContent).dump(p, "--||--");
assertTrue("Test completed without Exception", true);
}
@Test(expected = NullPointerException.class)
public void testDumpThrowsNullPointerException() throws Throwable {
- PrintStream p = new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1");
- new SimpleMsg("testSimpleMsgTagName1", "testSimpleMsgMsgName1", new SimpleMsg("testSimpleMsgTagName",
- "testSimpleMsgMsgName", (Object) null)).dump(p, "testSimpleMsgIndent");
+ new SimpleMsg("tag", "Some Name", new SimpleMsg("inner-tag",
+ "Inner Name", (Object) null)).dump(p, "--||--");
}
@Test(expected = NullPointerException.class)
public void testDumpThrowsNullPointerException1() throws Throwable {
- PrintStream p = new PrintStream(new ByteArrayOutputStream());
+ PrintStream ps = new PrintStream(new ByteArrayOutputStream());
SimpleMsg[] msgContent = new SimpleMsg[4];
- msgContent[0] = new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", 100);
- new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", msgContent).dump(p, "testSimpleMsgIndent");
+ msgContent[0] = new SimpleMsg("inner-tag", "Inner Name", 100);
+ new SimpleMsg("tag", "Some Name", msgContent).dump(ps, "--||--");
}
@Test(expected = NullPointerException.class)
public void testDumpThrowsNullPointerException2() throws Throwable {
- PrintStream p = new PrintStream(new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1"), false, "UTF-16BE");
- new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", (Object) null).dump(p, "testSimpleMsgIndent");
+ PrintStream ps = new PrintStream(p, false, "UTF-16BE");
+ new SimpleMsg("tag", "Some Name", (Object) null).dump(ps, "--||--");
}
@Test(expected = NullPointerException.class)
public void testDumpThrowsNullPointerException4() throws Throwable {
SimpleMsg[] msgContent = new SimpleMsg[4];
- PrintStream p = new PrintStream(new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1"), false, "ISO-8859-1");
- new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", msgContent).dump(p, "testSimpleMsgIndent");
+ PrintStream ps = new PrintStream(p, false, ISOUtil.ENCODING);
+ new SimpleMsg("tag", "Some Name", msgContent).dump(ps, "--||--");
}
@Test(expected = NullPointerException.class)
public void testDumpThrowsNullPointerException5() throws Throwable {
- new SimpleMsg("testSimpleMsgTagName", "testSimpleMsgMsgName", 100L).dump(null, "testSimpleMsgIndent");
+ new SimpleMsg("tag", "Some Name", 100L).dump(null, "--||--");
}
}

0 comments on commit 4da3acd

Please sign in to comment.