### Question:
TomlUser extends AbstractUser { @Override public JsonObject principal() { final JsonObject principle = new JsonObject() .put("username", username) .put("password", password) .put("groups", groups) .put("permissions", permissions) .put("roles", roles); privacyPublicKey.ifPresent(pk -> principle.put("privacyPublicKey", pk)); return principle; } TomlUser(
      final String username,
      final String password,
      final List<String> groups,
      final List<String> permissions,
      final List<String> roles,
      final Optional<String> privacyPublicKey); @Override JsonObject principal(); @Override void setAuthProvider(final AuthProvider authProvider); String getUsername(); String getPassword(); List<String> getGroups(); List<String> getPermissions(); List<String> getRoles(); Optional<String> getPrivacyPublicKey();  }### Answer:
@Test public void createsPrincipleWithAllValues() { final TomlUser tomlUser = new TomlUser( "user", "password", list("admin"), list("eth:*", "perm:*"), list("net"), Optional.of("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=")); final JsonObject principal = tomlUser.principal(); assertThat(principal.getString("username")).isEqualTo("user"); assertThat(principal.getString("password")).isEqualTo("password"); assertThat(principal.getJsonArray("groups")).isEqualTo(new JsonArray(list("admin"))); assertThat(principal.getJsonArray("permissions")) .isEqualTo(new JsonArray(list("eth:*", "perm:*"))); assertThat(principal.getJsonArray("roles")).isEqualTo(new JsonArray(list("net"))); assertThat(principal.getString("privacyPublicKey")) .isEqualTo("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="); }
@Test public void createsPrincipalWithOnlyRequiredValues() { final TomlUser tomlUser = new TomlUser("user", "password", list(), list(), list(), Optional.empty()); final JsonObject principal = tomlUser.principal(); assertThat(principal.getString("username")).isEqualTo("user"); assertThat(principal.getString("password")).isEqualTo("password"); assertThat(principal.getJsonArray("groups")).isEqualTo(new JsonArray()); assertThat(principal.getJsonArray("permissions")).isEqualTo(new JsonArray()); assertThat(principal.getJsonArray("roles")).isEqualTo(new JsonArray()); assertThat(principal.containsKey("privacyPublicKey")).isFalse(); }