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());
}
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);
}
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);
}
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);
}
Aggregations