Merge branch 'checkstyle-v1' into 'main'
draft checkstyle.xml with 10 rules See merge request cse1105/2025-2026/teams/csep-team-76!1
This commit is contained in:
commit
ac8f3f2699
13 changed files with 571 additions and 492 deletions
|
|
@ -1,13 +1,92 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
<!DOCTYPE module PUBLIC
|
<!DOCTYPE module PUBLIC
|
||||||
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||||
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||||
|
<module name="Checker">
|
||||||
|
<!-- CheckStyle settings -->
|
||||||
|
|
||||||
<module name = "Checker">
|
<module name="TreeWalker">
|
||||||
<module name="TreeWalker">
|
<!-- 1. camelCase for identifiers -->
|
||||||
<module name="UnusedImports" />
|
<module name="LocalVariableName">
|
||||||
</module>
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
<module name="ParameterName">
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
<module name="MemberName">
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
<module name="MethodName">
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
<module name="ClassTypeParameterName">
|
||||||
|
<property name="format" value="^[A-Z][a-zA-Z0-9]*$"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- 2. Avoid "bulk" aka. star imports in form of `import package.*` -->
|
||||||
|
<module name="AvoidStarImport">
|
||||||
|
<!-- We permit static member imports in the case of
|
||||||
|
JUnit tests such that unit tests aren't too verbose
|
||||||
|
-->
|
||||||
|
<property name="allowStaticMemberImports" value="true" />
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- 3. One class per file -->
|
||||||
|
<module name="OneTopLevelClass"/>
|
||||||
|
|
||||||
|
<!-- 4. Max 60 lines per method -->
|
||||||
|
<module name="MethodLength">
|
||||||
|
<property name="max" value="60"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- 5. Indentation 4 spaces -->
|
||||||
|
<module name="Indentation">
|
||||||
|
<property name="basicOffset" value="4"/>
|
||||||
|
<property name="braceAdjustment" value="0"/>
|
||||||
|
<property name="caseIndent" value="4"/>
|
||||||
|
<property name="lineWrappingIndentation" value="8"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- 6. No “fall-through” in switch cases -->
|
||||||
|
<!-- info: https://checkstyle.sourceforge.io/checks/coding/fallthrough.html -->
|
||||||
|
<module name="FallThrough" />
|
||||||
|
|
||||||
|
<!-- 7. Left curly brace on same line (EOL) as method name -->
|
||||||
|
<module name="LeftCurly">
|
||||||
|
<property name="option" value="eol"/>
|
||||||
|
<property name="tokens"
|
||||||
|
value="METHOD_DEF, CTOR_DEF, CLASS_DEF, LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, LITERAL_TRY, LITERAL_CATCH"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- 8. Magic numbers: disallow literal numbers (except allowed ones) -->
|
||||||
|
<module name="MagicNumber">
|
||||||
|
<!-- We allow -1, 0, 1 to make length checks mildly easier -->
|
||||||
|
<property name="ignoreNumbers"
|
||||||
|
value="-1,0,1"/>
|
||||||
|
<property name="ignoreHashCodeMethod" value="false"/>
|
||||||
|
<property name="ignoreAnnotation" value="true"/>
|
||||||
|
<property name="ignoreFieldDeclaration" value="false"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- 9: Check parameter number at most 6 -->
|
||||||
|
<module name="ParameterNumber">
|
||||||
|
<property name="max" value="6"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- 10. Unused imports -->
|
||||||
|
<module name="UnusedImports">
|
||||||
|
<!-- also check Javadoc references refer to things that exist,
|
||||||
|
where applicable. -->
|
||||||
|
<property name="processJavadoc" value="true"/>
|
||||||
|
</module>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- 11. File tabs/spaces: require no raw tabs etc -->
|
||||||
|
<module name="FileTabCharacter">
|
||||||
|
<property name="severity" value="warning" />
|
||||||
|
<property name="eachLine" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
<!-- TODO: decide in your team with other checkers to add! -->
|
|
||||||
|
|
||||||
</module>
|
</module>
|
||||||
240
client/pom.xml
240
client/pom.xml
|
|
@ -1,130 +1,130 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>csep</groupId>
|
<groupId>csep</groupId>
|
||||||
<artifactId>client</artifactId>
|
<artifactId>client</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<version.junit>5.10.1</version.junit>
|
<version.junit>5.10.1</version.junit>
|
||||||
<version.mockito>5.8.0</version.mockito>
|
<version.mockito>5.8.0</version.mockito>
|
||||||
<version.jersey>3.1.9</version.jersey>
|
<version.jersey>3.1.9</version.jersey>
|
||||||
<version.jfx>25.0.1</version.jfx>
|
<version.jfx>25.0.1</version.jfx>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>csep</groupId>
|
<groupId>csep</groupId>
|
||||||
<artifactId>commons</artifactId>
|
<artifactId>commons</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.core</groupId>
|
<groupId>org.glassfish.jersey.core</groupId>
|
||||||
<artifactId>jersey-client</artifactId>
|
<artifactId>jersey-client</artifactId>
|
||||||
<version>${version.jersey}</version>
|
<version>${version.jersey}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.inject</groupId>
|
<groupId>org.glassfish.jersey.inject</groupId>
|
||||||
<artifactId>jersey-hk2</artifactId>
|
<artifactId>jersey-hk2</artifactId>
|
||||||
<version>${version.jersey}</version>
|
<version>${version.jersey}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.media</groupId>
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
<artifactId>jersey-media-json-jackson</artifactId>
|
<artifactId>jersey-media-json-jackson</artifactId>
|
||||||
<version>${version.jersey}</version>
|
<version>${version.jersey}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.activation</groupId>
|
<groupId>jakarta.activation</groupId>
|
||||||
<artifactId>jakarta.activation-api</artifactId>
|
<artifactId>jakarta.activation-api</artifactId>
|
||||||
<version>2.1.3</version>
|
<version>2.1.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.inject</groupId>
|
<groupId>com.google.inject</groupId>
|
||||||
<artifactId>guice</artifactId>
|
<artifactId>guice</artifactId>
|
||||||
<version>7.0.0</version>
|
<version>7.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JavaFX -->
|
<!-- JavaFX -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openjfx</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
<artifactId>javafx-fxml</artifactId>
|
<artifactId>javafx-fxml</artifactId>
|
||||||
<version>${version.jfx}</version>
|
<version>${version.jfx}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openjfx</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
<artifactId>javafx-controls</artifactId>
|
<artifactId>javafx-controls</artifactId>
|
||||||
<version>${version.jfx}</version>
|
<version>${version.jfx}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openjfx</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
<artifactId>javafx-web</artifactId>
|
<artifactId>javafx-web</artifactId>
|
||||||
<version>${version.jfx}</version>
|
<version>${version.jfx}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- test -->
|
<!-- test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>${version.junit}</version>
|
<version>${version.junit}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>${version.junit}</version>
|
<version>${version.junit}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>${version.mockito}</version>
|
<version>${version.mockito}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.13.0</version>
|
<version>3.13.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<release>23</release>
|
<release>23</release>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.openjfx</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
<artifactId>javafx-maven-plugin</artifactId>
|
<artifactId>javafx-maven-plugin</artifactId>
|
||||||
<version>0.0.8</version>
|
<version>0.0.8</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<mainClass>client.Main</mainClass>
|
<mainClass>client.Main</mainClass>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configLocation>../checkstyle.xml</configLocation>
|
<configLocation>../checkstyle.xml</configLocation>
|
||||||
<sourceDirectories>${project.basedir}</sourceDirectories>
|
<sourceDirectories>${project.basedir}</sourceDirectories>
|
||||||
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
|
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
|
||||||
<excludes>**/target/**</excludes>
|
<excludes>**/target/**</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>validate</id>
|
<id>validate</id>
|
||||||
<phase>validate</phase>
|
<phase>validate</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>check</goal>
|
<goal>check</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -31,27 +31,27 @@ import javafx.stage.Stage;
|
||||||
|
|
||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
|
|
||||||
private static final Injector INJECTOR = createInjector(new MyModule());
|
private static final Injector INJECTOR = createInjector(new MyModule());
|
||||||
private static final MyFXML FXML = new MyFXML(INJECTOR);
|
private static final MyFXML FXML = new MyFXML(INJECTOR);
|
||||||
|
|
||||||
public static void main(String[] args) throws URISyntaxException, IOException {
|
public static void main(String[] args) throws URISyntaxException, IOException {
|
||||||
launch();
|
launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
|
||||||
var serverUtils = INJECTOR.getInstance(ServerUtils.class);
|
var serverUtils = INJECTOR.getInstance(ServerUtils.class);
|
||||||
if (!serverUtils.isServerAvailable()) {
|
if (!serverUtils.isServerAvailable()) {
|
||||||
var msg = "Server needs to be started before the client, but it does not seem to be available. Shutting down.";
|
var msg = "Server needs to be started before the client, but it does not seem to be available. Shutting down.";
|
||||||
System.err.println(msg);
|
System.err.println(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml");
|
var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml");
|
||||||
var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml");
|
var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml");
|
||||||
|
|
||||||
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
|
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
|
||||||
mainCtrl.initialize(primaryStage, overview, add);
|
mainCtrl.initialize(primaryStage, overview, add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -83,14 +83,14 @@ public class AddQuoteCtrl {
|
||||||
|
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
switch (e.getCode()) {
|
switch (e.getCode()) {
|
||||||
case ENTER:
|
case ENTER:
|
||||||
ok();
|
ok();
|
||||||
break;
|
break;
|
||||||
case ESCAPE:
|
case ESCAPE:
|
||||||
cancel();
|
cancel();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,43 +35,43 @@ import jakarta.ws.rs.core.GenericType;
|
||||||
|
|
||||||
public class ServerUtils {
|
public class ServerUtils {
|
||||||
|
|
||||||
private static final String SERVER = "http://localhost:8080/";
|
private static final String SERVER = "http://localhost:8080/";
|
||||||
|
|
||||||
public void getQuotesTheHardWay() throws IOException, URISyntaxException {
|
public void getQuotesTheHardWay() throws IOException, URISyntaxException {
|
||||||
var url = new URI("http://localhost:8080/api/quotes").toURL();
|
var url = new URI("http://localhost:8080/api/quotes").toURL();
|
||||||
var is = url.openConnection().getInputStream();
|
var is = url.openConnection().getInputStream();
|
||||||
var br = new BufferedReader(new InputStreamReader(is));
|
var br = new BufferedReader(new InputStreamReader(is));
|
||||||
String line;
|
String line;
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
System.out.println(line);
|
System.out.println(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Quote> getQuotes() {
|
public List<Quote> getQuotes() {
|
||||||
return ClientBuilder.newClient(new ClientConfig()) //
|
return ClientBuilder.newClient(new ClientConfig()) //
|
||||||
.target(SERVER).path("api/quotes") //
|
.target(SERVER).path("api/quotes") //
|
||||||
.request(APPLICATION_JSON) //
|
.request(APPLICATION_JSON) //
|
||||||
.get(new GenericType<List<Quote>>() {});
|
.get(new GenericType<List<Quote>>() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quote addQuote(Quote quote) {
|
public Quote addQuote(Quote quote) {
|
||||||
return ClientBuilder.newClient(new ClientConfig()) //
|
return ClientBuilder.newClient(new ClientConfig()) //
|
||||||
.target(SERVER).path("api/quotes") //
|
.target(SERVER).path("api/quotes") //
|
||||||
.request(APPLICATION_JSON) //
|
.request(APPLICATION_JSON) //
|
||||||
.post(Entity.entity(quote, APPLICATION_JSON), Quote.class);
|
.post(Entity.entity(quote, APPLICATION_JSON), Quote.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isServerAvailable() {
|
public boolean isServerAvailable() {
|
||||||
try {
|
try {
|
||||||
ClientBuilder.newClient(new ClientConfig()) //
|
ClientBuilder.newClient(new ClientConfig()) //
|
||||||
.target(SERVER) //
|
.target(SERVER) //
|
||||||
.request(APPLICATION_JSON) //
|
.request(APPLICATION_JSON) //
|
||||||
.get();
|
.get();
|
||||||
} catch (ProcessingException e) {
|
} catch (ProcessingException e) {
|
||||||
if (e.getCause() instanceof ConnectException) {
|
if (e.getCause() instanceof ConnectException) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
184
commons/pom.xml
184
commons/pom.xml
|
|
@ -1,102 +1,102 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>csep</groupId>
|
<groupId>csep</groupId>
|
||||||
<artifactId>commons</artifactId>
|
<artifactId>commons</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<version.junit>5.10.1</version.junit>
|
<version.junit>5.10.1</version.junit>
|
||||||
<version.mockito>5.8.0</version.mockito>
|
<version.mockito>5.8.0</version.mockito>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.17.0</version>
|
<version>3.17.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.persistence</groupId>
|
<groupId>jakarta.persistence</groupId>
|
||||||
<artifactId>jakarta.persistence-api</artifactId>
|
<artifactId>jakarta.persistence-api</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- test -->
|
<!-- test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>${version.junit}</version>
|
<version>${version.junit}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>${version.junit}</version>
|
<version>${version.junit}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>${version.mockito}</version>
|
<version>${version.mockito}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.13.0</version>
|
<version>3.13.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<release>23</release>
|
<release>23</release>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configLocation>../checkstyle.xml</configLocation>
|
<configLocation>../checkstyle.xml</configLocation>
|
||||||
<sourceDirectories>${project.basedir}</sourceDirectories>
|
<sourceDirectories>${project.basedir}</sourceDirectories>
|
||||||
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
|
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
|
||||||
<excludes>**/target/**</excludes>
|
<excludes>**/target/**</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>validate</id>
|
<id>validate</id>
|
||||||
<phase>validate</phase>
|
<phase>validate</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>check</goal>
|
<goal>check</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- disable execution of Spring/JavaFX plugins (which would otherwise fail) -->
|
<!-- disable execution of Spring/JavaFX plugins (which would otherwise fail) -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<version>3.4.0</version>
|
<version>3.4.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<skip>true</skip>
|
<skip>true</skip>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.openjfx</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
<artifactId>javafx-maven-plugin</artifactId>
|
<artifactId>javafx-maven-plugin</artifactId>
|
||||||
<version>0.0.8</version>
|
<version>0.0.8</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<skip>true</skip>
|
<skip>true</skip>
|
||||||
<mainClass>ignore.Me</mainClass>
|
<mainClass>ignore.Me</mainClass>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -29,35 +29,35 @@ import jakarta.persistence.Id;
|
||||||
@Entity
|
@Entity
|
||||||
public class Person {
|
public class Person {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
public long id;
|
public long id;
|
||||||
|
|
||||||
public String firstName;
|
public String firstName;
|
||||||
public String lastName;
|
public String lastName;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private Person() {
|
private Person() {
|
||||||
// for object mapper
|
// for object mapper
|
||||||
}
|
}
|
||||||
|
|
||||||
public Person(String firstName, String lastName) {
|
public Person(String firstName, String lastName) {
|
||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return EqualsBuilder.reflectionEquals(this, obj);
|
return EqualsBuilder.reflectionEquals(this, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return HashCodeBuilder.reflectionHashCode(this);
|
return HashCodeBuilder.reflectionHashCode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
|
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -31,36 +31,36 @@ import jakarta.persistence.OneToOne;
|
||||||
@Entity
|
@Entity
|
||||||
public class Quote {
|
public class Quote {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
public long id;
|
public long id;
|
||||||
|
|
||||||
@OneToOne(cascade = CascadeType.PERSIST)
|
@OneToOne(cascade = CascadeType.PERSIST)
|
||||||
public Person person;
|
public Person person;
|
||||||
public String quote;
|
public String quote;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private Quote() {
|
private Quote() {
|
||||||
// for object mappers
|
// for object mappers
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quote(Person person, String quote) {
|
public Quote(Person person, String quote) {
|
||||||
this.person = person;
|
this.person = person;
|
||||||
this.quote = quote;
|
this.quote = quote;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return EqualsBuilder.reflectionEquals(this, obj);
|
return EqualsBuilder.reflectionEquals(this, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return HashCodeBuilder.reflectionHashCode(this);
|
return HashCodeBuilder.reflectionHashCode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
|
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -23,34 +23,34 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class PersonTest {
|
public class PersonTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkConstructor() {
|
public void checkConstructor() {
|
||||||
var p = new Person("f", "l");
|
var p = new Person("f", "l");
|
||||||
assertEquals("f", p.firstName);
|
assertEquals("f", p.firstName);
|
||||||
assertEquals("l", p.lastName);
|
assertEquals("l", p.lastName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsHashCode() {
|
public void equalsHashCode() {
|
||||||
var a = new Person("a", "b");
|
var a = new Person("a", "b");
|
||||||
var b = new Person("a", "b");
|
var b = new Person("a", "b");
|
||||||
assertEquals(a, b);
|
assertEquals(a, b);
|
||||||
assertEquals(a.hashCode(), b.hashCode());
|
assertEquals(a.hashCode(), b.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notEqualsHashCode() {
|
public void notEqualsHashCode() {
|
||||||
var a = new Person("a", "b");
|
var a = new Person("a", "b");
|
||||||
var b = new Person("a", "c");
|
var b = new Person("a", "c");
|
||||||
assertNotEquals(a, b);
|
assertNotEquals(a, b);
|
||||||
assertNotEquals(a.hashCode(), b.hashCode());
|
assertNotEquals(a.hashCode(), b.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hasToString() {
|
public void hasToString() {
|
||||||
var actual = new Person("a", "b").toString();
|
var actual = new Person("a", "b").toString();
|
||||||
assertTrue(actual.contains(Person.class.getSimpleName()));
|
assertTrue(actual.contains(Person.class.getSimpleName()));
|
||||||
assertTrue(actual.contains("\n"));
|
assertTrue(actual.contains("\n"));
|
||||||
assertTrue(actual.contains("firstName"));
|
assertTrue(actual.contains("firstName"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -23,36 +23,36 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class QuoteTest {
|
public class QuoteTest {
|
||||||
|
|
||||||
private static final Person SOME_PERSON = new Person("a", "b");
|
private static final Person SOME_PERSON = new Person("a", "b");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkConstructor() {
|
public void checkConstructor() {
|
||||||
var q = new Quote(SOME_PERSON, "q");
|
var q = new Quote(SOME_PERSON, "q");
|
||||||
assertEquals(SOME_PERSON, q.person);
|
assertEquals(SOME_PERSON, q.person);
|
||||||
assertEquals("q", q.quote);
|
assertEquals("q", q.quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsHashCode() {
|
public void equalsHashCode() {
|
||||||
var a = new Quote(new Person("a", "b"), "c");
|
var a = new Quote(new Person("a", "b"), "c");
|
||||||
var b = new Quote(new Person("a", "b"), "c");
|
var b = new Quote(new Person("a", "b"), "c");
|
||||||
assertEquals(a, b);
|
assertEquals(a, b);
|
||||||
assertEquals(a.hashCode(), b.hashCode());
|
assertEquals(a.hashCode(), b.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notEqualsHashCode() {
|
public void notEqualsHashCode() {
|
||||||
var a = new Quote(new Person("a", "b"), "c");
|
var a = new Quote(new Person("a", "b"), "c");
|
||||||
var b = new Quote(new Person("a", "b"), "d");
|
var b = new Quote(new Person("a", "b"), "d");
|
||||||
assertNotEquals(a, b);
|
assertNotEquals(a, b);
|
||||||
assertNotEquals(a.hashCode(), b.hashCode());
|
assertNotEquals(a.hashCode(), b.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hasToString() {
|
public void hasToString() {
|
||||||
var actual = new Quote(new Person("a", "b"), "c").toString();
|
var actual = new Quote(new Person("a", "b"), "c").toString();
|
||||||
assertTrue(actual.contains(Quote.class.getSimpleName()));
|
assertTrue(actual.contains(Quote.class.getSimpleName()));
|
||||||
assertTrue(actual.contains("\n"));
|
assertTrue(actual.contains("\n"));
|
||||||
assertTrue(actual.contains("person"));
|
assertTrue(actual.contains("person"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
138
server/pom.xml
138
server/pom.xml
|
|
@ -1,76 +1,76 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.5.7</version>
|
<version>3.5.7</version>
|
||||||
<relativePath /> <!-- lookup parent from repository -->
|
<relativePath /> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>csep</groupId>
|
<groupId>csep</groupId>
|
||||||
<artifactId>server</artifactId>
|
<artifactId>server</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>25</java.version>
|
<java.version>25</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>csep</groupId>
|
<groupId>csep</groupId>
|
||||||
<artifactId>commons</artifactId>
|
<artifactId>commons</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- test -->
|
<!-- test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configLocation>../checkstyle.xml</configLocation>
|
<configLocation>../checkstyle.xml</configLocation>
|
||||||
<sourceDirectories>${project.basedir}</sourceDirectories>
|
<sourceDirectories>${project.basedir}</sourceDirectories>
|
||||||
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
|
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
|
||||||
<excludes>**/target/**</excludes>
|
<excludes>**/target/**</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>validate</id>
|
<id>validate</id>
|
||||||
<phase>validate</phase>
|
<phase>validate</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>check</goal>
|
<goal>check</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -30,23 +30,23 @@ import commons.Person;
|
||||||
@RequestMapping("/api/people")
|
@RequestMapping("/api/people")
|
||||||
public class PersonListingController {
|
public class PersonListingController {
|
||||||
|
|
||||||
private List<Person> people = new LinkedList<>();
|
private List<Person> people = new LinkedList<>();
|
||||||
|
|
||||||
public PersonListingController() {
|
public PersonListingController() {
|
||||||
people.add(new Person("Mickey", "Mouse"));
|
people.add(new Person("Mickey", "Mouse"));
|
||||||
people.add(new Person("Donald", "Duck"));
|
people.add(new Person("Donald", "Duck"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public List<Person> list() {
|
public List<Person> list() {
|
||||||
return people;
|
return people;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/")
|
@PostMapping("/")
|
||||||
public List<Person> add(@RequestBody Person p) {
|
public List<Person> add(@RequestBody Person p) {
|
||||||
if (!people.contains(p)) {
|
if (!people.contains(p)) {
|
||||||
people.add(p);
|
people.add(p);
|
||||||
}
|
}
|
||||||
return people;
|
return people;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,28 +26,28 @@ import commons.Person;
|
||||||
|
|
||||||
public class PersonListingControllerTest {
|
public class PersonListingControllerTest {
|
||||||
|
|
||||||
private static final Person MICKEY = new Person("Mickey", "Mouse");
|
private static final Person MICKEY = new Person("Mickey", "Mouse");
|
||||||
private static final Person DONALD = new Person("Donald", "Duck");
|
private static final Person DONALD = new Person("Donald", "Duck");
|
||||||
private static final Person SCROOGE = new Person("Scrooge", "McDuck");
|
private static final Person SCROOGE = new Person("Scrooge", "McDuck");
|
||||||
|
|
||||||
private PersonListingController sut;
|
private PersonListingController sut;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
sut = new PersonListingController();
|
sut = new PersonListingController();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void containsTwoDefaultNames() {
|
public void containsTwoDefaultNames() {
|
||||||
var actual = sut.list();
|
var actual = sut.list();
|
||||||
var expected = List.of(MICKEY, DONALD);
|
var expected = List.of(MICKEY, DONALD);
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canAddPeople() {
|
public void canAddPeople() {
|
||||||
var actual = sut.add(SCROOGE);
|
var actual = sut.add(SCROOGE);
|
||||||
var expected = List.of(MICKEY, DONALD, SCROOGE);
|
var expected = List.of(MICKEY, DONALD, SCROOGE);
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue