### Question:
DefaultRoleAccessor implements RoleAccessor { @Override public UserRoleModel createRole(String roleName) throws AlertDatabaseConstraintException { RoleEntity dbRole = createRole(roleName, true); return UserRoleModel.of(dbRole.getRoleName(), dbRole.getCustom()); } @Autowired  DefaultRoleAccessor(RoleRepository roleRepository, UserRoleRepository userRoleRepository, PermissionMatrixRepository permissionMatrixRepository,
        RegisteredDescriptorRepository registeredDescriptorRepository, ConfigContextRepository configContextRepository); @Override Set<UserRoleModel> getRoles(); @Override Set<UserRoleModel> getRoles(Collection<Long> roleIds); @Override boolean doesRoleNameExist(String name); @Override UserRoleModel createRole(String roleName); @Override UserRoleModel createRoleWithPermissions(String roleName, PermissionMatrixModel permissionMatrix); @Override void updateRoleName(Long roleId, String roleName); @Override PermissionMatrixModel updatePermissionsForRole(String roleName, PermissionMatrixModel permissionMatrix); @Override void deleteRole(Long roleId); @Override void updateUserRoles(Long userId, Collection<UserRoleModel> roles); @Override PermissionMatrixModel mergePermissionsForRoles(Collection<String> roleNames); @Override PermissionMatrixModel readPermissionsForRole(Long roleId);  }### Answer:
@Test public void createRoleTest() throws Exception { final String roleName = "roleName"; Mockito.when(roleRepository.save(Mockito.any())).thenReturn(new RoleEntity(roleName, true)); DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository); UserRoleModel userRoleModel = authorizationUtility.createRole(roleName); UserRoleModel expectedUserRoleModel = createUserRoleModel(null, roleName, true); assertEquals(expectedUserRoleModel, userRoleModel); }
@Test public void createRoleNullTest() throws Exception { DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository); try { authorizationUtility.createRole(""); fail("Blank roleName did not throw expected AlertDatabaseConstraintException."); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }