From 92fcacdd85381796d49f87801f0e16cb4be0204a Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 7 Jun 2018 22:36:16 +0800 Subject: [PATCH] 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 --- .../src/android/widget/DateTimeViewTest.java | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/core/tests/coretests/src/android/widget/DateTimeViewTest.java b/core/tests/coretests/src/android/widget/DateTimeViewTest.java index fbf0d36bac09..40a6b7a43f53 100644 --- a/core/tests/coretests/src/android/widget/DateTimeViewTest.java +++ b/core/tests/coretests/src/android/widget/DateTimeViewTest.java @@ -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(); + } } } -- 2.11.0