diff --git a/lib/src/main/java/javasdk/Hook.java b/lib/src/main/java/javasdk/Hook.java index 15651fa8..02d6c3b0 100644 --- a/lib/src/main/java/javasdk/Hook.java +++ b/lib/src/main/java/javasdk/Hook.java @@ -4,8 +4,8 @@ import com.google.common.collect.ImmutableMap; // TODO: interface? or abstract class? public abstract class Hook { - void before(HookContext ctx, ImmutableMap hints) {} - void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) {} - void error(HookContext ctx, Exception error, ImmutableMap hints) {} - void finallyAfter(HookContext ctx, ImmutableMap hints) {} + public void before(HookContext ctx, ImmutableMap hints) {} + public void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) {} + public void error(HookContext ctx, Exception error, ImmutableMap hints) {} + public void finallyAfter(HookContext ctx, ImmutableMap hints) {} } diff --git a/lib/src/test/java/javasdk/HookSpecTests.java b/lib/src/test/java/javasdk/HookSpecTests.java index 1e7e22fc..4ada90b3 100644 --- a/lib/src/test/java/javasdk/HookSpecTests.java +++ b/lib/src/test/java/javasdk/HookSpecTests.java @@ -195,23 +195,23 @@ public class HookSpecTests { api.setProvider(new NoOpProvider()); api.registerHooks(new Hook() { @Override - void before(HookContext ctx, ImmutableMap hints) { + public void before(HookContext ctx, ImmutableMap hints) { evalOrder.add("api before"); } @Override - void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) { + public void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) { evalOrder.add("api after"); throw new RuntimeException(); // trigger error flows. } @Override - void error(HookContext ctx, Exception error, ImmutableMap hints) { + public void error(HookContext ctx, Exception error, ImmutableMap hints) { evalOrder.add("api error"); } @Override - void finallyAfter(HookContext ctx, ImmutableMap hints) { + public void finallyAfter(HookContext ctx, ImmutableMap hints) { evalOrder.add("api finally"); } }); @@ -219,22 +219,22 @@ public class HookSpecTests { Client c = api.getClient(); c.registerHooks(new Hook() { @Override - void before(HookContext ctx, ImmutableMap hints) { + public void before(HookContext ctx, ImmutableMap hints) { evalOrder.add("client before"); } @Override - void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) { + public void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) { evalOrder.add("client after"); } @Override - void error(HookContext ctx, Exception error, ImmutableMap hints) { + public void error(HookContext ctx, Exception error, ImmutableMap hints) { evalOrder.add("client error"); } @Override - void finallyAfter(HookContext ctx, ImmutableMap hints) { + public void finallyAfter(HookContext ctx, ImmutableMap hints) { evalOrder.add("client finally"); } }); @@ -242,22 +242,22 @@ public class HookSpecTests { c.getBooleanValue("key", false, null, FlagEvaluationOptions.builder() .hook(new Hook() { @Override - void before(HookContext ctx, ImmutableMap hints) { + public void before(HookContext ctx, ImmutableMap hints) { evalOrder.add("invocation before"); } @Override - void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) { + public void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) { evalOrder.add("invocation after"); } @Override - void error(HookContext ctx, Exception error, ImmutableMap hints) { + public void error(HookContext ctx, Exception error, ImmutableMap hints) { evalOrder.add("invocation error"); } @Override - void finallyAfter(HookContext ctx, ImmutableMap hints) { + public void finallyAfter(HookContext ctx, ImmutableMap hints) { evalOrder.add("invocation finally"); } }) @@ -296,22 +296,22 @@ public class HookSpecTests { Client client = api.getClient(); Hook mutatingHook = new Hook() { @Override - void before(HookContext ctx, ImmutableMap hints) { + public void before(HookContext ctx, ImmutableMap hints) { assertTrue(hints instanceof ImmutableMap); } @Override - void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) { + public void after(HookContext ctx, FlagEvaluationDetails details, ImmutableMap hints) { assertTrue(hints instanceof ImmutableMap); } @Override - void error(HookContext ctx, Exception error, ImmutableMap hints) { + public void error(HookContext ctx, Exception error, ImmutableMap hints) { assertTrue(hints instanceof ImmutableMap); } @Override - void finallyAfter(HookContext ctx, ImmutableMap hints) { + public void finallyAfter(HookContext ctx, ImmutableMap hints) { assertTrue(hints instanceof ImmutableMap); } }; @@ -397,21 +397,14 @@ public class HookSpecTests { @SneakyThrows @Specification(spec="hooks", number="3.6", text="Condition: If finally is a reserved word in the language, finallyAfter SHOULD be used.") - @Disabled("Unsure why the getMethod() call doesn't work correctly") @Test void doesnt_use_finally() { -// Class [] carr = new Class[1]; -// carr[0] = HookContext.class; -// -// try { -// Hook.class.getMethod("finally", carr); -// fail("Not possible. Finally is a reserved word."); -// } catch (NoSuchMethodException e) { -// // expected -// } - - Hook.class.getMethod("finallyAfter", HookContext.class); + try { + Hook.class.getMethod("finally", HookContext.class, ImmutableMap.class); + fail("Not possible. Finally is a reserved word."); + } catch (NoSuchMethodException e) { + // expected + } + Hook.class.getMethod("finallyAfter", HookContext.class, ImmutableMap.class); } - - }