Search in sources :

Example 1 with SystemDefaults

use of org.apache.commons.lang3.test.SystemDefaults in project commons-lang by apache.

the class StringUtilsContainsTest method testContainsIgnoreCase_LocaleIndependence.

@SystemDefaults(locale = "de_DE")
@Test
public void testContainsIgnoreCase_LocaleIndependence() {
    final Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
    final String[][] tdata = { { "i", "I" }, { "I", "i" }, { "\u03C2", "\u03C3" }, { "\u03A3", "\u03C2" }, { "\u03A3", "\u03C3" } };
    final String[][] fdata = { { "\u00DF", "SS" } };
    for (final Locale testLocale : locales) {
        Locale.setDefault(testLocale);
        for (int j = 0; j < tdata.length; j++) {
            assertTrue(Locale.getDefault() + ": " + j + " " + tdata[j][0] + " " + tdata[j][1], StringUtils.containsIgnoreCase(tdata[j][0], tdata[j][1]));
        }
        for (int j = 0; j < fdata.length; j++) {
            assertFalse(Locale.getDefault() + ": " + j + " " + fdata[j][0] + " " + fdata[j][1], StringUtils.containsIgnoreCase(fdata[j][0], fdata[j][1]));
        }
    }
}
Also used : Locale(java.util.Locale) SystemDefaults(org.apache.commons.lang3.test.SystemDefaults) Test(org.junit.Test)

Example 2 with SystemDefaults

use of org.apache.commons.lang3.test.SystemDefaults in project commons-lang by apache.

the class DateFormatUtilsTest method testLang530.

@SystemDefaults(timezone = "UTC")
@Test
public void testLang530() throws ParseException {
    final Date d = new Date();
    final String isoDateStr = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(d);
    final Date d2 = DateUtils.parseDate(isoDateStr, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
    // the format loses milliseconds so have to reintroduce them
    assertEquals("Date not equal to itself ISO formatted and parsed", d.getTime(), d2.getTime() + d.getTime() % 1000);
}
Also used : Date(java.util.Date) SystemDefaults(org.apache.commons.lang3.test.SystemDefaults) Test(org.junit.Test)

Example 3 with SystemDefaults

use of org.apache.commons.lang3.test.SystemDefaults in project commons-lang by apache.

the class FastDatePrinterTest method testFormat.

@SystemDefaults(timezone = "America/New_York", locale = "en_US")
@Test
public void testFormat() {
    final GregorianCalendar cal1 = new GregorianCalendar(2003, 0, 10, 15, 33, 20);
    final GregorianCalendar cal2 = new GregorianCalendar(2003, 6, 10, 9, 0, 0);
    final Date date1 = cal1.getTime();
    final Date date2 = cal2.getTime();
    final long millis1 = date1.getTime();
    final long millis2 = date2.getTime();
    DatePrinter fdf = getInstance("yyyy-MM-dd'T'HH:mm:ss");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    assertEquals(sdf.format(date1), fdf.format(date1));
    assertEquals("2003-01-10T15:33:20", fdf.format(date1));
    assertEquals("2003-01-10T15:33:20", fdf.format(cal1));
    assertEquals("2003-01-10T15:33:20", fdf.format(millis1));
    assertEquals("2003-07-10T09:00:00", fdf.format(date2));
    assertEquals("2003-07-10T09:00:00", fdf.format(cal2));
    assertEquals("2003-07-10T09:00:00", fdf.format(millis2));
    fdf = getInstance("Z");
    assertEquals("-0500", fdf.format(date1));
    assertEquals("-0500", fdf.format(cal1));
    assertEquals("-0500", fdf.format(millis1));
    assertEquals("-0400", fdf.format(date2));
    assertEquals("-0400", fdf.format(cal2));
    assertEquals("-0400", fdf.format(millis2));
    fdf = getInstance("ZZ");
    assertEquals("-05:00", fdf.format(date1));
    assertEquals("-05:00", fdf.format(cal1));
    assertEquals("-05:00", fdf.format(millis1));
    assertEquals("-04:00", fdf.format(date2));
    assertEquals("-04:00", fdf.format(cal2));
    assertEquals("-04:00", fdf.format(millis2));
    final String pattern = "GGGG GGG GG G yyyy yyy yy y MMMM MMM MM M" + " dddd ddd dd d DDDD DDD DD D EEEE EEE EE E aaaa aaa aa a zzzz zzz zz z";
    fdf = getInstance(pattern);
    sdf = new SimpleDateFormat(pattern);
    // SDF bug fix starting with Java 7
    assertEquals(sdf.format(date1).replaceAll("2003 03 03 03", "2003 2003 03 2003"), fdf.format(date1));
    assertEquals(sdf.format(date2).replaceAll("2003 03 03 03", "2003 2003 03 2003"), fdf.format(date2));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SystemDefaults(org.apache.commons.lang3.test.SystemDefaults) Test(org.junit.Test)

Example 4 with SystemDefaults

use of org.apache.commons.lang3.test.SystemDefaults in project commons-lang by apache.

the class FastDatePrinterTest method testTimeZoneAsZ.

@SystemDefaults(timezone = "UTC")
@Test
public void testTimeZoneAsZ() throws Exception {
    final Calendar c = Calendar.getInstance(FastTimeZone.getGmtTimeZone());
    final FastDateFormat noColonFormat = FastDateFormat.getInstance("Z");
    assertEquals("+0000", noColonFormat.format(c));
    final FastDateFormat isoFormat = FastDateFormat.getInstance("ZZ");
    assertEquals("Z", isoFormat.format(c));
    final FastDateFormat colonFormat = FastDateFormat.getInstance("ZZZ");
    assertEquals("+00:00", colonFormat.format(c));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) SystemDefaults(org.apache.commons.lang3.test.SystemDefaults) Test(org.junit.Test)

Example 5 with SystemDefaults

use of org.apache.commons.lang3.test.SystemDefaults in project commons-lang by apache.

the class DateFormatUtilsTest method testSMTP.

@SystemDefaults(locale = "en")
@Test
public void testSMTP() {
    TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
    Calendar june = createJuneTestDate(timeZone);
    assertFormats("Sun, 08 Jun 2003 10:11:12 -0300", DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern(), timeZone, june);
    timeZone = FastTimeZone.getGmtTimeZone();
    june = createJuneTestDate(timeZone);
    assertFormats("Sun, 08 Jun 2003 10:11:12 +0000", DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern(), timeZone, june);
}
Also used : TimeZone(java.util.TimeZone) Calendar(java.util.Calendar) SystemDefaults(org.apache.commons.lang3.test.SystemDefaults) Test(org.junit.Test)

Aggregations

SystemDefaults (org.apache.commons.lang3.test.SystemDefaults)5 Test (org.junit.Test)5 Calendar (java.util.Calendar)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Locale (java.util.Locale)1 TimeZone (java.util.TimeZone)1