### Question:
DefaultAuthorityService implements AuthorityService { @Override public Authority getAuthorityById(String entityId) { return repository.get(entityId); } @Autowired  DefaultAuthorityService(AuthorityRepository repository); @Override Authority getAuthorityById(String entityId); @Override Authority getAuthorityByName(String authorityName); @Override SearchResult<Authority> getAllAuthorities(); @Override SearchResult<Authority> getDefaultAuthorities();  }### Answer:
@Test public void getAuthorityById() { Authority authority = createAuthority(); expect(repository.get("123")).andReturn(authority); replay(repository); Authority sAuthority = service.getAuthorityById("123"); assertEquals(sAuthority, authority); verify(repository); }
@Test public void getAuthorityById_NotFound() { AuthorityImpl authority = new AuthorityImpl(); authority.setAuthority("BAR"); final String entityId = "456"; expect(repository.get(entityId)).andReturn(null); replay(repository); Authority sAuthority = service.getAuthorityById(entityId); assertNull(sAuthority); verify(repository); }