@Test
public void test_createAppRole_failure_duplicate() {

    Response responseList = getMockResponse(HttpStatus.OK, true, "{\"keys\": [ \"approle1\" ]}");
    String token = "5PDrOhsy4ig8L3EpsJZSLAMg";
    String [] policies = {"default"};
    AppRole appRole = new AppRole("approle1", policies, true, 1, 100, 0);
    String jsonStr = "{\"role_name\":\"approle1\",\"policies\":[\"default\"],\"bind_secret_id\":true,\"secret_id_num_uses\":\"1\",\"secret_id_ttl\":\"100m\",\"token_num_uses\":0,\"token_ttl\":null,\"token_max_ttl\":null}";
    ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"AppRole already exists and can't be created\"]}");
    Map<String,Object> appRolesList = new HashMap<>();
    ArrayList<String> arrayList = new ArrayList<>();
    arrayList.add("approle1");
    appRolesList.put("keys", arrayList);
    when(ControllerUtil.parseJson("{\"keys\": [ \"approle1\" ]}")).thenReturn(appRolesList);
    when(reqProcessor.process("/auth/approle/role/list","{}",token)).thenReturn(responseList);
    when(ControllerUtil.areAppRoleInputsValid(appRole)).thenReturn(true);
    when(JSONUtil.getJSON(appRole)).thenReturn(jsonStr);
    when(ControllerUtil.convertAppRoleInputsToLowerCase(Mockito.any())).thenReturn(jsonStr);
    UserDetails userDetails = getMockUser(true);
    Response responseAfterHide = getMockResponse(HttpStatus.OK, true, "{\"keys\": [ \"approle1\" ]}");
    when(ControllerUtil.hideMasterAppRoleFromResponse(Mockito.any())).thenReturn(responseAfterHide);
    ResponseEntity<String> responseEntityActual = appRoleService.createAppRole(token, appRole, userDetails);
    assertEquals(HttpStatus.BAD_REQUEST, responseEntityActual.getStatusCode());
    assertEquals(responseEntityExpected, responseEntityActual);
}