diff --git a/.github/scripts/update-spring-versions.py b/.github/scripts/update-spring-versions.py deleted file mode 100644 index 1578b97..0000000 --- a/.github/scripts/update-spring-versions.py +++ /dev/null @@ -1,67 +0,0 @@ -import json -import re -from collections import defaultdict -from packaging.version import Version -from xml.etree import ElementTree as ET -import urllib.request - -# Configuration -managed_minors = {"3.4"} -boot_java_compatibility = { - "3.4": ["17", "21"] -} -output_path = ".github/spring-versions.json" - -# Step 1: Fetch Spring Boot versions -metadata_url = "https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter/maven-metadata.xml" -with urllib.request.urlopen(metadata_url) as response: - xml_data = response.read() - -root = ET.fromstring(xml_data) -versions = [v.text for v in root.findall(".//version")] - -boot_versions = defaultdict(list) -for v in versions: - if not re.match(r"^\d+\.\d+\.\d+$", v): - continue - minor = ".".join(v.split(".")[:2]) - if minor in managed_minors: - boot_versions[minor].append(Version(v)) - -latest_boot_versions = {minor: str(max(vlist)) for minor, vlist in boot_versions.items()} - -# Step 2: Resolve Spring Framework version -def get_spring_framework_version(boot_version: str) -> str: - pom_url = f"https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter/{boot_version}/spring-boot-starter-{boot_version}.pom" - try: - with urllib.request.urlopen(pom_url) as response: - pom_data = response.read() - pom_root = ET.fromstring(pom_data) - ns = {'m': 'http://maven.apache.org/POM/4.0.0'} - for dep in pom_root.findall(".//m:dependency", ns): - gid = dep.find("m:groupId", ns) - aid = dep.find("m:artifactId", ns) - ver = dep.find("m:version", ns) - if gid is not None and aid is not None and ver is not None: - if gid.text == "org.springframework" and aid.text == "spring-core": - return ver.text - except Exception as e: - print(f"Warning: Failed to fetch framework version for {boot_version}: {e}") - return "unknown" - -# Step 3: Build matrix -matrix_entries = [] -for minor, boot_version in sorted(latest_boot_versions.items()): - framework_version = get_spring_framework_version(boot_version) - for java_version in boot_java_compatibility.get(minor, []): - matrix_entries.append({ - "boot": boot_version, - "framework": framework_version, - "java": str(java_version) - }) - -# Step 4: Save result -with open(output_path, "w") as f: - json.dump({"matrix": matrix_entries}, f, indent=2) - -print(f"Updated {output_path} with {len(matrix_entries)} matrix entries.") diff --git a/.github/spring-versions.json b/.github/spring-versions.json deleted file mode 100644 index cc14e9b..0000000 --- a/.github/spring-versions.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "matrix": [ - { - "boot": "3.4.13", - "framework": "6.2.15", - "java": "17" - }, - { - "boot": "3.4.13", - "framework": "6.2.15", - "java": "21" - } - ] -} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7001910..d0ff56a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,57 +8,18 @@ on: branches: [ "master" ] workflow_dispatch: -jobs: - generate-matrix: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - name: Generate version matrix - steps: - - uses: actions/checkout@v6 - - name: Read matrix from JSON - id: set-matrix - run: | - MATRIX=$(jq -c '.matrix' .github/spring-versions.json) - echo "matrix={\"include\":$MATRIX}" >> $GITHUB_OUTPUT - - regression-tests: - needs: generate-matrix - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }} - name: Test Spring Boot ${{ matrix.boot }} / Java ${{ matrix.java }} - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Setup Java - uses: actions/setup-java@v5 - with: - distribution: temurin - java-version: ${{ matrix.java }} +env: + DEFAULT_JAVA_VERSION: '17' - - name: Run tests and generate reports - run: ./gradlew testAndReport -PspringBootVersion=${{ matrix.boot }} -PspringFrameworkVersion=${{ matrix.framework }} - - - name: Upload Artifact - uses: actions/upload-artifact@v6 - if: always() - with: - name: report-java-${{ matrix.java }}-spring-boot-${{ matrix.boot }} - path: build/reports/** - retention-days: 5 +jobs: test: runs-on: ubuntu-latest strategy: fail-fast: false matrix: - java: [ '17', '21' ] - name: Test Spring Boot latest / Java ${{ matrix.java }} + java: [ '17', '21', '25' ] + name: Test with Java ${{ matrix.java }} steps: - name: Checkout code uses: actions/checkout@v6 @@ -78,13 +39,13 @@ jobs: uses: actions/upload-artifact@v6 if: always() with: - name: report-java-${{ matrix.java }}-spring-boot-latest + name: report-java-${{ matrix.java }} path: build/reports/** retention-days: 5 - name: Run Sonar analysis # Skip Sonar on Dependabot in pull_request runs (no secrets there); handled by a separate job below - if: matrix.java == '17' && github.actor != 'dependabot[bot]' + if: matrix.java == env.DEFAULT_JAVA_VERSION && github.actor != 'dependabot[bot]' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -94,7 +55,7 @@ jobs: sonar-dependabot: name: Sonar (Dependabot PRs) # Only run when the event is pull_request_target and the actor is Dependabot - if: github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]' + if: github.event_name == 'pull_request_target' && github.event.pull_request.user.login == 'dependabot[bot]' runs-on: ubuntu-latest permissions: contents: read @@ -111,7 +72,7 @@ jobs: uses: actions/setup-java@v5 with: distribution: temurin - java-version: '17' + java-version: ${{ env.DEFAULT_JAVA_VERSION }} - name: Build (no tests) run: ./gradlew assemble -x test @@ -133,7 +94,7 @@ jobs: uses: actions/setup-java@v5 with: distribution: temurin - java-version: 17 + java-version: ${{ env.DEFAULT_JAVA_VERSION }} - name: Run build with Gradle Wrapper run: ./gradlew build -x test diff --git a/.github/workflows/update-spring-versions.yml b/.github/workflows/update-spring-versions.yml deleted file mode 100644 index 8d152fe..0000000 --- a/.github/workflows/update-spring-versions.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Update Spring Versions Matrix - -on: - schedule: - - cron: '0 3 1 * *' # Monthly on the 1st at 03:00 UTC - workflow_dispatch: # Allow manual trigger as well - -jobs: - update-matrix: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v6 - - - name: Set up Python - uses: actions/setup-python@v6 - with: - python-version: '3.x' - - - name: Install Python dependencies - run: pip install packaging - - - name: Run update script - run: python .github/scripts/update-spring-versions.py - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v8 - with: - commit-message: "chore: update Spring Boot/Framework testing matrix" - title: "Update Spring Versions Matrix" - body: | - This PR updates the `spring-versions.json` matrix with the latest patch versions of Spring Boot and their corresponding Spring Framework versions for Java 17 and 21. - branch: update/spring-versions-matrix - labels: | - dependencies - spring - author: github-actions[bot] diff --git a/build.gradle b/build.gradle index e6101cf..7d1830d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,25 +1,11 @@ -buildscript { - ext { - springBootVersion = project.hasProperty('springBootVersion') ? project.springBootVersion : '3.5.0' - springVersion = project.hasProperty('springFrameworkVersion') ? project.springFrameworkVersion : '6.2.7' - jacksonVersion = '2.20.1' - retrofitVersion = '3.0.0' - mockitoVersion = '5.21.+' // At least Mockito 5.2.0 is required to Mock final classes - } - dependencies { - classpath 'org.owasp:dependency-check-gradle' - } -} - plugins { id 'java' - id "org.owasp.dependencycheck" version "12.1.9" - id "io.freefair.lombok" version "9.1.0" + id "io.freefair.lombok" version "9.2.0" id "io.github.gradle-nexus.publish-plugin" version "2.0.0" } -group 'ee.bitweb' -version '4.0.5' +group = 'ee.bitweb' +version = '4.0.5' java { sourceCompatibility = '17' } @@ -38,82 +24,83 @@ repositories { dependencies { // https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina - compileOnly group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '10.1.50' + compileOnly 'org.apache.tomcat:tomcat-catalina:10.1.50' // https://mvnrepository.com/artifact/org.springframework/spring-webmvc - compileOnly group: 'org.springframework', name: 'spring-webmvc', version: "${springVersion}" + compileOnly 'org.springframework:spring-webmvc:6.2.7' // https://mvnrepository.com/artifact/org.springframework/spring-tx - compileOnly group: 'org.springframework', name: 'spring-tx', version: "${springVersion}" + compileOnly 'org.springframework:spring-tx:6.2.7' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security - compileOnly group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: "${springBootVersion}" + compileOnly 'org.springframework.boot:spring-boot-starter-security:3.5.0' // https://mvnrepository.com/artifact/org.springframework.amqp/spring-amqp - compileOnly group: 'org.springframework.boot', name: 'spring-boot-starter-amqp', version: "${springBootVersion}" + compileOnly 'org.springframework.boot:spring-boot-starter-amqp:3.5.0' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-configuration-processor - annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: "${springBootVersion}" + annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor:3.5.0' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator - compileOnly group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: "${springBootVersion}" + compileOnly 'org.springframework.boot:spring-boot-starter-actuator:3.5.0' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure - compileOnly group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: "${springBootVersion}" + compileOnly 'org.springframework.boot:spring-boot-autoconfigure:3.5.0' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation - compileOnly group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: "${springBootVersion}" + compileOnly 'org.springframework.boot:spring-boot-starter-validation:3.5.0' // https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 - compileOnly group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: "${jacksonVersion}" + compileOnly 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.20.1' // https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api - compileOnly group: 'jakarta.validation', name: 'jakarta.validation-api', version: '3.1.1' + compileOnly 'jakarta.validation:jakarta.validation-api:3.1.1' // https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit - compileOnly group: 'com.squareup.retrofit2', name: 'retrofit', version: "${retrofitVersion}" + compileOnly 'com.squareup.retrofit2:retrofit:3.0.0' // https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-jackson - compileOnly group: 'com.squareup.retrofit2', name: 'converter-jackson', version: "${retrofitVersion}" + compileOnly 'com.squareup.retrofit2:converter-jackson:3.0.0' // https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor - compileOnly group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: '4.12.0' + compileOnly 'com.squareup.okhttp3:logging-interceptor:5.3.2' // https://mvnrepository.com/artifact/de.siegmar/logback-gelf - compileOnly group: 'de.siegmar', name: 'logback-gelf', version: '6.1.+' + compileOnly 'de.siegmar:logback-gelf:6.1.+' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web - testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: "${springBootVersion}" + testImplementation 'org.springframework.boot:spring-boot-starter-web:3.5.0' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test - testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "${springBootVersion}" + testImplementation 'org.springframework.boot:spring-boot-starter-test:3.5.0' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security - testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: "${springBootVersion}" + testImplementation 'org.springframework.boot:spring-boot-starter-security:3.5.0' // https://mvnrepository.com/artifact/org.springframework.amqp/spring-amqp - testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-amqp', version: "${springBootVersion}" + testImplementation 'org.springframework.boot:spring-boot-starter-amqp:3.5.0' // https://mvnrepository.com/artifact/org.json/json - testImplementation group: 'org.json', name: 'json', version: '20250517' + testImplementation 'org.json:json:20250517' // https://mvnrepository.com/artifact/ee.bitweb/spring-test-core - testImplementation group: 'ee.bitweb', name: 'spring-test-core', version: '2.+' + testImplementation 'ee.bitweb:spring-test-core:2.+' // https://mvnrepository.com/artifact/org.mockito/mockito-core - testImplementation group: 'org.mockito', name: 'mockito-core', version: "${mockitoVersion}" + testImplementation 'org.mockito:mockito-core:5.21.+' // https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter - testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${mockitoVersion}" + testImplementation 'org.mockito:mockito-junit-jupiter:5.21.+' // https://mvnrepository.com/artifact/org.mock-server/mockserver-netty - testImplementation ("org.mock-server:mockserver-netty:5.15.0") { + testImplementation('org.mock-server:mockserver-netty:5.15.0') { exclude group: 'junit', module: 'junit' } - testImplementation group : 'org.testcontainers', name: 'testcontainers', version: "1.+" + // https://mvnrepository.com/artifact/org.testcontainers/testcontainers + testImplementation 'org.testcontainers:testcontainers:1.+' - testRuntimeOnly("org.junit.platform:junit-platform-launcher") + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } configurations { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 1b33c55..f8e1ee3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 002b867..23449a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 23d15a9..adff685 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -172,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -212,7 +210,6 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" diff --git a/gradlew.bat b/gradlew.bat index db3a6ac..c4bdd3a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -70,11 +70,10 @@ goto fail :execute @rem Setup the command line -set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/library.gradle b/library.gradle index ad3bc43..d1e6885 100644 --- a/library.gradle +++ b/library.gradle @@ -94,4 +94,5 @@ javadoc { jar { from sourceSets.main.allSource + manifest.attributes(Map.of("Automatic-Module-Name", "ee.bitweb.core")) } diff --git a/sonarcloud.gradle b/sonarcloud.gradle index 4899bef..52fb41b 100644 --- a/sonarcloud.gradle +++ b/sonarcloud.gradle @@ -6,7 +6,7 @@ buildscript { } } dependencies { - classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:6.2.0.5505") + classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:7.2.2.6593") } } apply plugin: org.sonarqube.gradle.SonarQubePlugin diff --git a/src/test/java/ee/bitweb/core/retrofit/logging/mappers/RetrofitResponseBodyMapperTest.java b/src/test/java/ee/bitweb/core/retrofit/logging/mappers/RetrofitResponseBodyMapperTest.java index dbccc71..82a8cfa 100644 --- a/src/test/java/ee/bitweb/core/retrofit/logging/mappers/RetrofitResponseBodyMapperTest.java +++ b/src/test/java/ee/bitweb/core/retrofit/logging/mappers/RetrofitResponseBodyMapperTest.java @@ -7,12 +7,12 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.util.HashMap; import java.util.HashSet; import java.util.Set; import java.util.zip.GZIPOutputStream; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; @Tag("unit") class RetrofitResponseBodyMapperTest { @@ -22,21 +22,13 @@ class RetrofitResponseBodyMapperTest { void isRedactUrl() { var mapper = new RetrofitResponseBodyMapper(Set.of("https://www.google.com/"), 0); - var response = new Response( - request("GET"), - Protocol.HTTP_1_0, - "message", - 200, - null, - new Headers.Builder().build(), - ResponseBody.create("123".getBytes(), MediaType.get("application/text")), - null, - null, - null, - 1, - 2, - null - ); + var response = new Response.Builder() + .request(request("GET")) + .protocol(Protocol.HTTP_1_0) + .message("message") + .code(200) + .body(ResponseBody.create("123".getBytes(), MediaType.get("application/text"))) + .build(); var value = mapper.getValue(null, response); @@ -48,21 +40,13 @@ void isRedactUrl() { void promisesBody() { var mapper = new RetrofitResponseBodyMapper(new HashSet<>(), 0); - var response = new Response( - request("HEAD"), - Protocol.HTTP_1_0, - "message", - 201, - null, - new Headers.Builder().build(), - ResponseBody.create("123".getBytes(), MediaType.get("application/text")), - null, - null, - null, - 1, - 2, - null - ); + var response = new Response.Builder() + .request(request("HEAD")) + .protocol(Protocol.HTTP_1_0) + .message("message") + .code(201) + .body(ResponseBody.create("123".getBytes(), MediaType.get("application/text"))) + .build(); var value = mapper.getValue(null, response); @@ -74,21 +58,14 @@ void promisesBody() { void bodyHasUnknownEncoding() { var mapper = new RetrofitResponseBodyMapper(new HashSet<>(), 0); - var response = new Response( - request("GET"), - Protocol.HTTP_1_0, - "message", - 201, - null, - new Headers.Builder().add("Content-Encoding", "unknownEncoding").build(), - ResponseBody.create("123".getBytes(), MediaType.get("application/text")), - null, - null, - null, - 1, - 2, - null - ); + var response = new Response.Builder() + .request(request("GET")) + .protocol(Protocol.HTTP_1_0) + .message("message") + .code(201) + .header("Content-Encoding", "unknownEncoding") + .body(ResponseBody.create("123".getBytes(), MediaType.get("application/text"))) + .build(); var value = mapper.getValue(null, response); @@ -100,21 +77,12 @@ void bodyHasUnknownEncoding() { void bodyMissing() { var mapper = new RetrofitResponseBodyMapper(new HashSet<>(), 0); - var response = new Response( - request("GET"), - Protocol.HTTP_1_0, - "message", - 201, - null, - new Headers.Builder().build(), - null, - null, - null, - null, - 1, - 2, - null - ); + // In OkHttp 5.x, Response.body() is non-null by design, so we need to mock it + var response = mock(Response.class); + when(response.request()).thenReturn(request("GET")); + when(response.code()).thenReturn(201); + when(response.headers()).thenReturn(new Headers.Builder().build()); + when(response.body()).thenReturn(null); var value = mapper.getValue(null, response); @@ -125,21 +93,13 @@ void bodyMissing() { @DisplayName("Response body is correctly returned") void bodyAvailable() { var mapper = new RetrofitResponseBodyMapper(new HashSet<>(), 4096); - var response = new Response( - request("GET"), - Protocol.HTTP_2, - "OK", - 200, - null, - new Headers.Builder().build(), - ResponseBody.create("123".getBytes(), MediaType.get("application/text")), - null, - null, - null, - 1, - 2, - null - ); + var response = new Response.Builder() + .request(request("GET")) + .protocol(Protocol.HTTP_2) + .message("OK") + .code(200) + .body(ResponseBody.create("123".getBytes(), MediaType.get("application/text"))) + .build(); assertEquals("123", mapper.getValue(null, response)); } @@ -148,21 +108,13 @@ void bodyAvailable() { @DisplayName("Response body is correctly shortened") void bodyIsShortened() { var mapper = new RetrofitResponseBodyMapper(new HashSet<>(), 2); - var response = new Response( - request("GET"), - Protocol.HTTP_2, - "OK", - 200, - null, - new Headers.Builder().build(), - ResponseBody.create("123".getBytes(), MediaType.get("application/text")), - null, - null, - null, - 1, - 2, - null - ); + var response = new Response.Builder() + .request(request("GET")) + .protocol(Protocol.HTTP_2) + .message("OK") + .code(200) + .body(ResponseBody.create("123".getBytes(), MediaType.get("application/text"))) + .build(); assertEquals("12 ... Content size: 3 characters", mapper.getValue(null, response)); } @@ -171,21 +123,13 @@ void bodyIsShortened() { @DisplayName("Response body is correctly returned when empty") void bodyIsEmpty() { var mapper = new RetrofitResponseBodyMapper(new HashSet<>(), 4096); - var response = new Response( - request("GET"), - Protocol.HTTP_2, - "OK", - 200, - null, - new Headers.Builder().build(), - ResponseBody.create(new byte[]{}, MediaType.get("application/text")), - null, - null, - null, - 1, - 2, - null - ); + var response = new Response.Builder() + .request(request("GET")) + .protocol(Protocol.HTTP_2) + .message("OK") + .code(200) + .body(ResponseBody.create(new byte[]{}, MediaType.get("application/text"))) + .build(); assertEquals("", mapper.getValue(null, response)); } @@ -194,21 +138,14 @@ void bodyIsEmpty() { @DisplayName("Response body is correctly returned when response is gzipped") void bodyIsGzipped() throws IOException { var mapper = new RetrofitResponseBodyMapper(new HashSet<>(), 4096); - var response = new Response( - request("GET"), - Protocol.HTTP_2, - "OK", - 200, - null, - new Headers.Builder().add("Content-Encoding", "gzip").build(), - ResponseBody.create(gzip("some amount of data"), MediaType.get("application/text")), - null, - null, - null, - 1, - 2, - null - ); + var response = new Response.Builder() + .request(request("GET")) + .protocol(Protocol.HTTP_2) + .message("OK") + .code(200) + .header("Content-Encoding", "gzip") + .body(ResponseBody.create(gzip("some amount of data"), MediaType.get("application/text"))) + .build(); assertEquals("some amount of data", mapper.getValue(null, response)); } @@ -220,16 +157,13 @@ void responseIsNull() { } private Request request(String method) { - return new Request( - new HttpUrl.Builder() + return new Request.Builder() + .url(new HttpUrl.Builder() .scheme("https") .host("www.google.com") - .build(), - method, - new Headers.Builder().build(), - RequestBody.create("123".getBytes(), MediaType.get("application/text")), - new HashMap<>() - ); + .build()) + .method(method, method.equals("GET") || method.equals("HEAD") ? null : RequestBody.create("123".getBytes(), MediaType.get("application/text"))) + .build(); } private byte[] gzip(String data) throws IOException { diff --git a/test.gradle b/test.gradle index fe611ea..e3ddcd4 100644 --- a/test.gradle +++ b/test.gradle @@ -5,7 +5,10 @@ test { } tasks.register('unitTest', Test) { - group("verification") + group = "verification" + + testClassesDirs = sourceSets.test.output.classesDirs + classpath = sourceSets.test.runtimeClasspath useJUnitPlatform { excludeTags "integration" @@ -13,7 +16,10 @@ tasks.register('unitTest', Test) { } tasks.register('integrationTest', Test) { - group("verification") + group = "verification" + + testClassesDirs = sourceSets.test.output.classesDirs + classpath = sourceSets.test.runtimeClasspath useJUnitPlatform { includeTags 'integration' @@ -38,7 +44,7 @@ tasks.register('jacocoIntegrationTestReport', JacocoReport) { } } -tasks.register('testAndReport', Test) { +tasks.register('testAndReport') { tasks.getByName('integrationTest').mustRunAfter('unitTest') dependsOn('unitTest', 'integrationTest', 'jacocoUnitTestReport', 'jacocoIntegrationTestReport') }