Skip to content

Commit 131f810

Browse files
committed
Merge #986 'Use Integer.compare() in HookComparator'
Also Update History.md.
2 parents 361c13c + a696674 commit 131f810

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [1.2.5-SNAPSHOT](https://github.com/cucumber/cucumber-jvm/compare/v1.2.4...master) (In Git)
22

3+
* [Core] Use Integer.compare() in HookComparator in order to guard against possible underflow ([#986](https://github.com/cucumber/cucumber-jvm/pull/986), [#985](https://github.com/cucumber/cucumber-jvm/issues/985) Mikael Auno)
34
* [Junit] Let JUnitReporter treat Pending results in hooks as failures in strict mode, and as ignored tests otherwise (Björn Rasmusson)
45
* [Core] Mark scenario as skipped in JUnitFormatter if PendingException is thrown in a hook ([#964](https://github.com/cucumber/cucumber-jvm/pull/964), [#962](https://github.com/cucumber/cucumber-jvm/issues/962) Felix Martin Martin)
56
* [Core] Support assume feature also with JUnit 4.12 ([#961](https://github.com/cucumber/cucumber-jvm/pull/961) Stefan Birkner)

core/src/main/java/cucumber/runtime/HookComparator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public HookComparator(boolean ascending) {
1111

1212
@Override
1313
public int compare(HookDefinition hook1, HookDefinition hook2) {
14-
int comparison = hook1.getOrder() - hook2.getOrder();
14+
int comparison = Integer.compare(hook1.getOrder(), hook2.getOrder());
1515
return ascending ? comparison : -comparison;
1616
}
1717
}

core/src/test/java/cucumber/runtime/HookOrderTest.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,39 @@ public void buildMockWorld() {
3737

3838
@Test
3939
public void before_hooks_execute_in_order() throws Throwable {
40-
List<HookDefinition> hooks = mockHooks(3, Integer.MAX_VALUE, 1);
40+
List<HookDefinition> hooks = mockHooks(3, Integer.MAX_VALUE, 1, -1, 0, 10000, Integer.MIN_VALUE);
4141
for (HookDefinition hook : hooks) {
4242
glue.addBeforeHook(hook);
4343
}
4444

4545
runtime.runBeforeHooks(mock(Reporter.class), new HashSet<Tag>());
4646

4747
InOrder inOrder = inOrder(hooks.toArray());
48+
inOrder.verify(hooks.get(6)).execute(Matchers.<Scenario>any());
49+
inOrder.verify(hooks.get(3)).execute(Matchers.<Scenario>any());
50+
inOrder.verify(hooks.get(4)).execute(Matchers.<Scenario>any());
4851
inOrder.verify(hooks.get(2)).execute(Matchers.<Scenario>any());
4952
inOrder.verify(hooks.get(0)).execute(Matchers.<Scenario>any());
53+
inOrder.verify(hooks.get(5)).execute(Matchers.<Scenario>any());
5054
inOrder.verify(hooks.get(1)).execute(Matchers.<Scenario>any());
5155
}
5256

5357
@Test
5458
public void after_hooks_execute_in_reverse_order() throws Throwable {
55-
List<HookDefinition> hooks = mockHooks(2, Integer.MAX_VALUE, 4);
59+
List<HookDefinition> hooks = mockHooks(Integer.MIN_VALUE, 2, Integer.MAX_VALUE, 4, -1, 0, 10000);
5660
for (HookDefinition hook : hooks) {
5761
glue.addAfterHook(hook);
5862
}
5963

6064
runtime.runAfterHooks(mock(Reporter.class), new HashSet<Tag>());
6165

6266
InOrder inOrder = inOrder(hooks.toArray());
63-
inOrder.verify(hooks.get(1)).execute(Matchers.<Scenario>any());
6467
inOrder.verify(hooks.get(2)).execute(Matchers.<Scenario>any());
68+
inOrder.verify(hooks.get(6)).execute(Matchers.<Scenario>any());
69+
inOrder.verify(hooks.get(3)).execute(Matchers.<Scenario>any());
70+
inOrder.verify(hooks.get(1)).execute(Matchers.<Scenario>any());
71+
inOrder.verify(hooks.get(5)).execute(Matchers.<Scenario>any());
72+
inOrder.verify(hooks.get(4)).execute(Matchers.<Scenario>any());
6573
inOrder.verify(hooks.get(0)).execute(Matchers.<Scenario>any());
6674
}
6775

0 commit comments

Comments
 (0)