#!/usr/bin/env bash # Writes output/09-junit5-vs-6.txt (what differs for extension authors between 5.14.4 and 6.1.3, by javap and javac) # and output/10-composed-annotations.txt (which popular annotations are @ExtendWith under the hood). # Needs JDK 17+, Maven and network access to Maven Central. set -euo pipefail # the sandbox sets JAVA_TOOL_OPTIONS for its proxy; javap/javac would echo a banner into the evidence files javap() { env -u JAVA_TOOL_OPTIONS javap "$@"; } javac() { env -u JAVA_TOOL_OPTIONS javac "$@"; } cd "$(dirname "$0")/.." OUT=output; mkdir -p "$OUT" target/probe V5=5.14.4; V6=6.1.3 MC=https://repo1.maven.org/maven2 fetch() { # group-path artifact version -> target/probe/-.jar local f="target/probe/$2-$3.jar" [ -s "$f" ] || curl -sfL --retry 5 --retry-delay 3 -o "$f" "$MC/$1/$2/$3/$2-$3.jar" echo "$f" } API5=$(fetch org/junit/jupiter junit-jupiter-api $V5) API6=$(fetch org/junit/jupiter junit-jupiter-api $V6) mvn -q -B dependency:build-classpath -Dmdep.outputFile=target/probe/cp6.txt >/dev/null mvn -q -B -Pjunit5 dependency:build-classpath -Dmdep.outputFile=target/probe/cp5.txt >/dev/null { echo "== Class-file version of ExtendWith.class (major 52 = Java 8, 61 = Java 17)" for v in $V5 $V6; do unzip -p target/probe/junit-jupiter-api-$v.jar org/junit/jupiter/api/extension/ExtendWith.class > target/probe/ExtendWith-$v.class echo "junit-jupiter-api $v: $(javap -v target/probe/ExtendWith-$v.class | grep 'major version' | sed 's/^ *//')" done echo echo "== ExtensionContext.Store: getOrComputeIfAbsent and computeIfAbsent" for v in $V5 $V6; do echo "-- junit-jupiter-api $v" javap -cp target/probe/junit-jupiter-api-$v.jar 'org.junit.jupiter.api.extension.ExtensionContext$Store' | grep -E 'ComputeIfAbsent|computeIfAbsent' | sed 's/^ *//' || true done echo echo "== InvocationInterceptor.interceptDynamicTest" for v in $V5 $V6; do echo "-- junit-jupiter-api $v" javap -cp target/probe/junit-jupiter-api-$v.jar org.junit.jupiter.api.extension.InvocationInterceptor | grep interceptDynamicTest | sed -e 's/^ *//' -e 's/org.junit.jupiter.api.extension.//g' -e 's/ throws java.lang.Throwable//' || true done echo echo "== A Store call compiled with -Xlint:deprecation (StoreProbe.java)" mkdir -p target/probe/src cat > target/probe/src/StoreProbe.java <<'JAVA' import org.junit.jupiter.api.extension.ExtensionContext; class StoreProbe { Object old(ExtensionContext.Store store) { return store.getOrComputeIfAbsent("k", k -> "v"); } } JAVA for v in 5 6; do echo "-- against JUnit $([ $v = 5 ] && echo $V5 || echo $V6)" javac --release 17 -Xlint:deprecation -d target/probe/classes$v -cp "$(cat target/probe/cp$v.txt)" target/probe/src/StoreProbe.java 2>&1 | grep -v 'JAVA_TOOL_OPTIONS' | sed "s|target/probe/src/||" || true echo " javac exit status: ${PIPESTATUS[0]}" done cat > target/probe/src/ComputeProbe.java <<'JAVA' import org.junit.jupiter.api.extension.ExtensionContext; class ComputeProbe { Object replacement(ExtensionContext.Store store) { return store.computeIfAbsent("k", k -> "v"); } } JAVA echo "-- the 6.x replacement computeIfAbsent (ComputeProbe.java)" for v in 5 6; do set +e res=$(javac --release 17 -Xlint:deprecation -d target/probe/classes$v -cp "$(cat target/probe/cp$v.txt)" target/probe/src/ComputeProbe.java 2>&1 | grep -v 'JAVA_TOOL_OPTIONS') rc=$? set -e javac --release 17 -d target/probe/classes$v -cp "$(cat target/probe/cp$v.txt)" target/probe/src/ComputeProbe.java >/dev/null 2>&1 && st=0 || st=$? echo " against JUnit $([ $v = 5 ] && echo $V5 || echo $V6): javac exit status $st" echo "$res" | sed 's/^/ /' | grep -v '^ *$' | head -3 || true done echo echo "== The module's extensions (src/test/java/.../ext) compiled unchanged with --release 17" for v in 5 6; do rm -rf target/probe/ext$v javac --release 17 -d target/probe/ext$v -cp "$(cat target/probe/cp$v.txt)" src/test/java/com/ankurm/tutorials/junit/extendwith/ext/*.java 2>&1 | grep -v 'JAVA_TOOL_OPTIONS' || true echo " JUnit $([ $v = 5 ] && echo $V5 || echo $V6): $(ls target/probe/ext$v/com/ankurm/tutorials/junit/extendwith/ext/*.class | wc -l) class files, javac exit status ${PIPESTATUS[0]}" done } > "$OUT/09-junit5-vs-6.txt" 2>&1 # ---- composed annotations MOCKITO_V=5.24.0; SPRING_V=7.0.10 MJ=$(fetch org/mockito mockito-junit-jupiter $MOCKITO_V) echo "mockito $MOCKITO_V spring-test $SPRING_V" >&2 ST=$(fetch org/springframework spring-test $SPRING_V) SBV=$(curl -sf $MC/org/springframework/boot/spring-boot-test/maven-metadata.xml | tr '<' '\n' | grep -E '^version>4' | sed 's/^version>//' | grep -vE -- '-M|-RC|-SNAPSHOT' | tail -1) SB=$(fetch org/springframework/boot spring-boot-test $SBV) { echo "== Is the annotation itself an @ExtendWith? (javap -v, RuntimeVisibleAnnotations)" show() { # jar class label echo "-- $3 ($(basename "$1"))" javap -v -cp "$1" "$2" 2>/dev/null | grep -E 'Utf8 +L.*(ExtendWith|SpringExtension|MockitoExtension)' | sed 's/^ *#[0-9]* = Utf8 *//' || true } show "$MJ" org.mockito.junit.jupiter.MockitoSettings "@MockitoSettings" show "$ST" org.springframework.test.context.junit.jupiter.SpringJUnitConfig "@SpringJUnitConfig" show "$SB" org.springframework.boot.test.context.SpringBootTest "@SpringBootTest" } > "$OUT/10-composed-annotations.txt" 2>&1 # ---- the Spring snippet of the 2026 article: compiled only, never run SPRING_CP="$ST:$SB:$MJ:$(cat target/probe/cp6.txt):$(fetch org/mockito mockito-core $MOCKITO_V 2>/dev/null || true)" { echo "== src/spring/UserProfileServiceTest.java compiled against spring-test $SPRING_V, spring-boot-test $SBV, mockito-junit-jupiter $MOCKITO_V, JUnit $V6" rm -rf target/probe/spring; set +e javac --release 17 -proc:none -d target/probe/spring -cp "$SPRING_CP" src/spring/UserProfileServiceTest.java 2>&1 echo "javac exit status: $?" set -e echo "(compiled only: running it would need a Spring Boot application class and context)" } > "$OUT/12-spring-snippet-compile.txt" 2>&1 ls "$OUT"