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

Commit 92fcacdd authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Fix DateTimeViewTest illegal access error

Even package path is the same, different classpath (bootclass vs test)
will be considered as different package that does not allow package access.
Also correct to verify twice detach.

Bug: 78506836
Test: atest FrameworksCoreTests:DateTimeViewTest
Change-Id: If60fe89049f5e4b8366c6e1e4d4e2d7e38a57b7c
parent a4e6ce36
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -31,11 +31,25 @@ public class DateTimeViewTest {
    @UiThreadTest
    @Test
    public void additionalOnDetachedFromWindow_noException() {
        final DateTimeView dateTimeView = new DateTimeView(InstrumentationRegistry.getContext());
        dateTimeView.onAttachedToWindow();
        dateTimeView.onAttachedToWindow();
        final TestDateTimeView dateTimeView = new TestDateTimeView();
        dateTimeView.attachedToWindow();
        dateTimeView.detachedFromWindow();
        // Even there is an additional detach (abnormal), DateTimeView should not unregister
        // receiver again that raises "java.lang.IllegalArgumentException: Receiver not registered".
        dateTimeView.onDetachedFromWindow();
        dateTimeView.detachedFromWindow();
    }

    private static class TestDateTimeView extends DateTimeView {
        TestDateTimeView() {
            super(InstrumentationRegistry.getContext());
        }

        void attachedToWindow() {
            super.onAttachedToWindow();
        }

        void detachedFromWindow() {
            super.onDetachedFromWindow();
        }
    }
}