ActionRegistry { @NonNull public Entry registerAction(@NonNull Action action, @NonNull String... names) { if (names.length == 0) { throw new IllegalArgumentException("Unable to register an action without a name."); } return registerEntry(new Entry(action, new ArrayList<>(Arrays.asList(names)))); }  @NonNull Entry registerAction(@NonNull Action action, @NonNull String... names); @NonNull Entry registerAction(@NonNull Class<? extends Action> clazz, @NonNull String... names); @Nullable Entry getEntry(@NonNull String name); @NonNull Set<Entry> getEntries(); void unregisterAction(@NonNull String name); void registerDefaultActions(@NonNull Context context); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void registerActions(@NonNull Context context, @XmlRes int actionsXml);  }
@Test public void testRegisterAction() { ActionRegistry.Entry entry = registry.registerAction(new TestAction(), "who", "are", "we?"); validateEntry(entry, "who", "are", "we?"); }
@Test(expected = IllegalArgumentException.class) public void testRegisterEmptyActionNames() { registry.registerAction(new TestAction(), ""); }
@Test(expected = IllegalArgumentException.class) public void testRegisterMultipleEmptyActionNames() { registry.registerAction(new TestAction(), "what", ""); }
@Test public void testEntryActionForSituation() { Action defaultAction = new TestAction(); Action openAction = new TestAction(); Action receiveAction = new TestAction(); registry.registerAction(defaultAction, "action"); ActionRegistry.Entry entry = registry.registerAction(defaultAction, "action"); entry.setSituationOverride(Action.SITUATION_PUSH_OPENED, openAction); entry.setSituationOverride(Action.SITUATION_PUSH_RECEIVED, receiveAction); assertEquals("Should return situation override action", entry.getActionForSituation(Action.SITUATION_PUSH_OPENED), openAction); assertEquals("Should return situation override action", entry.getActionForSituation(Action.SITUATION_PUSH_RECEIVED), receiveAction); assertEquals("Should return default action when no situation overrides exist", entry.getActionForSituation(Action.SITUATION_MANUAL_INVOCATION), defaultAction); }