Skip to content

Commit 5179b23

Browse files
committed
Hook methods are public
1 parent a66711a commit 5179b23

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

lib/src/main/java/javasdk/Hook.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
// TODO: interface? or abstract class?
66
public abstract class Hook<T> {
7-
void before(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
8-
void after(HookContext<T> ctx, FlagEvaluationDetails<T> details, ImmutableMap<String, Object> hints) {}
9-
void error(HookContext<T> ctx, Exception error, ImmutableMap<String, Object> hints) {}
10-
void finallyAfter(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
7+
public void before(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
8+
public void after(HookContext<T> ctx, FlagEvaluationDetails<T> details, ImmutableMap<String, Object> hints) {}
9+
public void error(HookContext<T> ctx, Exception error, ImmutableMap<String, Object> hints) {}
10+
public void finallyAfter(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
1111
}

lib/src/test/java/javasdk/HookSpecTests.java

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -195,69 +195,69 @@ void emptyApiHooks() {
195195
api.setProvider(new NoOpProvider());
196196
api.registerHooks(new Hook<Boolean>() {
197197
@Override
198-
void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
198+
public void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
199199
evalOrder.add("api before");
200200
}
201201

202202
@Override
203-
void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
203+
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
204204
evalOrder.add("api after");
205205
throw new RuntimeException(); // trigger error flows.
206206
}
207207

208208
@Override
209-
void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
209+
public void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
210210
evalOrder.add("api error");
211211
}
212212

213213
@Override
214-
void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
214+
public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
215215
evalOrder.add("api finally");
216216
}
217217
});
218218

219219
Client c = api.getClient();
220220
c.registerHooks(new Hook<Boolean>() {
221221
@Override
222-
void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
222+
public void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
223223
evalOrder.add("client before");
224224
}
225225

226226
@Override
227-
void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
227+
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
228228
evalOrder.add("client after");
229229
}
230230

231231
@Override
232-
void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
232+
public void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
233233
evalOrder.add("client error");
234234
}
235235

236236
@Override
237-
void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
237+
public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
238238
evalOrder.add("client finally");
239239
}
240240
});
241241

242242
c.getBooleanValue("key", false, null, FlagEvaluationOptions.builder()
243243
.hook(new Hook<Boolean>() {
244244
@Override
245-
void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
245+
public void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
246246
evalOrder.add("invocation before");
247247
}
248248

249249
@Override
250-
void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
250+
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
251251
evalOrder.add("invocation after");
252252
}
253253

254254
@Override
255-
void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
255+
public void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
256256
evalOrder.add("invocation error");
257257
}
258258

259259
@Override
260-
void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
260+
public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
261261
evalOrder.add("invocation finally");
262262
}
263263
})
@@ -296,22 +296,22 @@ void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints)
296296
Client client = api.getClient();
297297
Hook<Boolean> mutatingHook = new Hook<Boolean>() {
298298
@Override
299-
void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
299+
public void before(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
300300
assertTrue(hints instanceof ImmutableMap);
301301
}
302302

303303
@Override
304-
void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
304+
public void after(HookContext<Boolean> ctx, FlagEvaluationDetails<Boolean> details, ImmutableMap<String, Object> hints) {
305305
assertTrue(hints instanceof ImmutableMap);
306306
}
307307

308308
@Override
309-
void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
309+
public void error(HookContext<Boolean> ctx, Exception error, ImmutableMap<String, Object> hints) {
310310
assertTrue(hints instanceof ImmutableMap);
311311
}
312312

313313
@Override
314-
void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
314+
public void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints) {
315315
assertTrue(hints instanceof ImmutableMap);
316316
}
317317
};
@@ -397,21 +397,14 @@ void finallyAfter(HookContext<Boolean> ctx, ImmutableMap<String, Object> hints)
397397

398398
@SneakyThrows
399399
@Specification(spec="hooks", number="3.6", text="Condition: If finally is a reserved word in the language, finallyAfter SHOULD be used.")
400-
@Disabled("Unsure why the getMethod() call doesn't work correctly")
401400
@Test void doesnt_use_finally() {
402-
// Class [] carr = new Class[1];
403-
// carr[0] = HookContext.class;
404-
//
405-
// try {
406-
// Hook.class.getMethod("finally", carr);
407-
// fail("Not possible. Finally is a reserved word.");
408-
// } catch (NoSuchMethodException e) {
409-
// // expected
410-
// }
411-
412-
Hook.class.getMethod("finallyAfter", HookContext.class);
401+
try {
402+
Hook.class.getMethod("finally", HookContext.class, ImmutableMap.class);
403+
fail("Not possible. Finally is a reserved word.");
404+
} catch (NoSuchMethodException e) {
405+
// expected
406+
}
413407

408+
Hook.class.getMethod("finallyAfter", HookContext.class, ImmutableMap.class);
414409
}
415-
416-
417410
}

0 commit comments

Comments
 (0)