I'm writing test cases for my controller layer. One Of my controller method looks like below.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
@RequestMapping("/v1")
public class MyController {
private static Logger logger = LoggerFactory.getLogger(MyController.class);
@Autowired
private MyService service;
@GetMapping("/{pathVar}/check")
@MyAuthentication
public ResponseEntity<Object> check(@PathVariable String pathVar,
@MyAuthContext MyAuthInfo myAuthInfo) throws Exception {
try {
logger.info("Check API started by "+myAuthInfo.getUserId()+" and email "+ myAuthInfo.getUserEmail());
return ResponseEntity
.status(HttpStatus.OK)
.body(service.isPartner(pathVar, myAuthInfo));
} catch (Exception e) {
logger.info("Check API encountered the error.", e);
throw e;
}
}
}
Can someone please help to mock my auth context while I'm writing test cases?