I have a runner which produces an event when the value is updated/changed.
[CODE lang="java" title="runner"]public void run(){
if(val!= cachedValue){
applicationEventPublisher.publishEvent(new DataEvent(this, val);
//only if a new value comes, then the event is fired
}
}[/CODE]
To verify I have a testcase, where the functionality is called twice with same inputs(For eg: When called for the first time, the value is not equal to cached value, hence event is fired. But when called again, I expect the event to not get fired)
Mockito Junit test:
I am not understanding what is going wrong after the second run here. I expect to see no events(which is the case while debugging the runner), but does not work.
Any suggestions or inputs here please? ALso excuse my language, still learning Deutsch
[CODE lang="java" title="runner"]public void run(){
if(val!= cachedValue){
applicationEventPublisher.publishEvent(new DataEvent(this, val);
//only if a new value comes, then the event is fired
}
}[/CODE]
To verify I have a testcase, where the functionality is called twice with same inputs(For eg: When called for the first time, the value is not equal to cached value, hence event is fired. But when called again, I expect the event to not get fired)
Mockito Junit test:
Java:
public class Testing{
public UnderTest underTest;
@mockbean
ApplicationEventPublisher applicationEventPublisher;
@Captor
private ArgumentCaptor<DataEvent> eventArgumentCaptor,eventArgumentCaptor2;
@Test
public test1(){
// some sample inputs
underTest.run() // first run, i expect the event to fire
verify(applicationEventPublisher).publishEvent(eventArgumentCaptor.capture()); // i get the value as expected here
//now i run again
underTest.run();
verify(applicationEventPublisher, never()).publishEvent(eventArgumentCaptor2.capture());
//fails here, the result show that the event is fired
assertEquals(0, eventArgumentCaptor2.getAllValues().size());
}
}
I am not understanding what is going wrong after the second run here. I expect to see no events(which is the case while debugging the runner), but does not work.
Any suggestions or inputs here please? ALso excuse my language, still learning Deutsch