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:
Zhongheng Liu 2025-11-16 21:10:55 +01:00
commit ac8f3f2699
13 changed files with 571 additions and 492 deletions

View file

@ -1,13 +1,92 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<!-- CheckStyle settings -->
<module name = "Checker">
<module name="TreeWalker">
<module name="UnusedImports" />
</module>
<module name="TreeWalker">
<!-- 1. camelCase for identifiers -->
<module name="LocalVariableName">
<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>
<!-- TODO: decide in your team with other checkers to add! -->
<!-- 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>
</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>
</module>

View file

@ -1,130 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>
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">
<modelVersion>4.0.0</modelVersion>
<groupId>csep</groupId>
<artifactId>client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>csep</groupId>
<artifactId>client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.junit>5.10.1</version.junit>
<version.mockito>5.8.0</version.mockito>
<version.jersey>3.1.9</version.jersey>
<version.jfx>25.0.1</version.jfx>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.junit>5.10.1</version.junit>
<version.mockito>5.8.0</version.mockito>
<version.jersey>3.1.9</version.jersey>
<version.jfx>25.0.1</version.jfx>
</properties>
<dependencies>
<dependency>
<groupId>csep</groupId>
<artifactId>commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependencies>
<dependency>
<groupId>csep</groupId>
<artifactId>commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>7.0.0</version>
</dependency>
<!-- JavaFX -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${version.jfx}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${version.jfx}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>${version.jfx}</version>
</dependency>
<!-- JavaFX -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${version.jfx}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${version.jfx}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>${version.jfx}</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${version.mockito}</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${version.mockito}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>23</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>client.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
<sourceDirectories>${project.basedir}</sourceDirectories>
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
<excludes>**/target/**</excludes>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>23</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>client.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
<sourceDirectories>${project.basedir}</sourceDirectories>
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
<excludes>**/target/**</excludes>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -31,27 +31,27 @@ import javafx.stage.Stage;
public class Main extends Application {
private static final Injector INJECTOR = createInjector(new MyModule());
private static final MyFXML FXML = new MyFXML(INJECTOR);
private static final Injector INJECTOR = createInjector(new MyModule());
private static final MyFXML FXML = new MyFXML(INJECTOR);
public static void main(String[] args) throws URISyntaxException, IOException {
launch();
}
public static void main(String[] args) throws URISyntaxException, IOException {
launch();
}
@Override
public void start(Stage primaryStage) throws Exception {
@Override
public void start(Stage primaryStage) throws Exception {
var serverUtils = INJECTOR.getInstance(ServerUtils.class);
if (!serverUtils.isServerAvailable()) {
var msg = "Server needs to be started before the client, but it does not seem to be available. Shutting down.";
System.err.println(msg);
return;
}
var serverUtils = INJECTOR.getInstance(ServerUtils.class);
if (!serverUtils.isServerAvailable()) {
var msg = "Server needs to be started before the client, but it does not seem to be available. Shutting down.";
System.err.println(msg);
return;
}
var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml");
var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml");
var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml");
var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml");
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
mainCtrl.initialize(primaryStage, overview, add);
}
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
mainCtrl.initialize(primaryStage, overview, add);
}
}

View file

@ -83,14 +83,14 @@ public class AddQuoteCtrl {
public void keyPressed(KeyEvent e) {
switch (e.getCode()) {
case ENTER:
ok();
break;
case ESCAPE:
cancel();
break;
default:
break;
case ENTER:
ok();
break;
case ESCAPE:
cancel();
break;
default:
break;
}
}
}

View file

@ -35,43 +35,43 @@ import jakarta.ws.rs.core.GenericType;
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 {
var url = new URI("http://localhost:8080/api/quotes").toURL();
var is = url.openConnection().getInputStream();
var br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
public void getQuotesTheHardWay() throws IOException, URISyntaxException {
var url = new URI("http://localhost:8080/api/quotes").toURL();
var is = url.openConnection().getInputStream();
var br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
public List<Quote> getQuotes() {
return ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER).path("api/quotes") //
.request(APPLICATION_JSON) //
.get(new GenericType<List<Quote>>() {});
}
public List<Quote> getQuotes() {
return ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER).path("api/quotes") //
.request(APPLICATION_JSON) //
.get(new GenericType<List<Quote>>() {});
}
public Quote addQuote(Quote quote) {
return ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER).path("api/quotes") //
.request(APPLICATION_JSON) //
.post(Entity.entity(quote, APPLICATION_JSON), Quote.class);
}
public Quote addQuote(Quote quote) {
return ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER).path("api/quotes") //
.request(APPLICATION_JSON) //
.post(Entity.entity(quote, APPLICATION_JSON), Quote.class);
}
public boolean isServerAvailable() {
try {
ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER) //
.request(APPLICATION_JSON) //
.get();
} catch (ProcessingException e) {
if (e.getCause() instanceof ConnectException) {
return false;
}
}
return true;
}
public boolean isServerAvailable() {
try {
ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER) //
.request(APPLICATION_JSON) //
.get();
} catch (ProcessingException e) {
if (e.getCause() instanceof ConnectException) {
return false;
}
}
return true;
}
}

View file

@ -1,102 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>
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">
<modelVersion>4.0.0</modelVersion>
<groupId>csep</groupId>
<artifactId>commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>csep</groupId>
<artifactId>commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.junit>5.10.1</version.junit>
<version.mockito>5.8.0</version.mockito>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.junit>5.10.1</version.junit>
<version.mockito>5.8.0</version.mockito>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${version.mockito}</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${version.mockito}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>23</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
<sourceDirectories>${project.basedir}</sourceDirectories>
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
<excludes>**/target/**</excludes>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>23</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
<sourceDirectories>${project.basedir}</sourceDirectories>
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
<excludes>**/target/**</excludes>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- disable execution of Spring/JavaFX plugins (which would otherwise fail) -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<skip>true</skip>
<mainClass>ignore.Me</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<!-- disable execution of Spring/JavaFX plugins (which would otherwise fail) -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<skip>true</skip>
<mainClass>ignore.Me</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -29,35 +29,35 @@ import jakarta.persistence.Id;
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long id;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long id;
public String firstName;
public String lastName;
public String firstName;
public String lastName;
@SuppressWarnings("unused")
private Person() {
// for object mapper
}
@SuppressWarnings("unused")
private Person() {
// for object mapper
}
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
}
}

View file

@ -31,36 +31,36 @@ import jakarta.persistence.OneToOne;
@Entity
public class Quote {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long id;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long id;
@OneToOne(cascade = CascadeType.PERSIST)
public Person person;
public String quote;
@OneToOne(cascade = CascadeType.PERSIST)
public Person person;
public String quote;
@SuppressWarnings("unused")
private Quote() {
// for object mappers
}
@SuppressWarnings("unused")
private Quote() {
// for object mappers
}
public Quote(Person person, String quote) {
this.person = person;
this.quote = quote;
}
public Quote(Person person, String quote) {
this.person = person;
this.quote = quote;
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
}
}

View file

@ -23,34 +23,34 @@ import org.junit.jupiter.api.Test;
public class PersonTest {
@Test
public void checkConstructor() {
var p = new Person("f", "l");
assertEquals("f", p.firstName);
assertEquals("l", p.lastName);
}
@Test
public void checkConstructor() {
var p = new Person("f", "l");
assertEquals("f", p.firstName);
assertEquals("l", p.lastName);
}
@Test
public void equalsHashCode() {
var a = new Person("a", "b");
var b = new Person("a", "b");
assertEquals(a, b);
assertEquals(a.hashCode(), b.hashCode());
}
@Test
public void equalsHashCode() {
var a = new Person("a", "b");
var b = new Person("a", "b");
assertEquals(a, b);
assertEquals(a.hashCode(), b.hashCode());
}
@Test
public void notEqualsHashCode() {
var a = new Person("a", "b");
var b = new Person("a", "c");
assertNotEquals(a, b);
assertNotEquals(a.hashCode(), b.hashCode());
}
@Test
public void notEqualsHashCode() {
var a = new Person("a", "b");
var b = new Person("a", "c");
assertNotEquals(a, b);
assertNotEquals(a.hashCode(), b.hashCode());
}
@Test
public void hasToString() {
var actual = new Person("a", "b").toString();
assertTrue(actual.contains(Person.class.getSimpleName()));
assertTrue(actual.contains("\n"));
assertTrue(actual.contains("firstName"));
}
@Test
public void hasToString() {
var actual = new Person("a", "b").toString();
assertTrue(actual.contains(Person.class.getSimpleName()));
assertTrue(actual.contains("\n"));
assertTrue(actual.contains("firstName"));
}
}

View file

@ -23,36 +23,36 @@ import org.junit.jupiter.api.Test;
public class QuoteTest {
private static final Person SOME_PERSON = new Person("a", "b");
private static final Person SOME_PERSON = new Person("a", "b");
@Test
public void checkConstructor() {
var q = new Quote(SOME_PERSON, "q");
assertEquals(SOME_PERSON, q.person);
assertEquals("q", q.quote);
}
@Test
public void checkConstructor() {
var q = new Quote(SOME_PERSON, "q");
assertEquals(SOME_PERSON, q.person);
assertEquals("q", q.quote);
}
@Test
public void equalsHashCode() {
var a = new Quote(new Person("a", "b"), "c");
var b = new Quote(new Person("a", "b"), "c");
assertEquals(a, b);
assertEquals(a.hashCode(), b.hashCode());
}
@Test
public void equalsHashCode() {
var a = new Quote(new Person("a", "b"), "c");
var b = new Quote(new Person("a", "b"), "c");
assertEquals(a, b);
assertEquals(a.hashCode(), b.hashCode());
}
@Test
public void notEqualsHashCode() {
var a = new Quote(new Person("a", "b"), "c");
var b = new Quote(new Person("a", "b"), "d");
assertNotEquals(a, b);
assertNotEquals(a.hashCode(), b.hashCode());
}
@Test
public void notEqualsHashCode() {
var a = new Quote(new Person("a", "b"), "c");
var b = new Quote(new Person("a", "b"), "d");
assertNotEquals(a, b);
assertNotEquals(a.hashCode(), b.hashCode());
}
@Test
public void hasToString() {
var actual = new Quote(new Person("a", "b"), "c").toString();
assertTrue(actual.contains(Quote.class.getSimpleName()));
assertTrue(actual.contains("\n"));
assertTrue(actual.contains("person"));
}
@Test
public void hasToString() {
var actual = new Quote(new Person("a", "b"), "c").toString();
assertTrue(actual.contains(Quote.class.getSimpleName()));
assertTrue(actual.contains("\n"));
assertTrue(actual.contains("person"));
}
}

View file

@ -1,76 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.7</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>csep</groupId>
<artifactId>server</artifactId>
<version>0.0.1-SNAPSHOT</version>
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.7</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>csep</groupId>
<artifactId>server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>25</java.version>
</properties>
<properties>
<java.version>25</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>csep</groupId>
<artifactId>commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>csep</groupId>
<artifactId>commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
<sourceDirectories>${project.basedir}</sourceDirectories>
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
<excludes>**/target/**</excludes>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
<sourceDirectories>${project.basedir}</sourceDirectories>
<includes>src/**/*.java,**/*.xml,**/*.yml</includes>
<excludes>**/target/**</excludes>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -30,23 +30,23 @@ import commons.Person;
@RequestMapping("/api/people")
public class PersonListingController {
private List<Person> people = new LinkedList<>();
private List<Person> people = new LinkedList<>();
public PersonListingController() {
people.add(new Person("Mickey", "Mouse"));
people.add(new Person("Donald", "Duck"));
}
public PersonListingController() {
people.add(new Person("Mickey", "Mouse"));
people.add(new Person("Donald", "Duck"));
}
@GetMapping("/")
public List<Person> list() {
return people;
}
@GetMapping("/")
public List<Person> list() {
return people;
}
@PostMapping("/")
public List<Person> add(@RequestBody Person p) {
if (!people.contains(p)) {
people.add(p);
}
return people;
}
@PostMapping("/")
public List<Person> add(@RequestBody Person p) {
if (!people.contains(p)) {
people.add(p);
}
return people;
}
}

View file

@ -26,28 +26,28 @@ import commons.Person;
public class PersonListingControllerTest {
private static final Person MICKEY = new Person("Mickey", "Mouse");
private static final Person DONALD = new Person("Donald", "Duck");
private static final Person SCROOGE = new Person("Scrooge", "McDuck");
private static final Person MICKEY = new Person("Mickey", "Mouse");
private static final Person DONALD = new Person("Donald", "Duck");
private static final Person SCROOGE = new Person("Scrooge", "McDuck");
private PersonListingController sut;
private PersonListingController sut;
@BeforeEach
public void setup() {
sut = new PersonListingController();
}
@BeforeEach
public void setup() {
sut = new PersonListingController();
}
@Test
public void containsTwoDefaultNames() {
var actual = sut.list();
var expected = List.of(MICKEY, DONALD);
assertEquals(expected, actual);
}
@Test
public void containsTwoDefaultNames() {
var actual = sut.list();
var expected = List.of(MICKEY, DONALD);
assertEquals(expected, actual);
}
@Test
public void canAddPeople() {
var actual = sut.add(SCROOGE);
var expected = List.of(MICKEY, DONALD, SCROOGE);
assertEquals(expected, actual);
}
@Test
public void canAddPeople() {
var actual = sut.add(SCROOGE);
var expected = List.of(MICKEY, DONALD, SCROOGE);
assertEquals(expected, actual);
}
}