public class SupportController{
public void disableUserAccount(String username) throws Exception {
UserAccount userAccount =
new UserAccount(Constants.SYSTEM, Constants.CONTAINER, username);
UserAccount.disableAccount();
}
}
How would i test that the useraccount created is disabled?
I would suggest using Mock Objects.
Besides that, you can check the JUnit FAQ, where you can find a section about testing methods that return
void
.There are three basic solutions:
PowerMock
does not always play well with other runners (for example SpringJUnit4TestRunner). I usually avoid it for this reason and the fact that it modifies the compiled code.The overridable factory method is another option. To do this you must extend the class and override the factory method. This means that the test is running against an instance of the class under test that is not actually the class under test but a testable subclass. This has test-smell to me so I tend to avoid it where possible.
The factory class method is my preferred solution. Pass in a Factory class that be default creates the
UserAccount
. In your test provide a mocked (I useMockito
) version of the factory.