Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b85e357e authored by Kihong Seong's avatar Kihong Seong
Browse files

Fix ObexTimeTest

Some asserts in tests are expecting a wrong timestamp. For example,
timestamp with made with offset, but expecting a timestamp without
offset. Fixed these inconsistencies to make all tests pass.

Bug: 282809266
Test: atest BluetoothInstrumentationTests
Change-Id: I1876ca9db8c1f100e474d21c1aa9a394b7e1736e
parent f8577a6e
Loading
Loading
Loading
Loading
+16 −5
Original line number Original line Diff line number Diff line
@@ -53,11 +53,15 @@ public class ObexTimeTest {
    private static final long VALID_TS_OFFSET_POS = VALID_TS - TS_OFFSET;
    private static final long VALID_TS_OFFSET_POS = VALID_TS - TS_OFFSET;
    private static final long VALID_TS_OFFSET_NEG = VALID_TS + TS_OFFSET;
    private static final long VALID_TS_OFFSET_NEG = VALID_TS + TS_OFFSET;


    @SuppressWarnings("JavaUtilDate")
    private static final Date VALID_DATE = new Date(VALID_TS);

    private static final Date VALID_DATE_LOCAL_TZ = new Date(VALID_TS_LOCAL_TZ);
    private static final Date VALID_DATE_LOCAL_TZ = new Date(VALID_TS_LOCAL_TZ);
    private static final Date VALID_DATE_WITH_OFFSET_POS = new Date(VALID_TS_OFFSET_POS);
    private static final Date VALID_DATE_WITH_OFFSET_POS = new Date(VALID_TS_OFFSET_POS);
    private static final Date VALID_DATE_WITH_OFFSET_NEG = new Date(VALID_TS_OFFSET_NEG);
    private static final Date VALID_DATE_WITH_OFFSET_NEG = new Date(VALID_TS_OFFSET_NEG);


    private static final Instant VALID_INSTANT = Instant.ofEpochMilli(VALID_TS);
    private static final Instant VALID_INSTANT = Instant.ofEpochMilli(VALID_TS);
    private static final Instant VALID_INSTANT_LOCAL_TZ = Instant.ofEpochMilli(VALID_TS_LOCAL_TZ);
    private static final Instant VALID_INSTANT_WITH_OFFSET_POS =
    private static final Instant VALID_INSTANT_WITH_OFFSET_POS =
            Instant.ofEpochMilli(VALID_TS_OFFSET_POS);
            Instant.ofEpochMilli(VALID_TS_OFFSET_POS);
    private static final Instant VALID_INSTANT_WITH_OFFSET_NEG =
    private static final Instant VALID_INSTANT_WITH_OFFSET_NEG =
@@ -66,7 +70,9 @@ public class ObexTimeTest {
    @Test
    @Test
    public void createWithValidDateTimeString_TimestampCorrect() {
    public void createWithValidDateTimeString_TimestampCorrect() {
        ObexTime timestamp = new ObexTime(VALID_TIME_STRING);
        ObexTime timestamp = new ObexTime(VALID_TIME_STRING);
        Assert.assertEquals("Parsed instant must match expected", VALID_INSTANT,
        Assert.assertEquals(
                "Parsed instant must match expected",
                VALID_INSTANT_LOCAL_TZ,
                timestamp.getInstant());
                timestamp.getInstant());
        Assert.assertEquals("Parsed date must match expected",
        Assert.assertEquals("Parsed date must match expected",
                VALID_DATE_LOCAL_TZ, timestamp.getTime());
                VALID_DATE_LOCAL_TZ, timestamp.getTime());
@@ -93,19 +99,24 @@ public class ObexTimeTest {
    @Test
    @Test
    public void createWithValidDate_TimestampCorrect() {
    public void createWithValidDate_TimestampCorrect() {
        ObexTime timestamp = new ObexTime(VALID_DATE_LOCAL_TZ);
        ObexTime timestamp = new ObexTime(VALID_DATE_LOCAL_TZ);
        Assert.assertEquals("ObexTime created with a date must return the expected instant",
        Assert.assertEquals(
                VALID_INSTANT, timestamp.getInstant());
                "ObexTime created with a date must return the expected instant",
                VALID_INSTANT_LOCAL_TZ,
                timestamp.getInstant());
        Assert.assertEquals("ObexTime created with a date must return the same date",
        Assert.assertEquals("ObexTime created with a date must return the same date",
                VALID_DATE_LOCAL_TZ, timestamp.getTime());
                VALID_DATE_LOCAL_TZ, timestamp.getTime());
    }
    }


    @SuppressWarnings("JavaUtilDate")
    @Test
    @Test
    public void createWithValidInstant_TimestampCorrect() {
    public void createWithValidInstant_TimestampCorrect() {
        ObexTime timestamp = new ObexTime(VALID_INSTANT);
        ObexTime timestamp = new ObexTime(VALID_INSTANT);
        Assert.assertEquals("ObexTime created with a instant must return the same instant",
        Assert.assertEquals("ObexTime created with a instant must return the same instant",
                VALID_INSTANT, timestamp.getInstant());
                VALID_INSTANT, timestamp.getInstant());
        Assert.assertEquals("ObexTime created with a instant must return the expected date",
        Assert.assertEquals(
                VALID_DATE_LOCAL_TZ, timestamp.getTime());
                "ObexTime created with a instant must return the expected date",
                VALID_DATE,
                timestamp.getTime());
    }
    }


    @Test
    @Test