SimpleEngineManager implements EngineManager { @Override public Optional<String> getUsername(Resource userIri) { for (User user: getUsers()) { if (user.getResource().equals(userIri)) { return user.getUsername().map(Value::stringValue); } } return Optional.empty(); }  @Reference(type = '*', dynamic = true) void addEngine(Engine engine); void removeEngine(Engine engine); @Override boolean containsEngine(String engine); @Override Optional<Role> getRole(String engine, String roleName); @Override Optional<Role> getRole(String roleName); @Override Set<User> getUsers(String engine); @Override Set<User> getUsers(); @Override User createUser(String engine, UserConfig userConfig); @Override void storeUser(String engine, User user); @Override Optional<User> retrieveUser(String engine, String username); @Override Optional<User> retrieveUser(String username); @Override void deleteUser(String engine, String username); @Override void updateUser(String engine, User newUser); @Override void updateUser(User newUser); @Override boolean userExists(String engine, String username); @Override boolean userExists(String username); @Override Set<Group> getGroups(String engine); @Override Set<Group> getGroups(); @Override Group createGroup(String engine, GroupConfig groupConfig); @Override void storeGroup(String engine, Group group); @Override Optional<Group> retrieveGroup(String engine, String groupTitle); @Override Optional<Group> retrieveGroup(String groupTitle); @Override void deleteGroup(String engine, String groupTitle); @Override void updateGroup(String engine, Group newGroup); @Override void updateGroup(Group newGroup); @Override boolean groupExists(String engine, String groupTitle); @Override boolean groupExists(String groupTitle); @Override Set<Role> getUserRoles(String engine, String username); @Override Set<Role> getUserRoles(String username); @Override boolean checkPassword(String engine, String username, String password); @Override boolean checkPassword(String username, String password); @Override Optional<String> getUsername(Resource userIri);  }
@Test public void testGetUsername() { Optional<String> result = engineManager.getUsername(user.getResource()); assertTrue(result.isPresent()); assertEquals(result.get(), user.getUsername().get().stringValue()); result = engineManager.getUsername(ERROR_IRI); assertFalse(result.isPresent()); }