I'd like to write a test for verification if static method receiving correct callable as an argument. Let's say I have 2 classes:
Employee
public class Employee {
public static Item getEmployeeItem() {
return new Item((a, b) -> {
return a * b;
});
}
}
and Item
public class Item {
BiFunction<Integer, Integer, Integer> behaviour;
Item(BiFunction<Integer, Integer, Integer> biFunction) {
this.behaviour = biFunction;
}
}
Item has constructor with BiFunction. I'd like to to test with using junit5, Mockito, PowerMock or maybe other utills, behaviour when in case when I call
Item item = Employee.getEmployeeItem();
then appriopriate BiFunction has been delivered. How can I write such kind of test with junit5? Maybe should I use somehow ArgumentCaptor? Can someone deliver me example?
That's actually simpler example of more advanced case which I need to test in unit way in my job:
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class EthernetExtractFilterFrameParsingNodeDefinitions {
public static ExtractFilterTreeNodeDefinition<EthernetExtractFilter, EthernetDataTuple, IpProtocol, Option<Vector<SingleDataSet>>> getIpProtocolNodeDefinition() {
return new ExtractFilterTreeNodeDefinition<>(
ethernetExtractFilter -> ethernetExtractFilter.networkLayerPduFilter().ipProtocolFilter().toValueFilter(),
getNodeBehaviour(ethernetDataTuple -> ethernetDataTuple.networkLayerPdu().getIpProtocol())
);
}
}
I have to check here if ExtractFilterTreeNodeDefinition was created with appropriate Functions as parameters when I call getIpProtocolNodeDefinition() statick method.
I'd like to be sure that first argument is correct function, correctly map extractFilter to valueFilter:
ethernetExtractFilter -> ethernetExtractFilter.networkLayerPduFilter().ipProtocolFilter().toValueFilter()
second one as well How to approach to that problem? I would be grateful for suggestions how to achieve that.