Skip to content

Commit 4c3b538

Browse files
committed
upgrade all the libs. Upgrading Maven and Gradle enables built-in JUnit 5 support.
* JUnit 5.5.2 * Hamcrest 2.2 * AssertJ 3.11.1 * Gradle 6.0.1 * Maven Compiler plugin 3.8.1 * Maven Surefire plugin 2.22.2 (cherry picked from commit 30d71ef)
1 parent 3d0bdce commit 4c3b538

File tree

8 files changed

+93
-90
lines changed

8 files changed

+93
-90
lines changed

java-junit5/build.gradle

+21-31
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,39 @@
11
// Run JUnit 5 with Gradle
2-
// See https://github.com/junit-team/junit5-samples/blob/r5.0.0/junit5-gradle-consumer/build.gradle
3-
4-
buildscript {
5-
repositories {
6-
mavenLocal()
7-
mavenCentral()
8-
}
9-
dependencies {
10-
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
11-
}
2+
// See https://github.com/junit-team/junit5-samples/blob/master/junit5-jupiter-starter-gradle
3+
4+
plugins {
5+
id 'java'
6+
id 'eclipse' // optional (to generate Eclipse project files)
7+
id 'idea' // optional (to generate IntelliJ IDEA project files)
128
}
139

1410
group = "org.codecop"
1511
version = '1.0-SNAPSHOT'
1612

17-
apply plugin: 'java'
18-
apply plugin: 'org.junit.platform.gradle.plugin'
19-
2013
repositories {
21-
mavenLocal()
2214
mavenCentral()
2315
}
2416

25-
sourceCompatibility = 1.8
26-
targetCompatibility = 1.8
27-
2817
dependencies {
2918
// setup JUnit 5
30-
testCompile "org.junit.jupiter:junit-jupiter-api:5.0.0"
31-
testCompile "org.junit.jupiter:junit-jupiter-params:5.0.0"
19+
testImplementation('org.junit.jupiter:junit-jupiter:5.5.2')
20+
3221
// add different/alternative assertion libraries
33-
testCompile "org.hamcrest:hamcrest-library:1.3"
34-
testCompile "org.assertj:assertj-core:3.8.0"
22+
testImplementation "org.hamcrest:hamcrest-library:2.2"
23+
testImplementation "org.assertj:assertj-core:3.11.1"
24+
}
3525

36-
// API and engine are separated
37-
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.0.0"
26+
java {
27+
sourceCompatibility = JavaVersion.VERSION_1_8
28+
}
3829

39-
// Only needed to run tests in an (IntelliJ) IDE(A) that bundles an older version
40-
// testRuntime "org.junit.platform:junit-platform-launcher:1.0.0"
30+
tasks.withType(JavaCompile) {
31+
options.encoding = "UTF-8"
4132
}
4233

43-
junitPlatform {
44-
filters {
45-
engines {
46-
include 'junit-jupiter'
47-
}
48-
}
34+
test {
35+
useJUnitPlatform()
36+
testLogging {
37+
events "skipped", "failed"
38+
}
4939
}
5.03 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Mon Dec 05 07:21:40 CET 2016
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip

java-junit5/gradlew

+42-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
2+
3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
218

319
##############################################################################
420
##
@@ -28,16 +44,16 @@ APP_NAME="Gradle"
2844
APP_BASE_NAME=`basename "$0"`
2945

3046
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31-
DEFAULT_JVM_OPTS=""
47+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
3248

3349
# Use the maximum available, or set MAX_FD != -1 to use that value.
3450
MAX_FD="maximum"
3551

36-
warn ( ) {
52+
warn () {
3753
echo "$*"
3854
}
3955

40-
die ( ) {
56+
die () {
4157
echo
4258
echo "$*"
4359
echo
@@ -109,8 +125,8 @@ if $darwin; then
109125
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110126
fi
111127

112-
# For Cygwin, switch paths to Windows format before running java
113-
if $cygwin ; then
128+
# For Cygwin or MSYS, switch paths to Windows format before running java
129+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
114130
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115131
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116132
JAVACMD=`cygpath --unix "$JAVACMD"`
@@ -138,27 +154,30 @@ if $cygwin ; then
138154
else
139155
eval `echo args$i`="\"$arg\""
140156
fi
141-
i=$((i+1))
157+
i=`expr $i + 1`
142158
done
143159
case $i in
144-
(0) set -- ;;
145-
(1) set -- "$args0" ;;
146-
(2) set -- "$args0" "$args1" ;;
147-
(3) set -- "$args0" "$args1" "$args2" ;;
148-
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149-
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150-
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151-
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152-
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153-
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
160+
0) set -- ;;
161+
1) set -- "$args0" ;;
162+
2) set -- "$args0" "$args1" ;;
163+
3) set -- "$args0" "$args1" "$args2" ;;
164+
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165+
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166+
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167+
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168+
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169+
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154170
esac
155171
fi
156172

157-
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158-
function splitJvmOpts() {
159-
JVM_OPTS=("$@")
173+
# Escape application args
174+
save () {
175+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176+
echo " "
160177
}
161-
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162-
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
178+
APP_ARGS=`save "$@"`
163179

164-
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
180+
# Collect all arguments for the java command, following the shell quoting and substitution rules
181+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182+
183+
exec "$JAVACMD" "$@"

java-junit5/gradlew.bat

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem https://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
117
@if "%DEBUG%" == "" @echo off
218
@rem ##########################################################################
319
@rem
@@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
1430
set APP_HOME=%DIRNAME%
1531

1632
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17-
set DEFAULT_JVM_OPTS=
33+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
1834

1935
@rem Find java.exe
2036
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -49,7 +65,6 @@ goto fail
4965
@rem Get command-line arguments, handling Windows variants
5066

5167
if not "%OS%" == "Windows_NT" goto win9xME_args
52-
if "%@eval[2+2]" == "4" goto 4NT_args
5368

5469
:win9xME_args
5570
@rem Slurp the command line arguments.
@@ -60,11 +75,6 @@ set _SKIP=2
6075
if "x%~1" == "x" goto execute
6176

6277
set CMD_LINE_ARGS=%*
63-
goto execute
64-
65-
:4NT_args
66-
@rem Get arguments from the 4NT Shell from JP Software
67-
set CMD_LINE_ARGS=%$
6878

6979
:execute
7080
@rem Setup the command line

java-junit5/mvnw

100644100755
File mode changed.

java-junit5/pom.xml

+11-26
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
44

55
<!-- Run JUnit 5 with Maven -->
6-
<!-- See https://github.com/junit-team/junit5-samples/blob/r5.0.0/junit5-maven-consumer/pom.xml -->
6+
<!-- See https://github.com/junit-team/junit5-samples/blob/master/junit5-jupiter-starter-maven/pom.xml -->
77

88
<modelVersion>4.0.0</modelVersion>
99
<groupId>org.codecop</groupId>
@@ -19,56 +19,41 @@
1919
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2020
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2121
<maven.compiler.source>1.8</maven.compiler.source>
22-
<maven.compiler.target>1.8</maven.compiler.target>
22+
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
2323
</properties>
2424

2525
<dependencies>
2626
<!-- setup JUnit 5 -->
2727
<dependency>
2828
<groupId>org.junit.jupiter</groupId>
29-
<artifactId>junit-jupiter-api</artifactId>
30-
<version>5.0.0</version>
31-
<scope>test</scope>
32-
</dependency>
33-
<dependency>
34-
<groupId>org.junit.jupiter</groupId>
35-
<artifactId>junit-jupiter-params</artifactId>
36-
<version>5.0.0</version>
29+
<artifactId>junit-jupiter</artifactId>
30+
<version>5.5.2</version>
3731
<scope>test</scope>
3832
</dependency>
3933
<!-- add different/alternative assertion libraries -->
4034
<dependency>
4135
<groupId>org.hamcrest</groupId>
4236
<artifactId>hamcrest-library</artifactId>
43-
<version>1.3</version>
37+
<version>2.2</version>
4438
<scope>test</scope>
4539
</dependency>
4640
<dependency>
4741
<groupId>org.assertj</groupId>
4842
<artifactId>assertj-core</artifactId>
49-
<version>3.8.0</version>
43+
<version>3.11.1</version>
5044
<scope>test</scope>
5145
</dependency>
5246
</dependencies>
5347

5448
<build>
5549
<plugins>
50+
<plugin>
51+
<artifactId>maven-compiler-plugin</artifactId>
52+
<version>3.8.1</version>
53+
</plugin>
5654
<plugin>
5755
<artifactId>maven-surefire-plugin</artifactId>
58-
<version>2.19.1</version>
59-
<dependencies>
60-
<dependency>
61-
<groupId>org.junit.platform</groupId>
62-
<artifactId>junit-platform-surefire-provider</artifactId>
63-
<version>1.0.0</version>
64-
</dependency>
65-
<!-- API and engine are separated -->
66-
<dependency>
67-
<groupId>org.junit.jupiter</groupId>
68-
<artifactId>junit-jupiter-engine</artifactId>
69-
<version>5.0.0</version>
70-
</dependency>
71-
</dependencies>
56+
<version>2.22.2</version>
7257
</plugin>
7358
</plugins>
7459
</build>

java-junit5/src/test/java/org/codecop/Session2c_WordCounterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static org.hamcrest.MatcherAssert.assertThat;
44
import static org.hamcrest.Matchers.equalTo;
5-
import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
5+
import static org.hamcrest.collection.ArrayMatching.hasItemInArray;
66
import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize;
77
import static org.hamcrest.core.IsNot.not;
88
import static org.junit.jupiter.api.Assertions.assertEquals;

0 commit comments

Comments
 (0)