Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit a96b235

Browse files
slu-itAxel Schüssler
authored andcommitted
Migrated tests of webtester-support-assertj3 to JUnit 5
1 parent 6acf8f8 commit a96b235

File tree

16 files changed

+781
-556
lines changed

16 files changed

+781
-556
lines changed

pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
<!-- dependency versions -->
5757

5858
<version.junit>4.12</version.junit>
59+
<version.junit5>5.0.0-M2</version.junit5>
60+
<version.junit5.platform>1.0.0-M2</version.junit5.platform>
5961
<version.hamcrest>1.3</version.hamcrest>
6062
<version.assertj>3.4.1</version.assertj>
6163
<version.mockito>2.2.1</version.mockito>
@@ -203,6 +205,23 @@
203205
<artifactId>junit</artifactId>
204206
<version>${version.junit}</version>
205207
</dependency>
208+
209+
<dependency>
210+
<groupId>org.junit.jupiter</groupId>
211+
<artifactId>junit-jupiter-api</artifactId>
212+
<version>${version.junit5}</version>
213+
</dependency>
214+
<dependency>
215+
<groupId>org.junit.jupiter</groupId>
216+
<artifactId>junit-jupiter-engine</artifactId>
217+
<version>${version.junit5}</version>
218+
</dependency>
219+
<dependency>
220+
<groupId>org.junit.platform</groupId>
221+
<artifactId>junit-platform-surefire-provider</artifactId>
222+
<version>${version.junit5.platform}</version>
223+
</dependency>
224+
206225
<dependency>
207226
<groupId>org.hamcrest</groupId>
208227
<artifactId>hamcrest-all</artifactId>

webtester-support-assertj3/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,47 @@
4545
<type>test-jar</type>
4646
<scope>test</scope>
4747
</dependency>
48+
<dependency>
49+
<groupId>org.junit.jupiter</groupId>
50+
<artifactId>junit-jupiter-api</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.junit.jupiter</groupId>
55+
<artifactId>junit-jupiter-engine</artifactId>
56+
<scope>test</scope>
57+
</dependency>
4858
</dependencies>
4959

60+
<build>
61+
<plugins>
62+
<plugin>
63+
<!-- Currently only the surefire plugin can execute JUnit 5 tests. -->
64+
<!-- Therefore it needs to be reconfigured to execute all tests regardless of their type. -->
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-surefire-plugin</artifactId>
67+
<configuration>
68+
<includes>
69+
<include>**/*Test</include>
70+
</includes>
71+
</configuration>
72+
<dependencies>
73+
<dependency>
74+
<groupId>org.junit.platform</groupId>
75+
<artifactId>junit-platform-surefire-provider</artifactId>
76+
<version>${version.junit5.platform}</version>
77+
</dependency>
78+
</dependencies>
79+
</plugin>
80+
<plugin>
81+
<!-- Currently only the failsafe plugin can't execute JUnit 5 tests. -->
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-failsafe-plugin</artifactId>
84+
<configuration>
85+
<skip>true</skip>
86+
</configuration>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
5091
</project>

webtester-support-assertj3/src/main/java/info/novatec/testit/webtester/support/assertj/WebTesterAssertions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @see GenericTextFieldAssert
3030
* @since 2.0
3131
*/
32-
public final class WebTesterAssertions extends Assertions {
32+
public final class WebTesterAssertions {
3333

3434
/**
3535
* Creates a new {@link PageFragmentAssert} for the given {@link PageFragment}.
@@ -79,6 +79,7 @@ public static ButtonAssert assertThat(Button actual) {
7979
* @see GenericSelectAssert
8080
* @since 2.0
8181
*/
82+
@SuppressWarnings("unchecked")
8283
public static GenericSelectAssert assertThat(GenericSelect actual) {
8384
return new GenericSelectAssert(actual, GenericSelectAssert.class);
8485
}

webtester-support-assertj3/src/main/java/info/novatec/testit/webtester/support/assertj/assertions/AbstractWebTesterAssert.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,4 @@ public A and() {
3030
return ( A ) this;
3131
}
3232

33-
protected final void failOnActualBeingNull() {
34-
if (actual == null) {
35-
failWithMessage("actual is null");
36-
}
37-
}
38-
3933
}

webtester-support-assertj3/src/main/java/info/novatec/testit/webtester/support/assertj/assertions/pagefragments/AbstractPageFragmentAssert.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public abstract class AbstractPageFragmentAssert<A extends AbstractPageFragmentA
2525

2626
protected AbstractPageFragmentAssert(B actual, Class<A> selfType) {
2727
super(actual, selfType);
28-
failOnActualBeingNull();
2928
}
3029

3130
/* tag name */

webtester-support-assertj3/src/main/java/info/novatec/testit/webtester/support/assertj/assertions/pagefragments/MultiSelectAssert.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public MultiSelectAssert(MultiSelect actual) {
3131
* @since 2.0
3232
*/
3333
public MultiSelectAssert hasSelectionWithTexts(String... texts) {
34-
String errorMessage = "Expected select's selection texts to be <%s>, but were <%s>.";
34+
String errorMessage = "Expected select's selected texts to be <%s>, but they were <%s>.";
3535
List<String> actualTexts = actual.getSelectionTexts();
3636
assertThat(actualTexts).overridingErrorMessage(errorMessage, Arrays.toString(texts), actualTexts)
3737
.containsExactly(texts);
@@ -47,7 +47,7 @@ public MultiSelectAssert hasSelectionWithTexts(String... texts) {
4747
* @since 2.0
4848
*/
4949
public MultiSelectAssert hasSelectionWithValues(String... values) {
50-
String errorMessage = "Expected select's selection values to be <%s>, but were <%s>.";
50+
String errorMessage = "Expected select's selected values to be <%s>, but they were <%s>.";
5151
List<String> actualValues = actual.getSelectionValues();
5252
assertThat(actualValues).overridingErrorMessage(errorMessage, Arrays.toString(values), actualValues)
5353
.containsExactly(values);
@@ -63,7 +63,7 @@ public MultiSelectAssert hasSelectionWithValues(String... values) {
6363
* @since 2.0
6464
*/
6565
public MultiSelectAssert hasSelectionWithIndices(Integer... indices) {
66-
String errorMessage = "Expected select's selection indices to be <%s>, but were <%s>.";
66+
String errorMessage = "Expected select's selected indices to be <%s>, but they were <%s>.";
6767
List<Integer> actualIndices = actual.getSelectionIndices();
6868
assertThat(actualIndices).overridingErrorMessage(errorMessage, Arrays.toString(indices), actualIndices)
6969
.containsExactly(indices);

webtester-support-assertj3/src/test/java/info/novatec/testit/webtester/support/assertj/assertions/AbstractWebTesterAssertTest.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
package info.novatec.testit.webtester.support.assertj.assertions;
22

33
import org.assertj.core.api.Assertions;
4-
import org.junit.Test;
5-
import org.junit.experimental.runners.Enclosed;
6-
import org.junit.runner.RunWith;
4+
import org.junit.jupiter.api.Nested;
5+
import org.junit.jupiter.api.Test;
76

87

9-
@RunWith(Enclosed.class)
108
public class AbstractWebTesterAssertTest {
119

12-
public static class FailOnActualBeingNull {
10+
@Nested
11+
class AssertionsProvideFluentApi {
1312

1413
@Test
15-
public void nonNullActualPasses() {
16-
new TestAssert("foo").failOnActualBeingNull();
17-
}
18-
19-
@Test(expected = AssertionError.class)
20-
public void nullActualThrowsError() {
21-
new TestAssert(null).failOnActualBeingNull();
22-
}
23-
24-
}
25-
26-
public static class And {
27-
28-
@Test
29-
public void invocationReturnsSameAssertionInstance() {
14+
public void and() {
3015
TestAssert original = new TestAssert("foo");
3116
TestAssert returned = original.and();
3217
Assertions.assertThat(returned).isSameAs(original);

webtester-support-assertj3/src/test/java/info/novatec/testit/webtester/support/assertj/assertions/pagefragments/AbstractPageFragmentAssertTest.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

webtester-support-assertj3/src/test/java/info/novatec/testit/webtester/support/assertj/assertions/pagefragments/ButtonAssertTest.java

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,77 @@
11
package info.novatec.testit.webtester.support.assertj.assertions.pagefragments;
22

33
import static info.novatec.testit.webtester.support.assertj.WebTesterAssertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThat;
5+
import static org.junit.jupiter.api.Assertions.expectThrows;
46
import static org.mockito.Mockito.doReturn;
57
import static org.mockito.Mockito.mock;
68

7-
import org.junit.Test;
8-
import org.junit.experimental.runners.Enclosed;
9-
import org.junit.runner.RunWith;
9+
import org.junit.jupiter.api.Nested;
10+
import org.junit.jupiter.api.Test;
1011

1112
import info.novatec.testit.webtester.pagefragments.Button;
1213

1314

14-
@RunWith(Enclosed.class)
1515
public class ButtonAssertTest {
1616

17-
public static class HasLabel {
17+
@Nested
18+
class HasLabelAssertion {
1819

1920
@Test
20-
public void havingLabelPasses() {
21-
assertThat(buttonWithLabel("foo")).hasLabel("foo");
22-
}
23-
24-
@Test(expected = AssertionError.class)
25-
public void notHavingLabelFails() {
26-
assertThat(buttonWithLabel("bar")).hasLabel("foo");
21+
void passesForMatchingLabels() {
22+
Button fooButton = buttonWithLabel("foo");
23+
assertThat(fooButton).hasLabel("foo");
2724
}
2825

2926
@Test
30-
public void invocationReturnsSameAssertionInstance() {
31-
ButtonAssert original = assertThat(buttonWithLabel("foo"));
32-
ButtonAssert returned = original.hasLabel("foo");
33-
assertThat(returned).isSameAs(original);
27+
void failsForDifferentLabels() {
28+
Button barButton = buttonWithLabel("bar");
29+
assertThat(expectThrows(AssertionError.class, () -> {
30+
assertThat(barButton).hasLabel("foo");
31+
})).hasMessage("Expected buttons's label to be <foo>, but was <bar>.");
3432
}
3533

3634
}
3735

38-
public static class NotHasLabel {
36+
@Nested
37+
class HasNotLabelAssertion {
38+
39+
@Test
40+
void passesForDifferentLabels() {
41+
Button barButton = buttonWithLabel("bar");
42+
assertThat(barButton).hasNotLabel("foo");
43+
}
3944

4045
@Test
41-
public void notHavingLabelPasses() {
42-
assertThat(buttonWithLabel("bar")).hasNotLabel("foo");
46+
void failsForMatchingLabels() {
47+
Button fooButton = buttonWithLabel("foo");
48+
assertThat(expectThrows(AssertionError.class, () -> {
49+
assertThat(fooButton).hasNotLabel("foo");
50+
})).hasMessage("Expected buttons's label not to be <foo>, but it was.");
4351
}
4452

45-
@Test(expected = AssertionError.class)
46-
public void havingLabelFails() {
47-
assertThat(buttonWithLabel("foo")).hasNotLabel("foo");
53+
}
54+
55+
@Nested
56+
class AssertionsProvideFluentApi {
57+
58+
@Test
59+
void hasLabel() {
60+
ButtonAssert original = assertThat(buttonWithLabel("foo"));
61+
ButtonAssert returned = original.hasLabel("foo");
62+
assertThat(returned).isSameAs(original);
4863
}
4964

5065
@Test
51-
public void invocationReturnsSameAssertionInstance() {
66+
void hasNotLabel() {
5267
ButtonAssert original = assertThat(buttonWithLabel("bar"));
5368
ButtonAssert returned = original.hasNotLabel("foo");
5469
assertThat(returned).isSameAs(original);
5570
}
5671

5772
}
5873

59-
private static Button buttonWithLabel(String label) {
74+
Button buttonWithLabel(String label) {
6075
Button button = mock(Button.class);
6176
doReturn(label).when(button).getLabel();
6277
return button;

0 commit comments

Comments
 (0)