Ignore:
Timestamp:
2016-04-03T19:25:25+02:00 (8 years ago)
Author:
Don-vip
Message:

add more unit tests

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/history/CoordinateInfoViewerTest.java

    r9958 r10108  
    44import static org.junit.Assert.assertNotNull;
    55
     6import org.junit.BeforeClass;
    67import org.junit.Test;
     8import org.openstreetmap.josm.JOSMFixture;
    79
    810/**
     
    1012 */
    1113public class CoordinateInfoViewerTest {
     14
     15    /**
     16     * Setup test.
     17     */
     18    @BeforeClass
     19    public static void setUpBeforeClass() {
     20        JOSMFixture.createUnitTestFixture().init();
     21    }
    1222
    1323    /**
  • trunk/test/unit/org/openstreetmap/josm/gui/history/HistoryBrowserDialogTest.java

    r9958 r10108  
    66import java.util.Date;
    77
     8import org.junit.BeforeClass;
    89import org.junit.Test;
     10import org.openstreetmap.josm.JOSMFixture;
    911import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1012import org.openstreetmap.josm.data.osm.User;
     
    1921 */
    2022public class HistoryBrowserDialogTest {
     23
     24    /**
     25     * Setup test.
     26     */
     27    @BeforeClass
     28    public static void setUpBeforeClass() {
     29        JOSMFixture.createUnitTestFixture().init();
     30    }
    2131
    2232    /**
  • trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java

    r10103 r10108  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertNotEquals;
     6import static org.junit.Assert.assertNotNull;
    57
    68import java.text.DateFormat;
     
    116118        assertEquals("1:00:00 AM CET", DateUtils.formatTime(new Date(123), DateFormat.LONG));
    117119    }
     120
     121    /**
     122     * Unit test of {@link DateUtils#formatDate} method.
     123     */
     124    @Test
     125    public void testFormatDate() {
     126        assertEquals("1/1/70", DateUtils.formatDate(new Date(123), DateFormat.SHORT));
     127        assertEquals("January 1, 1970", DateUtils.formatDate(new Date(123), DateFormat.LONG));
     128    }
     129
     130    /**
     131     * Unit test of {@link DateUtils#tsFromString} method.
     132     */
     133    @Test
     134    public void testTsFromString() {
     135        // UTC times
     136        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00Z"));
     137        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00"));
     138        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03 15:00:00 UTC"));
     139        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00+00"));
     140        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00-00"));
     141        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00+00:00"));
     142        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00-00:00"));
     143
     144        // UTC times with millis
     145        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00.000Z"));
     146        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00.000"));
     147        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00.000+00:00"));
     148        assertEquals(1459695600000L, DateUtils.tsFromString("2016-04-03T15:00:00.000-00:00"));
     149
     150        // Local time
     151        assertEquals(1459688400000L, DateUtils.tsFromString("03-APR-16 15:00:00"));
     152    }
     153
     154    /**
     155     * Unit test of {@link DateUtils#getDateFormat} method.
     156     */
     157    @Test
     158    public void testGetDateFormat() {
     159        Boolean iso = DateUtils.PROP_ISO_DATES.get();
     160        try {
     161            DateFormat f1 = DateUtils.getDateFormat(DateFormat.SHORT);
     162            assertNotNull(f1);
     163            DateUtils.PROP_ISO_DATES.put(!iso);
     164            DateFormat f2 = DateUtils.getDateFormat(DateFormat.SHORT);
     165            assertNotNull(f1);
     166            assertNotEquals(f1, f2);
     167        } finally {
     168            DateUtils.PROP_ISO_DATES.put(iso);
     169        }
     170    }
     171
     172    /**
     173     * Unit test of {@link DateUtils#getTimeFormat} method.
     174     */
     175    @Test
     176    public void testTimeFormat() {
     177        Boolean iso = DateUtils.PROP_ISO_DATES.get();
     178        try {
     179            DateFormat f1 = DateUtils.getTimeFormat(DateFormat.SHORT);
     180            assertNotNull(f1);
     181            DateUtils.PROP_ISO_DATES.put(!iso);
     182            DateFormat f2 = DateUtils.getTimeFormat(DateFormat.SHORT);
     183            assertNotNull(f1);
     184            assertNotEquals(f1, f2);
     185        } finally {
     186            DateUtils.PROP_ISO_DATES.put(iso);
     187        }
     188    }
    118189}
Note: See TracChangeset for help on using the changeset viewer.