@PostMapping(path = "/add")
public @ResponseBody ResponseEntity<String> addAccount(@RequestBody Account account) {
if (account != null && account.getUserName() != null && account.getUserPass() != null) ) {
if (accountRepository.countUserName(account.getUserName()) > 0) {
return new ResponseEntity<String>("Account",HttpStatus.BAD_REQUEST);
}
account.setUserPass(bCryptPasswordEncoder.encod(account.getUserPass()));
accountRepository.AccountSaveTo(account);
return new ResponseEntity<String>("Saved",HttpStatus.OK);
}
return new ResponseEntity<String>("Invalid",HttpStatus.BAD_REQUEST);
}
I must test this method of AccountController. I am testing the method in Spring with the Mockito library. How I can test this method? I previously wrote the following unit test:
@Test
public void shouldSaveAccountToDb() {
Account acc = new Account();
acc.setUser(this.user);
acc.setEmail(this.mail);
String account = this.accountController.addAccount(this.user, this.mail);
verify(this.accountRepepetytory)).save(Mockito.refEq(acc, new String[0]));
Assert.assertThat(account, CoreMatchers.is("Account"));
}
but this method was improved and changed and I must write a new unit test, but I do not know how and where to start. Could you help, even with pseudocode?