### Question:
DatabaseBackupRestoreService { public void validate(Long workspaceId, NameOrCrn nameOrCrn, String location, String backupId) { Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId); ValidationResult validationResult = requestValidator.validate(stack, location, backupId); if (validationResult.hasError()) { throw new BadRequestException(validationResult.getFormattedErrors()); } }  void validate(Long workspaceId, NameOrCrn nameOrCrn, String location, String backupId); FlowIdentifier backupDatabase(Long workspaceId, NameOrCrn nameOrCrn, String location, String backupId); FlowIdentifier restoreDatabase(Long workspaceId, NameOrCrn nameOrCrn, String location, String backupId);  }### Answer:
@Test public void testValidationSuccess() { Stack stack = getStack(); when(stackService.findStackByNameAndWorkspaceId(any(), anyLong())).thenReturn(Optional.of(stack)); when(stackService.getByNameOrCrnInWorkspace(any(), anyLong())).thenReturn(stack); when(requestValidator.validate(any(), any(), any())).thenReturn(getValidationResult(null)); service.validate(WORKSPACE_ID, ofName, null, null); }
@Test public void testValidationFailure() { Stack stack = getStack(); when(stackService.findStackByNameAndWorkspaceId(any(), anyLong())).thenReturn(Optional.of(stack)); when(stackService.getByNameOrCrnInWorkspace(any(), anyLong())).thenReturn(stack); when(requestValidator.validate(any(), any(), any())).thenReturn(getValidationResult(MISSING_PARAM_EXCEPTION_MESSAGE)); expectedException.expect(BadRequestException.class); expectedException.expectMessage("1. " + MISSING_PARAM_EXCEPTION_MESSAGE); service.validate(WORKSPACE_ID, ofName, null, null); }