### Question:
ContributorService implements SearchableEntityService { protected boolean isRolesChanged(String id, Map<String, Object> entity) { Map<String, Object> oldEntity = get(id); if (oldEntity != null) { Set<String> oldRoles = extractRoles(oldEntity); Set<String> newRoles = extractRoles(entity); return !ListUtils.isEqualList(oldRoles, newRoles); } return false; }  @PostConstruct void init(); @Override StreamingOutput getAll(Integer from, Integer size, String[] fieldsToRemove); @Override List<Map<String, Object>> getAll(); @Override Map<String, Object> get(String id); @Override String create(Map<String, Object> entity); String create(Map<String, Object> entity, boolean fireEvent); @Override void create(String id, Map<String, Object> entity); void create(String id, Map<String, Object> entity, boolean fireEvent); @Override void update(String id, Map<String, Object> entity); void update(String id, Map<String, Object> entity, boolean fireEvent); @Override void delete(String id); SearchResponse findByCode(String code); SearchResponse findByEmail(String email); SearchResponse findByName(String name, boolean exactMatch); SearchResponse findByTypeSpecificCode(String codeName, String codeValue); SearchResponse findByTypeSpecificCodeExistence(String codeName); Set<String> getRolesByTypeSpecificCode(String codeName, String username); static String createContributorId(String fullName, String email); static String extractContributorName(String contributorID); @SuppressWarnings("unchecked") static Set<String> extractRoles(Map<String, Object> fields); @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) String createOrUpdateFromProfile(ContributorProfile profile, String typeSpecificCodeField,
			String typeSpecificCodeValue); static String getContributorCode(Map<String, Object> contribStructure); @SuppressWarnings("unchecked") static String getContributorTypeSpecificCodeFirst(Map<String, Object> contribStructure,
			String contributorCodeType); Map<String, Object> changeContributorCode(String id, String code); Map<String, Object> mergeContributors(String idFrom, String idTo); @Override ListRequest listRequestInit(); @Override ListRequest listRequestNext(ListRequest previous); @Override BulkRequestBuilder prepareBulkRequest(); @Override void updateSearchIndex(BulkRequestBuilder brb, String id, Map<String, Object> entity); @Override void deleteOldFromSearchIndex(Date timestamp); static final String SEARCH_INDEX_NAME; static final String SEARCH_INDEX_TYPE; static final String FIELD_CODE; static final String FIELD_EMAIL; static final String FIELD_NAME; static final String FIELD_ROLES; static final String FIELD_HIRE_DATE; static final String FIELD_LEAVE_DATE; static final String FIELD_TYPE_SPECIFIC_CODE; }### Answer:
@Test public void isRolesChanged() { ContributorService tested = new ContributorService(); tested.entityService = Mockito.mock(EntityService.class); Map<String, Object> oldEntity = new HashMap<>(); List<String> oldRoles = new ArrayList<>(); oldEntity.put(ContributorService.FIELD_ROLES, oldRoles); oldRoles.add("admin"); oldRoles.add("contributor"); Mockito.when(tested.entityService.get(Mockito.anyString())).thenReturn(oldEntity); Map<String, Object> newEntity = new HashMap<>(); List<String> newRoles = new ArrayList<>(); newEntity.put(ContributorService.FIELD_ROLES, newRoles); newRoles.add("admin"); newRoles.add("contributor"); Assert.assertFalse(tested.isRolesChanged("", newEntity)); newRoles.remove("admin"); Assert.assertTrue(tested.isRolesChanged("", newEntity)); }