diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e137bab..a73d5a1 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,11 +1,32 @@ version: 2 updates: -- package-ecosystem: gradle - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 2 - ignore: - - dependency-name: com.squareup.okhttp3:mockwebserver - versions: - - 4.9.0 + - package-ecosystem: gradle + directory: "/" + schedule: + interval: weekly + open-pull-requests-limit: 5 + groups: + gradle-minor-patch: + patterns: + - "*" + update-types: + - minor + - patch + gradle-major: + patterns: + - "*" + update-types: + - major + gradle-security: + applies-to: security-updates + patterns: + - "*" + + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: weekly + groups: + github-actions: + patterns: + - "*" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0a0957d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + # 27 is the newest non-LTS JDK: a forward-compatibility check that does not block merging + continue-on-error: ${{ matrix.java == 27 }} + strategy: + fail-fast: false + matrix: + java: [ 25, 27 ] + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: ${{ matrix.java }} + - uses: gradle/actions/setup-gradle@v6 + with: + cache-provider: basic + - run: ./gradlew build + - if: matrix.java == 25 + uses: codecov/codecov-action@v7 + with: + use_oidc: true + files: build/reports/jacoco/test/jacocoTestReport.xml + - if: matrix.java == 25 + name: Build as JitPack does for a tag + run: ./gradlew clean -Pgroup=com.github.Visual-Regression-Tracker -Pversion=ci -xtest assemble publishToMavenLocal + + # the required check on master: one name for the whole matrix + build: + needs: test + if: ${{ !cancelled() }} + runs-on: ubuntu-latest + steps: + - run: test "${{ needs.test.result }}" = success diff --git a/.github/workflows/dependency-submission.yml b/.github/workflows/dependency-submission.yml index 6c03782..bc3cdea 100644 --- a/.github/workflows/dependency-submission.yml +++ b/.github/workflows/dependency-submission.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/setup-java@v6 with: distribution: temurin - java-version: 11 + java-version: 25 - uses: gradle/actions/dependency-submission@v6 with: cache-provider: basic diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index 0adc305..0000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,33 +0,0 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: Java CI with Gradle - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up JDK 11 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 11 - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Gradle check - run: ./gradlew check - - - name: Codecov - uses: codecov/codecov-action@v1.0.12 diff --git a/build.gradle b/build.gradle index 7e0f06e..6423709 100644 --- a/build.gradle +++ b/build.gradle @@ -1,52 +1,62 @@ -group 'io.visual-regression-tracker.sdk-java' -version '4.3.1' - -apply plugin: 'java' -apply plugin: 'jacoco' -apply plugin: "io.freefair.lombok" +plugins { + id 'java-library' + id 'jacoco' + id 'maven-publish' + id 'io.freefair.lombok' version '9.8.3' +} repositories { mavenCentral() } -buildscript { - repositories { - maven { - url "https://plugins.gradle.org/m2/" - } +java { + withSourcesJar() +} - } - dependencies { - classpath "io.freefair.gradle:lombok-plugin:5.1.1" - } +tasks.withType(JavaCompile).configureEach { + options.release = 25 + options.encoding = 'UTF-8' } +configurations { + mockitoAgent +} + +def mockito = 'org.mockito:mockito-core:5.24.0' + dependencies { - implementation 'com.google.code.gson:gson:2.9.0' - implementation 'org.slf4j:slf4j-api:1.7.25' - testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.38' - testImplementation group: 'org.testng', name: 'testng', version: '7.7.0' - testImplementation 'commons-io:commons-io:2.18.0' - testImplementation 'org.mockito:mockito-core:4.4.0' - testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0' - testImplementation 'uk.org.webcompere:system-stubs-testng:2.1.3' + implementation 'com.google.code.gson:gson:2.15.0' + implementation 'org.slf4j:slf4j-api:2.0.20' + + testImplementation 'ch.qos.logback:logback-classic:1.6.6' + testImplementation 'org.testng:testng:7.12.0' + testImplementation 'org.hamcrest:hamcrest:3.0' + testImplementation mockito + mockitoAgent(mockito) { + transitive = false + } + testImplementation 'com.squareup.okhttp3:mockwebserver3:5.5.1' + testImplementation 'uk.org.webcompere:system-stubs-testng:2.1.8' } test { useTestNG() + def agent = configurations.mockitoAgent + jvmArgs '-XX:+EnableDynamicAgentLoading' + jvmArgumentProviders.add({ ["-javaagent:${agent.singleFile}".toString()] } as CommandLineArgumentProvider) + finalizedBy jacocoTestReport } -// codecov integration https://github.com/codecov/example-gradle jacocoTestReport { reports { - xml.enabled true - html.enabled true + xml.required = true } } -check.dependsOn jacocoTestReport - -// Gradle 6.1 otherwise picks the sources variant of Kotlin multiplatform modules such as okio 3.6 -configurations.matching { it.canBeResolved }.configureEach { - attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) +publishing { + publications { + maven(MavenPublication) { + from components.java + } + } } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..a3e43de --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +group=io.visual-regression-tracker.sdk-java +version=0.0.0-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index f3d88b1..9fa7f28 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 0f18fec..5907d39 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,10 @@ -#Sat May 09 22:38:23 CEST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionSha256Sum=21bd5da2de49b642904077f38c0efdc7778e92b3ed0889392dca61b97e389607 +distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 2fe81a7..249efbb 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or 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. @@ -15,80 +15,114 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# gradlew start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh gradlew +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,87 +131,118 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 24467a1..03754c4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,22 +13,55 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem -@rem Gradle startup script for Windows +@rem gradlew startup script for Windows @rem @rem ########################################################################## -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions + +@rem Catch executions from older scripts and ensure they exit cleanly. +@rem This can be removed once we can be reasonably confident that few people +@rem will be migrating directly to this new wrapper. +goto afterSafetyNet +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +goto exitWithErrorLevel +:afterSafetyNet set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -37,64 +70,43 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +1>&2 echo. +1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +1>&2 echo. +1>&2 echo Please set the JAVA_HOME variable in your environment to match the +1>&2 echo location of your Java installation. -goto fail +"%COMSPEC%" /c exit 1 +goto exitWithErrorLevel :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants +if exist "%JAVA_EXE%" goto execute -if not "%OS%" == "Windows_NT" goto win9xME_args +1>&2 echo. +1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +1>&2 echo. +1>&2 echo Please set the JAVA_HOME variable in your environment to match the +1>&2 echo location of your Java installation. -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* +"%COMSPEC%" /c exit 1 +goto exitWithErrorLevel :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 -:mainEnd -if "%OS%"=="Windows_NT" endlocal +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel -:omega +@rem This label must not be changed. We rely on old scripts being able to jump to this point. +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/jitpack.yml b/jitpack.yml index 46c8529..aaa5890 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,2 +1,2 @@ jdk: - - openjdk11 \ No newline at end of file + - openjdk25 diff --git a/lombok.config b/lombok.config index 189c0be..df71bb6 100644 --- a/lombok.config +++ b/lombok.config @@ -1,3 +1,2 @@ -# This file is generated by the 'io.freefair.lombok' Gradle plugin config.stopBubbling = true lombok.addLombokGeneratedAnnotation = true diff --git a/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerMultipartTest.java b/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerMultipartTest.java index 35182a2..e7bc883 100644 --- a/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerMultipartTest.java +++ b/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerMultipartTest.java @@ -3,9 +3,9 @@ import com.google.gson.Gson; import io.visual_regression_tracker.sdk_java.response.TestRunResponse; import lombok.SneakyThrows; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; +import mockwebserver3.MockResponse; +import mockwebserver3.MockWebServer; +import mockwebserver3.RecordedRequest; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -48,7 +48,7 @@ public void setup() { @SneakyThrows @AfterMethod public void tearDown() { - mockWebServer.shutdown(); + mockWebServer.close(); } @Test @@ -69,12 +69,12 @@ public void trackBytesShouldPostEveryOptionAsMultipartForm() throws Exception { .build()); RecordedRequest request = mockWebServer.takeRequest(); - String body = request.getBody().readUtf8(); + String body = request.getBody().utf8(); assertThat(request.getMethod(), is("POST")); - assertThat(request.getPath(), endsWith("/test-runs/multipart")); - assertThat(request.getHeader("Content-Type"), startsWith("multipart/form-data; boundary=")); - assertThat(request.getHeader("Content-Length"), is(String.valueOf(request.getBodySize()))); - assertThat(request.getHeader(VisualRegressionTracker.API_KEY_HEADER), is("key")); + assertThat(request.getUrl().encodedPath(), endsWith("/test-runs/multipart")); + assertThat(request.getHeaders().get("Content-Type"), startsWith("multipart/form-data; boundary=")); + assertThat(request.getHeaders().get("Content-Length"), is(String.valueOf(request.getBodySize()))); + assertThat(request.getHeaders().get(VisualRegressionTracker.API_KEY_HEADER), is("key")); assertThat(body, containsString(field("projectId", PROJECT_ID))); assertThat(body, containsString(field("buildId", BUILD_ID))); assertThat(body, containsString(field("name", "Home page"))); @@ -99,7 +99,7 @@ public void trackBytesShouldLeaveOutOptionsThatAreNotSet() throws Exception { vrt.track("Home page", IMAGE); - String body = mockWebServer.takeRequest().getBody().readUtf8(); + String body = mockWebServer.takeRequest().getBody().utf8(); assertThat(body, not(containsString("name=\"os\""))); assertThat(body, not(containsString("name=\"comment\""))); assertThat(body, not(containsString("name=\"merge\""))); @@ -115,16 +115,16 @@ public void trackPathShouldUploadTheFileUnderItsName() throws Exception { vrt.track("Home page", screenshot); RecordedRequest request = mockWebServer.takeRequest(); - assertThat(request.getPath(), endsWith("/test-runs/multipart")); - assertThat(request.getBody().readUtf8(), containsString(image("home.png", "PNG bytes"))); + assertThat(request.getUrl().encodedPath(), endsWith("/test-runs/multipart")); + assertThat(request.getBody().utf8(), containsString(image("home.png", "PNG bytes"))); } @Test public void trackBytesShouldFailOnDifferenceLikeBase64() { - mockWebServer.enqueue(new MockResponse().setBody(gson.toJson(TestRunResponse.builder() + mockWebServer.enqueue(new MockResponse.Builder().body(gson.toJson(TestRunResponse.builder() .status(TestRunStatus.UNRESOLVED) .url("http://localhost:8080/test/1") - .build()))); + .build())).build()); TestRunException exception = expectThrows(TestRunException.class, () -> vrt.track("Home page", IMAGE)); @@ -133,7 +133,7 @@ public void trackBytesShouldFailOnDifferenceLikeBase64() { @Test public void payloadTooLargeOnMultipartShouldPointAtTheMultipartLimit() { - mockWebServer.enqueue(new MockResponse().setResponseCode(413).setBody("{\"message\":\"File too large\"}")); + mockWebServer.enqueue(new MockResponse.Builder().code(413).body("{\"message\":\"File too large\"}").build()); TestRunException exception = expectThrows(TestRunException.class, () -> vrt.track("Home page", IMAGE)); @@ -144,7 +144,7 @@ public void payloadTooLargeOnMultipartShouldPointAtTheMultipartLimit() { @Test public void payloadTooLargeOnBase64ShouldSuggestMultipart() { - mockWebServer.enqueue(new MockResponse().setResponseCode(413).setBody("{\"message\":\"request entity too large\"}")); + mockWebServer.enqueue(new MockResponse.Builder().code(413).body("{\"message\":\"request entity too large\"}").build()); TestRunException exception = expectThrows(TestRunException.class, () -> vrt.track("Home page", "aW1hZ2U=")); @@ -153,7 +153,7 @@ public void payloadTooLargeOnBase64ShouldSuggestMultipart() { } private void enqueueStatus(TestRunStatus status) { - mockWebServer.enqueue(new MockResponse().setBody(gson.toJson(TestRunResponse.builder().status(status).build()))); + mockWebServer.enqueue(new MockResponse.Builder().body(gson.toJson(TestRunResponse.builder().status(status).build())).build()); } private static String field(String name, String value) { diff --git a/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerRetryTest.java b/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerRetryTest.java index fde1c5a..5da3a09 100644 --- a/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerRetryTest.java +++ b/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerRetryTest.java @@ -3,8 +3,8 @@ import com.google.gson.Gson; import io.visual_regression_tracker.sdk_java.response.BuildResponse; import lombok.SneakyThrows; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; +import mockwebserver3.MockResponse; +import mockwebserver3.MockWebServer; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -42,7 +42,7 @@ void sleep(Duration duration) { @SneakyThrows @AfterMethod public void tearDown() { - mockWebServer.shutdown(); + mockWebServer.close(); } @Test @@ -81,7 +81,7 @@ public void shouldGiveUpAfterTheLastRetry() { @Test public void shouldNotRetryServiceUnavailableWithoutRetryAfter() { - mockWebServer.enqueue(new MockResponse().setResponseCode(503).setBody("{\"message\":\"Directory service is not available.\"}")); + mockWebServer.enqueue(new MockResponse.Builder().code(503).body("{\"message\":\"Directory service is not available.\"}").build()); mockWebServer.enqueue(started()); TestRunException exception = expectThrows(TestRunException.class, () -> vrt.start()); @@ -92,7 +92,7 @@ public void shouldNotRetryServiceUnavailableWithoutRetryAfter() { @Test public void shouldNotRetryOtherErrorsWithRetryAfter() { - mockWebServer.enqueue(new MockResponse().setResponseCode(429).setHeader("Retry-After", "0")); + mockWebServer.enqueue(new MockResponse.Builder().code(429).setHeader("Retry-After", "0").build()); mockWebServer.enqueue(started()); expectThrows(TestRunException.class, () -> vrt.start()); @@ -112,13 +112,14 @@ public void shouldNotRetryWhenRetryAfterIsNotSeconds() { } private static MockResponse busy(String retryAfter) { - return new MockResponse() - .setResponseCode(503) + return new MockResponse.Builder() + .code(503) .setHeader("Retry-After", retryAfter) - .setBody("{\"message\":\"Image diff queue is full (100 jobs)\"}"); + .body("{\"message\":\"Image diff queue is full (100 jobs)\"}") + .build(); } private MockResponse started() { - return new MockResponse().setBody(gson.toJson(BuildResponse.builder().id("buildId").projectId("projectId").build())); + return new MockResponse.Builder().body(gson.toJson(BuildResponse.builder().id("buildId").projectId("projectId").build())).build(); } } diff --git a/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerTest.java b/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerTest.java index efe0716..50ff444 100755 --- a/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerTest.java +++ b/src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerTest.java @@ -10,9 +10,9 @@ import io.visual_regression_tracker.sdk_java.response.BuildResponse; import io.visual_regression_tracker.sdk_java.response.TestRunResponse; import lombok.SneakyThrows; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; +import mockwebserver3.MockResponse; +import mockwebserver3.MockWebServer; +import mockwebserver3.RecordedRequest; import org.slf4j.LoggerFactory; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -25,7 +25,6 @@ import java.net.http.HttpTimeoutException; import java.time.Duration; import java.util.Arrays; -import java.util.Objects; import java.util.Optional; import java.util.concurrent.TimeUnit; @@ -81,7 +80,7 @@ public void setup() { @SneakyThrows @AfterMethod public void tearDown() { - mockWebServer.shutdown(); + mockWebServer.close(); reset(vrtMocked); } @@ -97,17 +96,17 @@ public void shouldStartBuild() throws IOException, InterruptedException { .projectId(PROJECT_ID) .ciBuildId(CI_BUILD_ID) .build(); - mockWebServer.enqueue(new MockResponse() - .setResponseCode(200) - .setBody(gson.toJson(buildResponse))); + mockWebServer.enqueue(new MockResponse.Builder() + .code(200) + .body(gson.toJson(buildResponse)).build()); BuildResponse result = vrt.start(); RecordedRequest recordedRequest = mockWebServer.takeRequest(); - assertThat(recordedRequest.getPath(), is("/builds")); - assertThat(recordedRequest.getHeader(VisualRegressionTracker.API_KEY_HEADER), is(config.getApiKey())); - assertThat(recordedRequest.getHeader(VisualRegressionTracker.PROJECT_HEADER), is(config.getProject())); - assertThat(recordedRequest.getBody().readUtf8(), is(gson.toJson(buildRequest))); + assertThat(recordedRequest.getUrl().encodedPath(), is("/builds")); + assertThat(recordedRequest.getHeaders().get(VisualRegressionTracker.API_KEY_HEADER), is(config.getApiKey())); + assertThat(recordedRequest.getHeaders().get(VisualRegressionTracker.PROJECT_HEADER), is(config.getProject())); + assertThat(recordedRequest.getBody().utf8(), is(gson.toJson(buildRequest))); assertThat(vrt.buildId, is(BUILD_ID)); assertThat(vrt.projectId, is(PROJECT_ID)); assertThat(result.getId(), is(BUILD_ID)); @@ -126,18 +125,18 @@ public void shouldStopBuild() throws IOException, InterruptedException { .isRunning(false) .status("unresolved") .build(); - mockWebServer.enqueue(new MockResponse() - .setResponseCode(200) - .setBody(gson.toJson(buildResponse))); + mockWebServer.enqueue(new MockResponse.Builder() + .code(200) + .body(gson.toJson(buildResponse)).build()); BuildResponse actualBuildResponse = vrt.stop(); RecordedRequest recordedRequest = mockWebServer.takeRequest(); assertThat(recordedRequest.getMethod(), is("PATCH")); - assertThat(recordedRequest.getHeader(VisualRegressionTracker.API_KEY_HEADER), is(config.getApiKey())); - assertThat(recordedRequest.getHeader(VisualRegressionTracker.PROJECT_HEADER), is(config.getProject())); - assertThat(Objects.requireNonNull(recordedRequest.getRequestUrl()).encodedPath(), containsString(BUILD_ID)); - assertThat(recordedRequest.getBody().readUtf8(), is("{\"isRunning\":false}")); + assertThat(recordedRequest.getHeaders().get(VisualRegressionTracker.API_KEY_HEADER), is(config.getApiKey())); + assertThat(recordedRequest.getHeaders().get(VisualRegressionTracker.PROJECT_HEADER), is(config.getProject())); + assertThat(recordedRequest.getUrl().encodedPath(), containsString(BUILD_ID)); + assertThat(recordedRequest.getBody().utf8(), is("{\"isRunning\":false}")); assertThat(actualBuildResponse.isRunning(), is(false)); assertThat(actualBuildResponse.getStatus(), containsString("unresolved")); assertThat(actualBuildResponse.getPassedCount(), is(1)); @@ -188,7 +187,7 @@ public void shouldSubmitTestRun() throws IOException, InterruptedException { TestRunResponse testRunResponse = TestRunResponse.builder() .status(TestRunStatus.UNRESOLVED) .build(); - mockWebServer.enqueue(new MockResponse().setBody(gson.toJson(testRunResponse))); + mockWebServer.enqueue(new MockResponse.Builder().body(gson.toJson(testRunResponse)).build()); config.setSourceBranch("release"); vrt.buildId = BUILD_ID; vrt.projectId = PROJECT_ID; @@ -196,9 +195,9 @@ public void shouldSubmitTestRun() throws IOException, InterruptedException { TestRunResponse result = vrt.submitTestRun(NAME, IMAGE_BASE_64, testRunOptions); RecordedRequest request = mockWebServer.takeRequest(); - assertThat(request.getHeader(VisualRegressionTracker.API_KEY_HEADER), is(config.getApiKey())); - assertThat(request.getHeader(VisualRegressionTracker.PROJECT_HEADER), is(config.getProject())); - assertThat(request.getBody().readUtf8(), is(gson.toJson(testRunRequest))); + assertThat(request.getHeaders().get(VisualRegressionTracker.API_KEY_HEADER), is(config.getApiKey())); + assertThat(request.getHeaders().get(VisualRegressionTracker.PROJECT_HEADER), is(config.getProject())); + assertThat(request.getBody().utf8(), is(gson.toJson(testRunRequest))); assertThat(gson.toJson(result), is(gson.toJson(testRunResponse))); } @@ -386,39 +385,39 @@ public void handleResponseShouldThrowWithStatusAndServerMessage(int statusCode, public void trackShouldSendBranchNameOfBuildWhenNoneConfigured() throws IOException, InterruptedException { vrt = new VisualRegressionTracker(new VisualRegressionTrackerConfig( mockWebServer.url("/").toString(), "key", "project", null, null, false, HTTP_TIMEOUT)); - mockWebServer.enqueue(new MockResponse().setBody(gson.toJson(BuildResponse.builder() + mockWebServer.enqueue(new MockResponse.Builder().body(gson.toJson(BuildResponse.builder() .id(BUILD_ID) .projectId(PROJECT_ID) .branchName("main") - .build()))); - mockWebServer.enqueue(new MockResponse().setBody(gson.toJson(TestRunResponse.builder() + .build())).build()); + mockWebServer.enqueue(new MockResponse.Builder().body(gson.toJson(TestRunResponse.builder() .status(TestRunStatus.OK) - .build()))); + .build())).build()); vrt.start(); vrt.track(NAME, IMAGE_BASE_64); mockWebServer.takeRequest(); - TestRunRequest sent = gson.fromJson(mockWebServer.takeRequest().getBody().readUtf8(), TestRunRequest.class); + TestRunRequest sent = gson.fromJson(mockWebServer.takeRequest().getBody().utf8(), TestRunRequest.class); assertThat(sent.getBranchName(), is("main")); } @Test public void trackShouldSendConfiguredBranchNameOverBuildBranch() throws IOException, InterruptedException { - mockWebServer.enqueue(new MockResponse().setBody(gson.toJson(BuildResponse.builder() + mockWebServer.enqueue(new MockResponse.Builder().body(gson.toJson(BuildResponse.builder() .id(BUILD_ID) .projectId(PROJECT_ID) .branchName("main") - .build()))); - mockWebServer.enqueue(new MockResponse().setBody(gson.toJson(TestRunResponse.builder() + .build())).build()); + mockWebServer.enqueue(new MockResponse.Builder().body(gson.toJson(TestRunResponse.builder() .status(TestRunStatus.OK) - .build()))); + .build())).build()); vrt.start(); vrt.track(NAME, IMAGE_BASE_64); mockWebServer.takeRequest(); - TestRunRequest sent = gson.fromJson(mockWebServer.takeRequest().getBody().readUtf8(), TestRunRequest.class); + TestRunRequest sent = gson.fromJson(mockWebServer.takeRequest().getBody().utf8(), TestRunRequest.class); assertThat(sent.getBranchName(), is("develop")); } @@ -431,7 +430,7 @@ public void shouldConnectWithTenSecondTimeout() { public void trackShouldReturnUnknownForStatusItDoesNotKnow() throws IOException, InterruptedException { vrt.buildId = BUILD_ID; vrt.projectId = PROJECT_ID; - mockWebServer.enqueue(new MockResponse().setBody("{\"status\":\"someFutureStatus\",\"url\":\"https://someurl.com/test/1\"}")); + mockWebServer.enqueue(new MockResponse.Builder().body("{\"status\":\"someFutureStatus\",\"url\":\"https://someurl.com/test/1\"}").build()); ListAppender listAppender = new ListAppender<>(); listAppender.start(); ((Logger) LoggerFactory.getLogger(VisualRegressionTracker.class)).addAppender(listAppender); @@ -453,9 +452,9 @@ public void httpTimeoutWorks() throws IOException, InterruptedException { .build(); String json = gson.toJson(buildResponse); //body size is 97 bytes, http timeout is 1s, set body read delay to 0.5s, wait that vrt get all values correctly - mockWebServer.enqueue(new MockResponse().throttleBody(json.length(), HTTP_TIMEOUT * 1000 - 500, TimeUnit.MILLISECONDS) - .setResponseCode(200) - .setBody(json)); + mockWebServer.enqueue(new MockResponse.Builder().throttleBody(json.length(), HTTP_TIMEOUT * 1000 - 500, TimeUnit.MILLISECONDS) + .code(200) + .body(json).build()); vrt.start(); @@ -469,10 +468,10 @@ public void httpTimeoutWorks() throws IOException, InterruptedException { public void zeroHttpTimeoutShouldMeanNoLimit() throws IOException, InterruptedException { vrt = new VisualRegressionTracker(new VisualRegressionTrackerConfig( mockWebServer.url("/").toString(), "key", "project", "develop", null, false, 0)); - mockWebServer.enqueue(new MockResponse().setBody(gson.toJson(BuildResponse.builder() + mockWebServer.enqueue(new MockResponse.Builder().body(gson.toJson(BuildResponse.builder() .id(BUILD_ID) .projectId(PROJECT_ID) - .build()))); + .build())).build()); vrt.start(); @@ -483,7 +482,7 @@ public void zeroHttpTimeoutShouldMeanNoLimit() throws IOException, InterruptedEx public void negativeHttpTimeoutShouldBeRejected() throws IOException, InterruptedException { vrt = new VisualRegressionTracker(new VisualRegressionTrackerConfig( mockWebServer.url("/").toString(), "key", "project", "develop", null, false, -1)); - mockWebServer.enqueue(new MockResponse().setBody(gson.toJson(BuildResponse.builder().id(BUILD_ID).build()))); + mockWebServer.enqueue(new MockResponse.Builder().body(gson.toJson(BuildResponse.builder().id(BUILD_ID).build())).build()); vrt.start(); } @@ -504,9 +503,9 @@ public void httpTimeoutElapsed() throws IOException, InterruptedException { String json = gson.toJson(buildResponse); //Send part of the body after every timeout, http timeout is 1s, set body read delay to 1s, wait for error //For some reason double HTTP_TIMEOUT does not throw exception. - mockWebServer.enqueue(new MockResponse().throttleBody((json.length() / 2), HTTP_TIMEOUT, TimeUnit.SECONDS) - .setResponseCode(200) - .setBody(json)); + mockWebServer.enqueue(new MockResponse.Builder().throttleBody((json.length() / 2), HTTP_TIMEOUT, TimeUnit.SECONDS) + .code(200) + .body(json).build()); vrt.start();