Add junit-mockito module: 30 runnable JUnit 6.1.3 / Mockito 5.24.0 interview answers
One test per question, each writing and asserting its own transcript under output/. Covers lifecycle, extensions, parameterized and dynamic tests, mocks vs spies, verification, strict stubs, static and constructor mocking, and flaky tests. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CifR2BE7PBvRy5hT8TS9oz
This commit is contained in:
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# Q2: compares the real junit-jupiter-api 5.14.4 and 6.1.3 jars. Writes output/q02-jar-comparison.txt.
|
||||
# Needs JDK (javap, unzip) and Maven. Downloads both jars into the local Maven repository.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
REPO="${HOME}/.m2/repository"
|
||||
OUT=output/q02-jar-comparison.txt
|
||||
TMP="$(mktemp -d)"
|
||||
: > "$OUT"
|
||||
for v in 5.14.4 6.1.3; do
|
||||
mvn -B -q dependency:get -Dartifact="org.junit.jupiter:junit-jupiter-api:$v" >/dev/null
|
||||
jar="$REPO/org/junit/jupiter/junit-jupiter-api/$v/junit-jupiter-api-$v.jar"
|
||||
mkdir -p "$TMP/$v"
|
||||
unzip -q -o "$jar" 'org/junit/jupiter/api/Test.class' -d "$TMP/$v"
|
||||
major=$(javap -v -cp "$TMP/$v" org.junit.jupiter.api.Test | grep 'major version' | awk '{print $3}')
|
||||
alpha=$(unzip -l "$jar" | grep -c 'MethodOrderer\$Alphanumeric' || true)
|
||||
echo "junit-jupiter-api $v : class-file major version $major (Java $((major-44))), MethodOrderer\$Alphanumeric entries in jar: $alpha" | tee -a "$OUT"
|
||||
done
|
||||
rm -rf "$TMP"
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
# Q27: runs one Mockito test WITHOUT the -javaagent flag and keeps only the JVM's own warning lines.
|
||||
# Writes output/q27-no-agent-warning.txt. Compare with the normal run, which prints none of these.
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
OUT=output/q27-no-agent-warning.txt
|
||||
mvn -B test -Dtest='D_MockitoCoreTest#q18_mockVersusSpy' \
|
||||
-Dmockito.agentArg=-Dlab.no.agent=true 2>&1 \
|
||||
| grep -E '^(WARNING|Mockito is currently self-attaching)|dynamic(ally)? load|byte-buddy|-javaagent|EnableDynamicAgentLoading' \
|
||||
| grep -v -E 'Unsafe|HiddenClassDefiner|guice' \
|
||||
| sed -E "s#/[^ ]*/\.m2/repository#~/.m2/repository#g" > "$OUT"
|
||||
cat "$OUT"
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file in output/ (one per interview question).
|
||||
# Requires JDK 25 and Maven. The first run must be online so Maven can fetch plugins and dependencies.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
rm -f output/q*.txt
|
||||
mvn -B -q test
|
||||
./scripts/compare-5-vs-6.sh
|
||||
./scripts/no-agent.sh
|
||||
echo "done: $(ls output | wc -l) files in output/"
|
||||
Reference in New Issue
Block a user