AbstractCredentials implements Credentials { public void setAttribute(@NotNull String name, @Nullable Object value) { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } if (value == null) { removeAttribute(name); return; } synchronized (attributes) { attributes.put(name, value); } } AbstractCredentials(@NotNull String userId); @NotNull String getUserId(); void setAttribute(@NotNull String name, @Nullable Object value); @Nullable Object getAttribute(@NotNull String name); void removeAttribute(@NotNull String name); @NotNull Map<String,Object> getAttributes(); void setAttributes(@NotNull Map<String,Object> attributes);  }
@Test public void testSetAttribute() { Object value = new Date(); credentials.setAttribute("attr", value); assertEquals(value, credentials.getAttribute("attr")); Map<String,Object> attributes = credentials.getAttributes(); assertTrue(attributes.containsKey("attr")); assertEquals(1, attributes.size()); assertEquals(value, attributes.get("attr")); }
@Test(expected = IllegalArgumentException.class) public void testSetNullAttributeName() { credentials.setAttribute(null, "value"); }