AssociateIdentifiersEvent extends Event { @Override public boolean isValid() { boolean isValid = true; if (ids.size() > AssociatedIdentifiers.MAX_IDS) { Logger.error("Associated identifiers exceeds %s", AssociatedIdentifiers.MAX_IDS); isValid = false; } for (Map.Entry<String, String> entry : ids.entrySet()) { if (entry.getKey().length() > AssociatedIdentifiers.MAX_CHARACTER_COUNT) { Logger.error("Associated identifiers key %s exceeds %s characters.", entry.getKey(), AssociatedIdentifiers.MAX_CHARACTER_COUNT); isValid = false; } if (entry.getValue().length() > AssociatedIdentifiers.MAX_CHARACTER_COUNT) { Logger.error("Associated identifiers for key %s exceeds %s characters.", entry.getKey(), AssociatedIdentifiers.MAX_CHARACTER_COUNT); isValid = false; } } return isValid; } AssociateIdentifiersEvent(@NonNull AssociatedIdentifiers ids); @NonNull @Override String getType(); @Override boolean isValid(); @NonNull @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) JsonMap getEventData();  }
@Test public void testInvalidEvent() { Map<String, String> ids = new HashMap<>(); for (int i = 0; i < 101; i++) { ids.put(UUID.randomUUID().toString(), "value"); } assertFalse(new AssociateIdentifiersEvent(new AssociatedIdentifiers(ids)).isValid()); }
@Test public void testValidEvent() { assertTrue(new AssociateIdentifiersEvent(new AssociatedIdentifiers()).isValid()); Map<String, String> ids = new HashMap<>(); for (int i = 0; i < 100; i++) { ids.put(UUID.randomUUID().toString(), "value"); } assertTrue(new AssociateIdentifiersEvent(new AssociatedIdentifiers(ids)).isValid()); }