@Implementation protected void setTimeZone(String timeZone) { // Do the real check first Shadow.directlyOn(realObject, AlarmManager.class).setTimeZone(timeZone); // Then do the right side effect TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); }
@Test public void setTimeZone_OlsonTimeZone_acceptAlways() { alarmManager.setTimeZone("America/Sao_Paulo"); assertThat(TimeZone.getDefault().getID()).isEqualTo("America/Sao_Paulo"); }
@Test @Config(maxSdk = VERSION_CODES.LOLLIPOP_MR1) public void setTimeZone_abbreviateTimezoneId_accept() { alarmManager.setTimeZone("PST"); assertThat(TimeZone.getDefault().getID()).isEqualTo("PST"); }
@Test @Config(maxSdk = VERSION_CODES.LOLLIPOP_MR1) public void setTimeZone_invalidTimeZone_fallbackToGMT() { alarmManager.setTimeZone("-07:00"); assertThat(TimeZone.getDefault().getID()).isEqualTo("GMT"); }
@Test public void setTimeZone_UTC_acceptAlways() { alarmManager.setTimeZone("UTC"); assertThat(TimeZone.getDefault().getID()).isEqualTo("UTC"); }
@Test @Config(minSdk = VERSION_CODES.M) public void setTimeZone_abbreviateTimeZone_ignore() { try { alarmManager.setTimeZone("PST"); fail("IllegalArgumentException not thrown"); } catch (IllegalArgumentException e) { // expected } assertThat(TimeZone.getDefault().getID()).isEqualTo("America/Los_Angeles"); }
@Test @Config(minSdk = VERSION_CODES.M) public void setTimeZone_invalidTimeZone_ignore() { try { alarmManager.setTimeZone("-07:00"); fail("IllegalArgumentException not thrown"); } catch (IllegalArgumentException e) { // expected } assertThat(TimeZone.getDefault().getID()).isEqualTo("America/Los_Angeles"); }
@Implementation protected void setTimeZone(String timeZone) { // Do the real check first Shadow.directlyOn(realObject, AlarmManager.class).setTimeZone(timeZone); // Then do the right side effect TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); }