Hook methods are public
This commit is contained in:
parent
a66711a5b4
commit
5179b230c3
|
|
@ -4,8 +4,8 @@ import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
// TODO: interface? or abstract class?
|
// TODO: interface? or abstract class?
|
||||||
public abstract class Hook<T> {
|
public abstract class Hook<T> {
|
||||||
void before(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
|
public void before(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
|
||||||
void after(HookContext<T> ctx, FlagEvaluationDetails<T> details, ImmutableMap<String, Object> hints) {}
|
public void after(HookContext<T> ctx, FlagEvaluationDetails<T> details, ImmutableMap<String, Object> hints) {}
|
||||||
void error(HookContext<T> ctx, Exception error, ImmutableMap<String, Object> hints) {}
|
public void error(HookContext<T> ctx, Exception error, ImmutableMap<String, Object> hints) {}
|
||||||
void finallyAfter(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
|
public void finallyAfter(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,23 +195,23 @@ public class HookSpecTests {
|
||||||
api.setProvider(new NoOpProvider());
|
api.setProvider(new NoOpProvider());
|
||||||
api.registerHooks(new Hook<Boolean>() {
|
api.registerHooks(new Hook<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
public void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("api before");
|
evalOrder.add("api before");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
|
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("api after");
|
evalOrder.add("api after");
|
||||||
throw new RuntimeException(); // trigger error flows.
|
throw new RuntimeException(); // trigger error flows.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
|
public void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("api error");
|
evalOrder.add("api error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("api finally");
|
evalOrder.add("api finally");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -219,22 +219,22 @@ public class HookSpecTests {
|
||||||
Client c = api.getClient();
|
Client c = api.getClient();
|
||||||
c.registerHooks(new Hook<Boolean>() {
|
c.registerHooks(new Hook<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
public void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("client before");
|
evalOrder.add("client before");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
|
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("client after");
|
evalOrder.add("client after");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
|
public void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("client error");
|
evalOrder.add("client error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("client finally");
|
evalOrder.add("client finally");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -242,22 +242,22 @@ public class HookSpecTests {
|
||||||
c.getBooleanValue("key", false, null, FlagEvaluationOptions.builder()
|
c.getBooleanValue("key", false, null, FlagEvaluationOptions.builder()
|
||||||
.hook(new Hook<Boolean>() {
|
.hook(new Hook<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
public void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("invocation before");
|
evalOrder.add("invocation before");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
|
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("invocation after");
|
evalOrder.add("invocation after");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
|
public void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("invocation error");
|
evalOrder.add("invocation error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
||||||
evalOrder.add("invocation finally");
|
evalOrder.add("invocation finally");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -296,22 +296,22 @@ public class HookSpecTests {
|
||||||
Client client = api.getClient();
|
Client client = api.getClient();
|
||||||
Hook<Boolean> mutatingHook = new Hook<Boolean>() {
|
Hook<Boolean> mutatingHook = new Hook<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
public void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
||||||
assertTrue(hints instanceof ImmutableMap);
|
assertTrue(hints instanceof ImmutableMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
|
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
|
||||||
assertTrue(hints instanceof ImmutableMap);
|
assertTrue(hints instanceof ImmutableMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
|
public void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
|
||||||
assertTrue(hints instanceof ImmutableMap);
|
assertTrue(hints instanceof ImmutableMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
|
||||||
assertTrue(hints instanceof ImmutableMap);
|
assertTrue(hints instanceof ImmutableMap);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -397,21 +397,14 @@ public class HookSpecTests {
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Specification(spec="hooks", number="3.6", text="Condition: If finally is a reserved word in the language, finallyAfter SHOULD be used.")
|
@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() {
|
@Test void doesnt_use_finally() {
|
||||||
// Class [] carr = new Class[1];
|
try {
|
||||||
// carr[0] = HookContext.class;
|
Hook.class.getMethod("finally", HookContext.class, ImmutableMap.class);
|
||||||
//
|
fail("Not possible. Finally is a reserved word.");
|
||||||
// try {
|
} catch (NoSuchMethodException e) {
|
||||||
// Hook.class.getMethod("finally", carr);
|
// expected
|
||||||
// fail("Not possible. Finally is a reserved word.");
|
}
|
||||||
// } catch (NoSuchMethodException e) {
|
|
||||||
// // expected
|
|
||||||
// }
|
|
||||||
|
|
||||||
Hook.class.getMethod("finallyAfter", HookContext.class);
|
|
||||||
|
|
||||||
|
Hook.class.getMethod("finallyAfter", HookContext.class, ImmutableMap.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue