SimpleStateManager implements StateManager { @Override public boolean stateExistsForUser(Resource stateId, String username) { User user = engineManager.retrieveUser(username).orElseThrow(() -> new IllegalArgumentException("User not found")); try (RepositoryConnection conn = repository.getConnection()) { if (!stateExists(stateId, conn)) { throw new IllegalArgumentException("State not found"); } return conn.getStatements(stateId, factory.createIRI(State.forUser_IRI), user.getResource()).hasNext(); } }  @Override boolean stateExists(Resource stateId); @Override boolean stateExistsForUser(Resource stateId, String username); @Override Map<Resource, Model> getStates(@Nullable String username, @Nullable String applicationId,
                                          Set<Resource> subjects); @Override Resource storeState(Model newState, String username); @Override Resource storeState(Model newState, String username, String applicationId); @Override Model getState(Resource stateId); @Override void updateState(Resource stateId, Model newState); @Override void deleteState(Resource stateId);  }
@Test public void stateExistsForUserTest() throws Exception { RepositoryConnection conn = repo.getConnection(); conn.add(VALUE_FACTORY.createIRI("http: conn.add(VALUE_FACTORY.createIRI("http: conn.add(VALUE_FACTORY.createIRI("http: conn.add(VALUE_FACTORY.createIRI("http: assertTrue(manager.stateExistsForUser(VALUE_FACTORY.createIRI("http: assertFalse(manager.stateExistsForUser(VALUE_FACTORY.createIRI("http: conn.close(); }
@Test(expected = IllegalArgumentException.class) public void stateThatDoesNotExistExistsForUserTest() { manager.stateExistsForUser(VALUE_FACTORY.createIRI("http: }
@Test(expected = IllegalArgumentException.class) public void stateExistsForUserThatDoesNotExistTest() { RepositoryConnection conn = repo.getConnection(); conn.add(VALUE_FACTORY.createIRI("http: when(engineManager.retrieveUser(anyString())).thenReturn(Optional.empty()); manager.stateExistsForUser(VALUE_FACTORY.createIRI("http: }