Skip to content

Commit 23cc96c

Browse files
committed
[Cdi2] Use Junit 5
1 parent 95dddd5 commit 23cc96c

File tree

9 files changed

+32
-36
lines changed

9 files changed

+32
-36
lines changed

cdi2/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</dependency>
6060
<dependency>
6161
<groupId>io.cucumber</groupId>
62-
<artifactId>cucumber-junit</artifactId>
62+
<artifactId>cucumber-junit-platform-engine</artifactId>
6363
<scope>test</scope>
6464
</dependency>
6565
<dependency>
@@ -68,8 +68,8 @@
6868
<scope>test</scope>
6969
</dependency>
7070
<dependency>
71-
<groupId>org.junit.vintage</groupId>
72-
<artifactId>junit-vintage-engine</artifactId>
71+
<groupId>org.hamcrest</groupId>
72+
<artifactId>hamcrest-core</artifactId>
7373
<scope>test</scope>
7474
</dependency>
7575
</dependencies>

cdi2/src/test/java/io/cucumber/cdi2/ApplicationScopedBean.java

-8
This file was deleted.

cdi2/src/test/java/io/cucumber/cdi2/Cdi2FactoryTest.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import io.cucumber.core.backend.ObjectFactory;
44
import org.junit.jupiter.api.Test;
55

6+
import javax.enterprise.context.ApplicationScoped;
7+
import javax.enterprise.inject.Vetoed;
8+
69
import static org.hamcrest.MatcherAssert.assertThat;
710
import static org.hamcrest.core.Is.is;
811
import static org.hamcrest.core.IsEqual.equalTo;
@@ -15,6 +18,11 @@ class Cdi2FactoryTest {
1518

1619
final ObjectFactory factory = new Cdi2Factory();
1720

21+
@Vetoed
22+
static class VetoedBean {
23+
24+
}
25+
1826
@Test
1927
void shouldCreateNewInstancesForEachScenario() {
2028
factory.addClass(VetoedBean.class);
@@ -34,9 +42,14 @@ void shouldCreateNewInstancesForEachScenario() {
3442
// VetoedBean makes it possible to compare the object outside the
3543
// scenario/application scope
3644
assertAll(
37-
() -> assertThat(a1, is(notNullValue())),
38-
() -> assertThat(a1, is(not(equalTo(b1)))),
39-
() -> assertThat(b1, is(not(equalTo(a1)))));
45+
() -> assertThat(a1, is(notNullValue())),
46+
() -> assertThat(a1, is(not(equalTo(b1)))),
47+
() -> assertThat(b1, is(not(equalTo(a1)))));
48+
}
49+
50+
@ApplicationScoped
51+
static class ApplicationScopedBean {
52+
4053
}
4154

4255
@Test
@@ -45,9 +58,9 @@ void shouldCreateApplicationScopedInstance() {
4558
factory.start();
4659
ApplicationScopedBean cdiStep = factory.getInstance(ApplicationScopedBean.class);
4760
assertAll(
48-
// assert that it is is a CDI proxy
49-
() -> assertThat(cdiStep.getClass(), not(is(ApplicationScopedBean.class))),
50-
() -> assertThat(cdiStep.getClass().getSuperclass(), is(ApplicationScopedBean.class)));
61+
// assert that it is is a CDI proxy
62+
() -> assertThat(cdiStep.getClass(), not(is(ApplicationScopedBean.class))),
63+
() -> assertThat(cdiStep.getClass().getSuperclass(), is(ApplicationScopedBean.class)));
5164
factory.stop();
5265
}
5366

@@ -56,7 +69,13 @@ void shouldCreateUnmanagedInstance() {
5669
factory.addClass(UnmanagedBean.class);
5770
factory.start();
5871
assertNotNull(factory.getInstance(UnmanagedBean.class));
72+
UnmanagedBean cdiStep = factory.getInstance(UnmanagedBean.class);
73+
assertThat(cdiStep.getClass(), is(UnmanagedBean.class));
5974
factory.stop();
6075
}
6176

77+
static class UnmanagedBean {
78+
79+
}
80+
6281
}

cdi2/src/test/java/io/cucumber/cdi2/UnmanagedBean.java

-5
This file was deleted.

cdi2/src/test/java/io/cucumber/cdi2/VetoedBean.java

-7
This file was deleted.

cdi2/src/test/java/io/cucumber/cdi2/Belly.java renamed to cdi2/src/test/java/io/cucumber/cdi2/example/Belly.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.cucumber.cdi2;
1+
package io.cucumber.cdi2.example;
22

33
import javax.enterprise.context.ApplicationScoped;
44

cdi2/src/test/java/io/cucumber/cdi2/example/BellyStepDefinitions.java

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.cucumber.cdi2.example;
22

3-
import io.cucumber.cdi2.Belly;
43
import io.cucumber.java.en.Given;
54
import io.cucumber.java.en.Then;
65

@@ -28,5 +27,4 @@ public void checkCukes(int n) {
2827
assertEquals(n, belly.getCukes());
2928
}
3029

31-
3230
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package io.cucumber.cdi2.example;
22

3-
import io.cucumber.junit.Cucumber;
4-
import org.junit.runner.RunWith;
3+
import io.cucumber.junit.platform.engine.Cucumber;
54

6-
@RunWith(Cucumber.class)
5+
@Cucumber
76
public class RunCucumberTest {
87

98
}

cdi2/src/test/resources/META-INF/beans.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<!-- Exclude the class to force it to be loaded as an unmanaged dependency -->
66
<scan>
77
<exclude
8-
name="io.cucumber.cdi2.UnmanagedBean" />
8+
name="io.cucumber.cdi2.Cdi2FactoryTest$UnmanagedBean" />
99
</scan>
1010
</beans>

0 commit comments

Comments
 (0)