Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationVisitUrisTest.java +17 −3 Original line number Original line Diff line number Diff line Loading @@ -115,11 +115,19 @@ public class NotificationVisitUrisTest extends UiServiceTestCase { PREFERRED_CONSTRUCTORS = ImmutableMap.of( PREFERRED_CONSTRUCTORS = ImmutableMap.of( Notification.Builder.class, Notification.Builder.class, Notification.Builder.class.getConstructor(Context.class, String.class)); Notification.Builder.class.getConstructor(Context.class, String.class)); EXCLUDED_SETTERS_OVERLOADS = ImmutableMultimap.<Class<?>, Method>builder() .put(RemoteViews.class, // b/245950570: Tries to connect to service and will crash. RemoteViews.class.getMethod("setRemoteAdapter", int.class, Intent.class)) .build(); } catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) { throw new RuntimeException(e); throw new RuntimeException(e); } } } } // Setters that shouldn't be called, for various reasons (but NOT because they are KNOWN_BAD). private static final Multimap<Class<?>, String> EXCLUDED_SETTERS = private static final Multimap<Class<?>, String> EXCLUDED_SETTERS = ImmutableMultimap.<Class<?>, String>builder() ImmutableMultimap.<Class<?>, String>builder() // Handled by testAllStyles(). // Handled by testAllStyles(). Loading @@ -134,6 +142,9 @@ public class NotificationVisitUrisTest extends UiServiceTestCase { .put(RemoteViews.class, "mergeRemoteViews") .put(RemoteViews.class, "mergeRemoteViews") .build(); .build(); // Same as above, but specific overloads that should not be called. private static final Multimap<Class<?>, Method> EXCLUDED_SETTERS_OVERLOADS; private Context mContext; private Context mContext; @Rule @Rule Loading @@ -146,10 +157,12 @@ public class NotificationVisitUrisTest extends UiServiceTestCase { @Test // This is a meta-test, checks that the generators are not broken. @Test // This is a meta-test, checks that the generators are not broken. public void verifyTest() { public void verifyTest() { Generated<Notification> notification = buildNotification(mContext, /* styleClass= */ null, Generated<Notification> notification = buildNotification(mContext, /* extenderClass= */ null, /* actionExtenderClass= */ null, /* styleClass= */ Notification.MessagingStyle.class, /* extenderClass= */ Notification.WearableExtender.class, /* actionExtenderClass= */ Notification.Action.WearableExtender.class, /* includeRemoteViews= */ true); /* includeRemoteViews= */ true); assertThat(notification.includedUris.size()).isAtLeast(20); assertThat(notification.includedUris.size()).isAtLeast(730); } } @Test @Test Loading Loading @@ -479,6 +492,7 @@ public class NotificationVisitUrisTest extends UiServiceTestCase { || method.getReturnType().equals(clazz)) || method.getReturnType().equals(clazz)) && method.getParameterCount() >= 1 && method.getParameterCount() >= 1 && !EXCLUDED_SETTERS.containsEntry(clazz, method.getName()) && !EXCLUDED_SETTERS.containsEntry(clazz, method.getName()) && !EXCLUDED_SETTERS_OVERLOADS.containsEntry(clazz, method) && Arrays.stream(method.getParameterTypes()) && Arrays.stream(method.getParameterTypes()) .noneMatch(excludingParameterTypes::contains)) { .noneMatch(excludingParameterTypes::contains)) { methods.put(method.getName(), method); methods.put(method.getName(), method); Loading Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationVisitUrisTest.java +17 −3 Original line number Original line Diff line number Diff line Loading @@ -115,11 +115,19 @@ public class NotificationVisitUrisTest extends UiServiceTestCase { PREFERRED_CONSTRUCTORS = ImmutableMap.of( PREFERRED_CONSTRUCTORS = ImmutableMap.of( Notification.Builder.class, Notification.Builder.class, Notification.Builder.class.getConstructor(Context.class, String.class)); Notification.Builder.class.getConstructor(Context.class, String.class)); EXCLUDED_SETTERS_OVERLOADS = ImmutableMultimap.<Class<?>, Method>builder() .put(RemoteViews.class, // b/245950570: Tries to connect to service and will crash. RemoteViews.class.getMethod("setRemoteAdapter", int.class, Intent.class)) .build(); } catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) { throw new RuntimeException(e); throw new RuntimeException(e); } } } } // Setters that shouldn't be called, for various reasons (but NOT because they are KNOWN_BAD). private static final Multimap<Class<?>, String> EXCLUDED_SETTERS = private static final Multimap<Class<?>, String> EXCLUDED_SETTERS = ImmutableMultimap.<Class<?>, String>builder() ImmutableMultimap.<Class<?>, String>builder() // Handled by testAllStyles(). // Handled by testAllStyles(). Loading @@ -134,6 +142,9 @@ public class NotificationVisitUrisTest extends UiServiceTestCase { .put(RemoteViews.class, "mergeRemoteViews") .put(RemoteViews.class, "mergeRemoteViews") .build(); .build(); // Same as above, but specific overloads that should not be called. private static final Multimap<Class<?>, Method> EXCLUDED_SETTERS_OVERLOADS; private Context mContext; private Context mContext; @Rule @Rule Loading @@ -146,10 +157,12 @@ public class NotificationVisitUrisTest extends UiServiceTestCase { @Test // This is a meta-test, checks that the generators are not broken. @Test // This is a meta-test, checks that the generators are not broken. public void verifyTest() { public void verifyTest() { Generated<Notification> notification = buildNotification(mContext, /* styleClass= */ null, Generated<Notification> notification = buildNotification(mContext, /* extenderClass= */ null, /* actionExtenderClass= */ null, /* styleClass= */ Notification.MessagingStyle.class, /* extenderClass= */ Notification.WearableExtender.class, /* actionExtenderClass= */ Notification.Action.WearableExtender.class, /* includeRemoteViews= */ true); /* includeRemoteViews= */ true); assertThat(notification.includedUris.size()).isAtLeast(20); assertThat(notification.includedUris.size()).isAtLeast(730); } } @Test @Test Loading Loading @@ -479,6 +492,7 @@ public class NotificationVisitUrisTest extends UiServiceTestCase { || method.getReturnType().equals(clazz)) || method.getReturnType().equals(clazz)) && method.getParameterCount() >= 1 && method.getParameterCount() >= 1 && !EXCLUDED_SETTERS.containsEntry(clazz, method.getName()) && !EXCLUDED_SETTERS.containsEntry(clazz, method.getName()) && !EXCLUDED_SETTERS_OVERLOADS.containsEntry(clazz, method) && Arrays.stream(method.getParameterTypes()) && Arrays.stream(method.getParameterTypes()) .noneMatch(excludingParameterTypes::contains)) { .noneMatch(excludingParameterTypes::contains)) { methods.put(method.getName(), method); methods.put(method.getName(), method); Loading