Skip to content

Commit

Permalink
Apply spotless prettier code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaprasadreddy committed Dec 1, 2023
1 parent 19517bd commit 79c3cab
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
java=17.0.4-tem
gradle=7.5.1
java=17.0.8-tem
gradle=8.5
maven=3.8.6
22 changes: 19 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.6'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
id 'com.diffplug.spotless' version "6.23.0"
}

group = 'com.testcontainers'
Expand All @@ -19,7 +20,7 @@ repositories {
}

ext {
set('testcontainersVersion', "1.18.0")
set('testcontainersVersion', "1.19.3")
}

dependencies {
Expand Down Expand Up @@ -47,3 +48,18 @@ tasks.named('test') {
exceptionFormat = "full"
}
}

spotless {
java {
importOrder()
removeUnusedImports()
prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0'])
.config([
'parser': 'java',
'tabWidth': 2,
'printWidth': 80,
'plugins': ['prettier-plugin-java']
])
formatAnnotations()
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 22 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${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"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +131,29 @@ 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.
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" && ! "$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
Expand Down Expand Up @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# 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, 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" \
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Once the application is generated, add the following *RestAssured* and *Mockserv

[source,groovy,indent=0]
----
include::{codebase}/build.gradle[lines="31..33"]
include::{codebase}/build.gradle[lines="32..34"]
----

Assume we are building an application to manage video albums, and we are going to use a 3rd party
Expand Down Expand Up @@ -180,7 +180,7 @@ So, let us write the test for GET `/api/albums/\{albumId}` endpoint as follows:

[source,java]
----
include::{codebase}/src/test/java/com/testcontainers/demo/AlbumControllerTest.java[lines="1..99,117..124"]
include::{codebase}/src/test/java/com/testcontainers/demo/AlbumControllerTest.java[lines="1..102,123..130"]
----

Let us understand what is going on in this test.
Expand Down
35 changes: 23 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<version>3.2.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.testcontainers</groupId>
Expand All @@ -17,7 +17,7 @@
<description>Testing REST API integrations using MockServer</description>
<properties>
<java.version>17</java.version>
<testcontainers.version>1.18.0</testcontainers.version>
<testcontainers.version>1.19.3</testcontainers.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -74,20 +74,31 @@
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>0.16</version>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.41.0</version>
<configuration>
<prettierJavaVersion>1.5.0</prettierJavaVersion>
<printWidth>90</printWidth>
<tabWidth>2</tabWidth>
<useTabs>false</useTabs>
<ignoreConfigFile>true</ignoreConfigFile>
<ignoreEditorConfig>true</ignoreEditorConfig>
<java>
<importOrder />
<removeUnusedImports />
<prettier>
<devDependencies>
<prettier>3.0.3</prettier>
<prettier-plugin-java>2.3.0</prettier-plugin-java>
</devDependencies>
<config>
<parser>java</parser>
<tabWidth>2</tabWidth>
<printWidth>80</printWidth>
<plugins>prettier-plugin-java</plugins>
</config>
</prettier>
<formatAnnotations />
</java>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/testcontainers/demo/AlbumController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
@RequestMapping("/api")
class AlbumController {

private static final Logger logger = LoggerFactory.getLogger(AlbumController.class);
private static final Logger logger = LoggerFactory.getLogger(
AlbumController.class
);

private final PhotoServiceClient photoServiceClient;

Expand Down
20 changes: 13 additions & 7 deletions src/test/java/com/testcontainers/demo/AlbumControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class AlbumControllerTest {
@DynamicPropertySource
static void overrideProperties(DynamicPropertyRegistry registry) {
mockServerClient =
new MockServerClient(
mockServerContainer.getHost(),
mockServerContainer.getServerPort()
);
new MockServerClient(
mockServerContainer.getHost(),
mockServerContainer.getServerPort()
);
registry.add("photos.api.base-url", mockServerContainer::getEndpoint);
}

Expand All @@ -58,11 +58,15 @@ void shouldGetAlbumById() {
Long albumId = 1L;

mockServerClient
.when(request().withMethod("GET").withPath("/albums/" + albumId + "/photos"))
.when(
request().withMethod("GET").withPath("/albums/" + albumId + "/photos")
)
.respond(
response()
.withStatusCode(200)
.withHeaders(new Header("Content-Type", "application/json; charset=utf-8"))
.withHeaders(
new Header("Content-Type", "application/json; charset=utf-8")
)
.withBody(
json(
"""
Expand Down Expand Up @@ -101,7 +105,9 @@ void shouldGetAlbumById() {
void shouldReturn404StatusWhenAlbumNotFound() {
Long albumId = 1L;
mockServerClient
.when(request().withMethod("GET").withPath("/albums/" + albumId + "/photos"))
.when(
request().withMethod("GET").withPath("/albums/" + albumId + "/photos")
)
.respond(response().withStatusCode(404));

given()
Expand Down

0 comments on commit 79c3cab

Please sign in to comment.