I have build a kind of handler pattern which gives me specific handler types based on input parameter. The autowiring is at constructor level, which fills the container(HashMap) with respective Strategy beans. Here is the code. How can I assert this using Junit?
NOTE: Strategy is an interface and those are used by impl class.
@Component
public class StrategyHandler {
private Map<String, Strategy> responses;
@Autowired
public StrategyHandler(Set<Strategy> responseSet) {
responses = new HashMap<>();
responseSet.forEach(strategy -> responses.put(strategy.getName(), strategy));
}
public Strategy getStrategy(String name) {
return responses.get(name);
}
}