Hi I want to test the generateKey method and the messages being dispatched by the Dispatcher. I have tried to mock the class and the public method verifyOtherDetails(). Inside it I created an expectation that the dispatcher method had a literal value but it always passes. Any help would be appreciated.
See bottom for my attempted code thanks.
abstract class KeyGen {
private static void generateKey(String key, String username){
if(Strings.isNullOrEmpty(key)){
Dispatcher.dispatch(new WarningString(String.format("The key is null or empty for user %s", username)));
}else{
Dispatcher.dispatch(new InfoString(String.format("The key is correct for user %s", username)));
}
}
public void verifyOtherDetails(String address, Map<String, String> favouriteFilms){
String key ="";
String username ="";
generateKey(key, username);
}
}
public class TestKeyGen {
@Test
public void testKey() {
new MockUp<KeyGen>() {
@Mock()
public void verifyOtherDetails() {
String key = "sfjhlkjhfkjdhlsk";
final String username = "Daniel";
new Expectations() {
{
Dispatcher.dispatch(new WarningString(String.format("The key is null or empty for user %s", username)));
}
};
}
};
}
}