Search in sources :

Example 1 with TimeZone

use of com.google.gwt.i18n.client.TimeZone in project kie-wb-common by kiegroup.

the class TimeZoneUtilsTest method testGetTimeZone.

@Test
@PrepareForTest({ DateTimeFormat.class })
public void testGetTimeZone() {
    final String expectedId = "Etc/GMT-3";
    final int expectedOffsetInMinutes = -180;
    final TimeZone timeZone = TimeZoneUtils.getTimeZone();
    assertEquals(expectedId, timeZone.getID());
    assertEquals(expectedOffsetInMinutes, timeZone.getStandardOffset());
}
Also used : TimeZone(com.google.gwt.i18n.client.TimeZone) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with TimeZone

use of com.google.gwt.i18n.client.TimeZone in project kie-wb-common by kiegroup.

the class TimeZoneUtilsTest method testFormatWithServerTimeZone.

@Test
@PrepareForTest({ TimeZoneUtils.class, DateTimeFormat.class })
public void testFormatWithServerTimeZone() {
    final Date date = mock(Date.class);
    final TimeZone timeZone = mock(TimeZone.class);
    final String expectedFormat = "01-01-1900";
    mockStatic(TimeZoneUtils.class);
    when(TimeZoneUtils.getTimeZone()).thenReturn(timeZone);
    when(TimeZoneUtils.formatWithServerTimeZone(Mockito.<Date>any())).thenCallRealMethod();
    when(dateTimeFormat.format(eq(date), eq(timeZone))).thenReturn(expectedFormat);
    final String actualFormat = TimeZoneUtils.formatWithServerTimeZone(date);
    assertEquals(expectedFormat, actualFormat);
}
Also used : TimeZone(com.google.gwt.i18n.client.TimeZone) Date(java.util.Date) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with TimeZone

use of com.google.gwt.i18n.client.TimeZone in project kie-wb-common by kiegroup.

the class TimeZoneUtilsTest method testGetClientOffset.

@Test
@PrepareForTest({ TimeZoneUtils.class, DateTimeFormat.class })
public void testGetClientOffset() {
    final Date date = mock(Date.class);
    final TimeZone timeZone = mock(TimeZone.class);
    final int serverSideOffSet = -180;
    final int dateOffSet = -120;
    final int expectedOffset = -60;
    mockStatic(TimeZoneUtils.class);
    when(TimeZoneUtils.getTimeZone()).thenReturn(timeZone);
    when(TimeZoneUtils.getClientOffset(Mockito.<Date>any())).thenCallRealMethod();
    when(timeZone.getStandardOffset()).thenReturn(serverSideOffSet);
    when(date.getTimezoneOffset()).thenReturn(dateOffSet);
    final int actualOffset = TimeZoneUtils.getClientOffset(date);
    assertEquals(expectedOffset, actualOffset);
}
Also used : TimeZone(com.google.gwt.i18n.client.TimeZone) Date(java.util.Date) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with TimeZone

use of com.google.gwt.i18n.client.TimeZone in project kie-wb-common by kiegroup.

the class TimeZoneUtilsTest method testConvertToServerTimeZone.

@Test
@PrepareForTest({ TimeZoneUtils.class, DateTimeFormat.class })
public void testConvertToServerTimeZone() {
    final Date date = mock(Date.class);
    final Date expectedDate = mock(Date.class);
    final TimeZone timeZone = mock(TimeZone.class);
    final ArgumentCaptor<TimeZone> captorTimeZone = ArgumentCaptor.forClass(TimeZone.class);
    final String convertedDate = "01-01-1900";
    final DateTimeFormat internalFormat = mock(DateTimeFormat.class);
    final int expectedClientOffset = -60;
    mockStatic(TimeZoneUtils.class);
    when(TimeZoneUtils.getTimeZone()).thenReturn(timeZone);
    when(TimeZoneUtils.internalFormatter()).thenReturn(internalFormat);
    when(TimeZoneUtils.getClientOffset(date)).thenReturn(expectedClientOffset);
    when(TimeZoneUtils.convertToServerTimeZone(Mockito.<Date>any())).thenCallRealMethod();
    when(internalFormat.format(eq(date), captorTimeZone.capture())).thenReturn(convertedDate);
    when(internalFormat.parse(convertedDate)).thenReturn(expectedDate);
    final Date actualDate = TimeZoneUtils.convertToServerTimeZone(date);
    assertEquals(expectedClientOffset, captorTimeZone.getValue().getStandardOffset());
    assertEquals(expectedDate, actualDate);
}
Also used : TimeZone(com.google.gwt.i18n.client.TimeZone) Date(java.util.Date) DateTimeFormat(com.google.gwt.i18n.client.DateTimeFormat) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

TimeZone (com.google.gwt.i18n.client.TimeZone)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Date (java.util.Date)3 DateTimeFormat (com.google.gwt.i18n.client.DateTimeFormat)1