We have a bunch of classes that listen for events from the server and then respond to them. For instance:
class EventManager {
private Set<Event> cache = new HashSet<Event>();
private EventListener eventListener = new EventListener() {
void onEvent(Event e) {
if (e instanceof MyEvent || e instanceof YourEvent) {
handleEvent(e);
}
}
}
public EventManager(ServerCommunication serverComm) {
serverComm.addListener(eventListener);
}
private handleEvent(Event e) {
cache.add(cache);
}
}
Here is an example of what we are doing. Here are the problems I see:
- I would like to check handleEvent to make sure that it does what it should, but I cannot because it is closed.
- I would also like to check that something has been added to the cache, but it also seems difficult, since the cache is a private member and I do not want to add an unnecessary getter method.
- I would also like to test the code inside the method of the anonymous onEvent class.
handleEvent, handleEvent ( unit test ). , .
- , ?