From 78236dd07f3b79ca1b608b8fa0fd7ff3fbc0495c Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sat, 16 Nov 2024 14:51:59 -0800 Subject: [PATCH] Fixes SwitcherTest when input not provided for evaluation --- .../client/model/response/CriteriaResponse.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/switcherapi/client/model/response/CriteriaResponse.java b/src/main/java/com/github/switcherapi/client/model/response/CriteriaResponse.java index c0c6715d..9d99d2ad 100644 --- a/src/main/java/com/github/switcherapi/client/model/response/CriteriaResponse.java +++ b/src/main/java/com/github/switcherapi/client/model/response/CriteriaResponse.java @@ -33,9 +33,11 @@ public class CriteriaResponse { protected Map> entryWhen; public CriteriaResponse() { + entryWhen = new HashMap<>(); } public CriteriaResponse(final boolean result, final String reason, final Switcher switcher) { + this(); this.result = result; this.reason = reason; this.switcherKey = switcher.getSwitcherKey(); @@ -58,7 +60,7 @@ public CriteriaResponse buildFromSwitcher(Switcher switcher) { } private boolean isEntryMatching(Entry inputEntry) { - return entryWhen.containsKey(inputEntry.getStrategy()) && + return entryWhen.isEmpty() || entryWhen.containsKey(inputEntry.getStrategy()) && entryWhen.get(inputEntry.getStrategy()).contains(inputEntry.getInput()); } @@ -120,10 +122,6 @@ public CriteriaResponse when(StrategyValidator strategy, String input) { } public CriteriaResponse when(StrategyValidator strategy, List inputs) { - if (entryWhen == null) { - entryWhen = new HashMap<>(); - } - entryWhen.put(strategy.toString(), inputs); return this; }