Example #1
0
 @Test
 public void testReadWriteExternal() throws IOException, ClassNotFoundException, ISOException {
   // given
   ByteArrayOutputStream data = new ByteArrayOutputStream();
   ObjectOutputStream ostr = new ObjectOutputStream(data);
   // when
   iSOAmount.writeExternal(ostr);
   ostr.close();
   ObjectInputStream istr = new ObjectInputStream(new ByteArrayInputStream(data.toByteArray()));
   // then
   ISOAmount pickled = new ISOAmount();
   pickled.readExternal(istr);
   istr.close();
   assertThat(pickled.getAmountAsString(), is(iSOAmount.getAmountAsString()));
 }
Example #2
0
 @Test
 public void testUnpack() {
   try {
     iSOAmount.unpack(new byte[1]);
     fail("ISOException Expected");
   } catch (ISOException isoe) {
     assertThat(isoe.getMessage(), is("Not available"));
   }
 }
Example #3
0
 @Test
 public void testUnPack2() throws IOException {
   try {
     iSOAmount.unpack((InputStream) null);
     fail("ISOException Expected");
   } catch (ISOException isoe) {
     assertThat(isoe.getMessage(), is("Not available"));
   }
 }
Example #4
0
 @Test
 public void testSetValueBadCurrencyCode() {
   try {
     iSOAmount.setValue("X23456789012");
     fail("expected exception");
   } catch (ISOException e) {
     assertThat(e.getMessage(), is("For input string: \"X23\""));
   }
 }
Example #5
0
 @Test
 public void testSetValueBadLength() {
   try {
     iSOAmount.setValue("1234");
     fail("expected invalid length ISOException");
   } catch (ISOException e) {
     assertThat(e.getMessage(), is("ISOAmount invalid length 4"));
   }
 }
Example #6
0
 @Test
 public void testDump() {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   iSOAmount.dump(new PrintStream(baos), ":-o");
   // then
   String lineSep = System.getProperty("line.separator");
   String expected =
       ":-o<field id=\"28\" currency=\"840\" type=\"amount\" value=\"10.00\"/>" + lineSep;
   assertThat(baos.toString(), is(expected));
 }
Example #7
0
 @Test
 public void testBadReadAttemptISOException() throws IOException, ClassNotFoundException {
   iSOAmount =
       new ISOAmount() {
         @Override
         public void setValue(Object obj) throws ISOException {
           throw new ISOException("yikes!");
         }
       };
   ObjectInput in = mock(ObjectInput.class);
   try {
     iSOAmount.readExternal(in);
   } catch (IOException ioe) {
     assertThat(ioe.getMessage(), is("yikes!"));
   }
 }
Example #8
0
 @Test
 public void testBadWriteAttemptISOException() throws IOException {
   iSOAmount =
       new ISOAmount() {
         @Override
         public Object getValue() throws ISOException {
           throw new ISOException("boo!");
         }
       };
   ObjectOutput oo = mock(ObjectOutput.class);
   try {
     iSOAmount.writeExternal(oo);
   } catch (IOException ioe) {
     assertThat(ioe.getMessage(), is("org.jpos.iso.ISOException: boo!"));
   }
 }
Example #9
0
 @Test
 public void testGetAmount() {
   assertThat(iSOAmount.getAmount(), is(BigDecimal.TEN.setScale(2)));
 }
Example #10
0
 @Test
 public void testGetAmountAsLegacyString() throws ISOException {
   assertThat(iSOAmount.getAmountAsLegacyString(), is("000000001000"));
 }
Example #11
0
 @Test
 public void testISOAmountInt() {
   iSOAmount = new ISOAmount(75);
   assertThat(iSOAmount.getKey(), is((Object) Integer.valueOf(75)));
 }
Example #12
0
 @Test
 public void testGetCurrencyCodeAsString() throws ISOException {
   assertThat(iSOAmount.getCurrencyCodeAsString(), is("840"));
 }
Example #13
0
 @Test
 public void testGetCurrencyCode() {
   assertThat(iSOAmount.getCurrencyCode(), is(840));
 }
Example #14
0
 @Test
 public void testGetScaleAsString() {
   assertThat(iSOAmount.getScaleAsString(), is("2"));
 }
Example #15
0
 @Test
 public void testGetScale() {
   assertThat(iSOAmount.getScale(), is(2));
 }