This question is somewhat philosophical. Given i have a Method like this:
public List<String> getStuffByName(@NotNull String name) throws SomeException {
return someDependency.createQuery().byName(name).list().stream()
.map(execution -> execution.getProcessInstanceId())
.collect(Collectors.toList());
}
Basically all it does is call a dependencies method and then process it using the stream api.
A Unittest - in a strict understanding(?) - is only testing one isolated unit. So i would Mock the dependencies, as i assume they also are already tested units themselves.
If I go through with this, i end up with a Method that exclusively consists of stuff that is tested elsewhere.
Eg my JMockit Test would look like this:
public void test_get_processes_for_bkey_2(@Mocked ExecutionQuery query,
@Mocked List<String> processes,
@Mocked List<Execution> executions,
@Mocked Stream<Execution> e_stream,
@Mocked Stream<String> pid_stream,
@Mocked Stream<String> pdef_stream
) {
new Expectations() {
{
someDependency.createQuery(); result = query;
query.byName("somefilter"); result = query;
query.list(); result = executions;
executions.stream(); result = e_stream;
e_stream.map((Function) any); result = fin_stream;
fin_stream.collect((Collector) any); result = processes;
processes.size(); result = 2;
}
};
assertEquals(tested.getStuffByName("somefilter").size(), 2);
}
But what does this test really tell me?
In test-driven-development, would i omit tests of such "wrapper" methods?
What would a professional approach to test this be, independent of Jmockit or other frameworks?
The contract of the method is to execute the query having the given name, and return the process instance IDs of the Execution instances returned by the query. Whether your method uses streams, or a for loop, or anything to do that is irrelevant.
So I would only stub the query and make it return a real list of 2 or 3 executions. Based on that list returned by the query, I would check that the returned List contains the appropriate 2 or 3 IDs, in the correct order.