Skip to content

Commit

Permalink
Merge pull request #6575 from utzcoz/use-UTC-time-zone-explicitly-for…
Browse files Browse the repository at this point in the history
…-isEpoch-test

Use UTC time zone explicitly for isEpoch test
  • Loading branch information
hoisie committed Jun 28, 2021
2 parents d87cb1e + 85885c0 commit bef2afb
Showing 1 changed file with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package android.text.format;

import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
import static android.os.Build.VERSION_CODES.KITKAT_WATCH;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.os.SystemClock;
import android.util.TimeFormatException;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SdkSuppress;
Expand All @@ -17,7 +15,6 @@
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.internal.DoNotInstrument;

@DoNotInstrument
Expand Down Expand Up @@ -76,13 +73,13 @@ public void tearDown() {
}

@Test
public void shouldHaveNoArgsConstructor() throws Exception {
public void shouldHaveNoArgsConstructor() {
Time t = new Time();
assertNotNull(t.timezone);
}

@Test
public void shouldHaveCopyConstructor() throws Exception {
public void shouldHaveCopyConstructor() {
Time t = new Time();
t.setToNow();
Time t2 = new Time(t);
Expand All @@ -96,7 +93,7 @@ public void shouldHaveCopyConstructor() throws Exception {
}

@Test
public void shouldHaveSetTime() throws Exception {
public void shouldHaveSetTime() {
Time t = new Time();
t.setToNow();
Time t2 = new Time();
Expand All @@ -111,7 +108,7 @@ public void shouldHaveSetTime() throws Exception {
}

@Test
public void shouldHaveSet3Args() throws Exception {
public void shouldHaveSet3Args() {
Time t = new Time();
t.set(1, 1, 2000);
assertEquals(t.year, 2000);
Expand All @@ -120,7 +117,7 @@ public void shouldHaveSet3Args() throws Exception {
}

@Test
public void shouldHaveSet6Args() throws Exception {
public void shouldHaveSet6Args() {
Time t = new Time();
t.set(1, 1, 1, 1, 1, 2000);
assertEquals(t.year, 2000);
Expand All @@ -132,13 +129,13 @@ public void shouldHaveSet6Args() throws Exception {
}

@Test
public void shouldHaveTimeZoneConstructor() throws Exception {
public void shouldHaveTimeZoneConstructor() {
Time t = new Time("UTC");
assertEquals(t.timezone, "UTC");
}

@Test
public void shouldClear() throws Exception {
public void shouldClear() {
Time t = new Time();
t.setToNow();
t.clear("UTC");
Expand All @@ -156,19 +153,19 @@ public void shouldClear() throws Exception {
}

@Test
public void shouldHaveToMillis() throws Exception {
public void shouldHaveToMillis() {
Time t = new Time();
t.set(86400 * 1000);
assertEquals(86400 * 1000, t.toMillis(false));
}

@Test
public void shouldHaveCurrentTimeZone() throws Exception {
public void shouldHaveCurrentTimeZone() {
assertNotNull(Time.getCurrentTimezone());
}

@Test
public void shouldSwitchTimeZones() throws Exception {
public void shouldSwitchTimeZones() {
Time t = new Time("UTC");

t.set(1414213562373L);
Expand All @@ -184,7 +181,7 @@ public void shouldSwitchTimeZones() throws Exception {
}

@Test
public void shouldHaveCompareAndBeforeAfter() throws Exception {
public void shouldHaveCompareAndBeforeAfter() {
Time a = new Time();
Time b = new Time();

Expand All @@ -204,7 +201,7 @@ public void shouldHaveCompareAndBeforeAfter() throws Exception {
}

@Test
public void shouldHaveParse() throws Exception {
public void shouldHaveParse() {
Time t = new Time("Europe/Berlin");
assertFalse(t.parse("20081013T160000"));
assertEquals(2008, t.year);
Expand All @@ -223,17 +220,14 @@ public void shouldHaveParse() throws Exception {
assertEquals(0, t.second);
}




@Test(expected = TimeFormatException.class)
public void shouldThrowTimeFormatException() throws Exception {
public void shouldThrowTimeFormatException() {
Time t = new Time();
t.parse("BLARGH");
}

@Test
public void shouldHaveParseShort() throws Exception {
public void shouldHaveParseShort() {
Time t = new Time();
t.parse("20081013");
assertEquals(2008, t.year);
Expand All @@ -246,7 +240,7 @@ public void shouldHaveParseShort() throws Exception {

@Test
@SdkSuppress(minSdkVersion = JELLY_BEAN_MR1)
public void shouldFormat() throws Exception {
public void shouldFormat() {
Time t = new Time(Time.TIMEZONE_UTC);
t.set(3600000L);

Expand All @@ -256,7 +250,7 @@ public void shouldFormat() throws Exception {

@Test
@SdkSuppress(minSdkVersion = JELLY_BEAN_MR1)
public void shouldFormatAndroidStrings() throws Exception {
public void shouldFormatAndroidStrings() {
Time t = new Time("UTC");
// NOTE: month is zero-based.
t.set(12, 13, 14, 8, 8, 1987);
Expand All @@ -282,7 +276,7 @@ public void shouldFormatAndroidStrings() throws Exception {
}

@Test
public void shouldFormat2445() throws Exception {
public void shouldFormat2445() {
Time t = new Time();
t.timezone = "PST";
assertEquals("19700101T000000", t.format2445());
Expand All @@ -293,21 +287,20 @@ public void shouldFormat2445() throws Exception {
}

@Test
public void shouldFormat3339() throws Exception {
public void shouldFormat3339() {
Time t = new Time("Europe/Berlin");
assertEquals("1970-01-01T00:00:00.000+00:00", t.format3339(false));
assertEquals("1970-01-01", t.format3339(true));
}

@Test
public void testIsEpoch() throws Exception {
Time t = new Time();
boolean isEpoch = Time.isEpoch(t);
assertEquals(true, isEpoch);
public void testIsEpoch() {
Time t = new Time(Time.TIMEZONE_UTC);
assertThat(Time.isEpoch(t)).isTrue();
}

@Test
public void testGetJulianDay() throws Exception {
public void testGetJulianDay() {
Time time = new Time();

time.set(0, 0, 0, 12, 5, 2008);
Expand All @@ -331,7 +324,7 @@ public void testGetJulianDay() throws Exception {
}

@Test
public void testSetJulianDay() throws Exception {
public void testSetJulianDay() {
Time time = new Time();
time.set(0, 0, 0, 12, 5, 2008);
time.timezone = "Australia/Sydney";
Expand Down

0 comments on commit bef2afb

Please sign in to comment.