Open rhusar opened 2 months ago
@rhusar Do you mean those two?
Do you have any idea what to do about them? I browsed the history, and the initial commit from 2012 still contained @Test
annotations and some mocks for variables, but this was removed afterwards, further methods were added, but none are invoked.
So I have no idea what this piece of code should actually do and why parts of the class were removed ;-).
Yes, those in API module. I think these were meant to be just mocks, just to avoid accidentally breaking the API contract, but for some reason that was dropped and never restored. But those are compiled, so basically, little to lose here anyway,...
Your explanation sounds reasonable ;-). So, what to do about them and this issue?
I suppose just make them @ Test -s again and use mocking.
OK, I will take a look the next few days. But I will have much more questions on the way ;-)
@rhusar Help ;-)... This issue turns out to become a Mockito tutorial...
I started with the first method in TestObserverBuilderAPI
:
public void testFilterBuilderUriNot() {
Warp
.initiate(activity)
.observe(request().uri().not().endsWith(".jsf"))
.inspect(inspection);
}
..and tried to split it to pieces and mock it:
public void testFilterBuilderUriNot() {
WarpExecutionBuilder mockBuilder = Mockito.mock(WarpExecutionBuilder.class);
MockedStatic<Warp> mockWarp = Mockito.mockStatic(Warp.class);
mockWarp.when(() -> Warp.initiate(activity)).thenReturn(mockBuilder);
WarpExecutionBuilder realBuilder = Warp.initiate(activity) ;
//call "observe":
SingleInspectionSpecifier mockInspectionSpecifier = Mockito.mock(SingleInspectionSpecifier.class);
//this line fails - "HttpFilters.request()" returns null.
Mockito.when(realBuilder.observe(request().uri().not().endsWith(".jsf"))).thenReturn(mockInspectionSpecifier);
SingleInspectionSpecifier realInspectionSpecifier = realBuilder.observe(request().uri().not().endsWith(".jsf"));
Should I mock "HttpFilters.request", too (and all the chain down)?
MockedStatic<HttpFilters> mockFilters = Mockito.mockStatic(HttpFilters.class);
//what should "request()" return? A mock to `HttpFilterBuilder`?
It looks like these are only meant to be 'compiled' but never run but the execution was never disabled in maven.
These tests would require the impl to be available, so they need to be reworked to Mocks.
FYI @WolfgangHG - this one is quite funny :-)