How to simulate annotated EJBs?

Iโ€™ve already entered Google, but it seems to me that itโ€™s hard to find topics about mock injection dependency objects (EJB 3.0).

public class MyTestBean { @EJB ILoginService mLoginService; public void doLogin() { if (!mLoginService.login(name, pass)) { // fehler } } 

When running tests with openEJB, I want the name LoginService.login (name, pass) to return true. Is there any way to make fun of LoginService bean?

(Currently, the login method uses some JAAS things that I cannot simulate during tests.)

+4
source share
2 answers

Maybe take a look at Mokito. You can apply the @EJB annotation to the setters and enter the ridiculous LoginService into your tests.

+3
source

Another option is to simply provide a second implementation of your ILoginService interface. This second implementation is a layout, but it does not require a special Mock library or support.

You put this implementation in a special source folder, usually called a test. Then you create your deployment scripts so that during normal build this test folder is ignored. When you run your unit tests and create an archive for testing, you explicitly include the Mock implementation from the test source folder.

+1
source

Source: https://habr.com/ru/post/1337345/


All Articles