From 515a632251cd98c845c857e4d5d6b3153994dec4 Mon Sep 17 00:00:00 2001 From: Enrique Zamudio Date: Wed, 18 Dec 2013 18:13:57 -0600 Subject: [PATCH] tests for #21 --- src/test/java/j8583/TestDates.java | 4 ++-- src/test/java/j8583/TestFormats.java | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/test/java/j8583/TestDates.java b/src/test/java/j8583/TestDates.java index 399274d..e8febf9 100644 --- a/src/test/java/j8583/TestDates.java +++ b/src/test/java/j8583/TestDates.java @@ -27,7 +27,7 @@ public class TestDates { today.set(GregorianCalendar.MINUTE,0); today.set(GregorianCalendar.SECOND,0); today.set(GregorianCalendar.MILLISECOND,0); - byte[] buf = IsoType.DATE4.format(soon).getBytes(); + byte[] buf = IsoType.DATE4.format(soon, null).getBytes(); IsoValue comp = new Date4ParseInfo().parse(0, buf, 0, null); Assert.assertEquals(comp.getValue(), today.getTime()); //Now with the binary @@ -40,7 +40,7 @@ public class TestDates { @Test public void testDate10FutureTolerance() throws ParseException, IOException { Date soon = new Date(System.currentTimeMillis() + 50000); - byte[] buf = IsoType.DATE10.format(soon).getBytes(); + byte[] buf = IsoType.DATE10.format(soon, null).getBytes(); IsoValue comp = new Date10ParseInfo().parse(0, buf, 0, null); assert comp.getValue().after(new Date()); //Now with the binary diff --git a/src/test/java/j8583/TestFormats.java b/src/test/java/j8583/TestFormats.java index f7b4466..dca5df9 100644 --- a/src/test/java/j8583/TestFormats.java +++ b/src/test/java/j8583/TestFormats.java @@ -2,7 +2,9 @@ package j8583; import java.math.BigDecimal; import java.util.Date; +import java.util.TimeZone; +import org.junit.Assert; import org.junit.Test; import com.solab.iso8583.IsoType; @@ -13,14 +15,26 @@ import com.solab.iso8583.IsoType; */ public class TestFormats { - private Date date = new Date(96867296000l); + private final Date date = new Date(96867296000l); @Test public void testDateFormats() { - assert IsoType.DATE10.format(date).equals("0125213456"); - assert IsoType.DATE4.format(date).equals("0125"); - assert IsoType.DATE_EXP.format(date).equals("7301"); - assert IsoType.TIME.format(date).equals("213456"); + assert IsoType.DATE10.format(date, null).equals("0125213456"); + assert IsoType.DATE4.format(date, null).equals("0125"); + assert IsoType.DATE_EXP.format(date, null).equals("7301"); + assert IsoType.TIME.format(date, null).equals("213456"); + //Now with GMT + TimeZone gmt = TimeZone.getTimeZone("GMT"); + Assert.assertEquals("0126033456", IsoType.DATE10.format(date, gmt)); + Assert.assertEquals("0126", IsoType.DATE4.format(date, gmt)); + Assert.assertEquals("7301", IsoType.DATE_EXP.format(date, gmt)); + Assert.assertEquals("033456", IsoType.TIME.format(date, gmt)); + //And now with GMT+1 + gmt = TimeZone.getTimeZone("GMT+0100"); + Assert.assertEquals("0126043456", IsoType.DATE10.format(date, gmt)); + Assert.assertEquals("0126", IsoType.DATE4.format(date, gmt)); + Assert.assertEquals("7301", IsoType.DATE_EXP.format(date, gmt)); + Assert.assertEquals("043456", IsoType.TIME.format(date, gmt)); } @Test