-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
231 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com) | ||
SPDX-FileContributor: Sebastian Thomschke | ||
SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
<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>com.vegardit.maven</groupId> | ||
<artifactId>vegardit-maven-parent</artifactId> | ||
<version>5.0.1-SNAPSHOT</version> | ||
<relativePath>../../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>vegardit-maven-parent.test</artifactId> | ||
|
||
<properties> | ||
<maven.deploy.skip>true</maven.deploy.skip> | ||
<java.version.unit-tests>21</java.version.unit-tests> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit</groupId> | ||
<artifactId>junit-bom</artifactId> | ||
<version>5.11.0</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
77 changes: 77 additions & 0 deletions
77
src/test/project/src/main/java/com/vegardit/maven/parent/test/Shape.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.vegardit.maven.parent.test; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Sebastian Thomschke | ||
*/ | ||
public abstract sealed class Shape { | ||
|
||
public static final class Circle extends Shape { | ||
private final double radius; | ||
|
||
public Circle(final double radius) { | ||
this.radius = radius; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
final Circle circle = (Circle) o; | ||
return Double.compare(circle.radius, radius) == 0; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(radius); | ||
} | ||
|
||
public double radius() { | ||
return radius; | ||
} | ||
} | ||
|
||
public static final class Rectangle extends Shape { | ||
private final double length; | ||
private final double width; | ||
|
||
public Rectangle(final double length, final double width) { | ||
this.length = length; | ||
this.width = width; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
final Rectangle rectangle = (Rectangle) o; | ||
return Double.compare(rectangle.length, length) == 0 && Double.compare(rectangle.width, width) == 0; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(length, width); | ||
} | ||
|
||
public double length() { | ||
return length; | ||
} | ||
|
||
public double width() { | ||
return width; | ||
} | ||
} | ||
|
||
public static String describeShape(final Shape shape) { | ||
if (shape instanceof final Circle c) | ||
return "Circle with radius: " + c.radius(); | ||
else if (shape instanceof final Rectangle r) | ||
return "Rectangle with length: " + r.length() + " and width: " + r.width(); | ||
return "Unknown shape"; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/project/src/test/java/com/vegardit/maven/parent/test/RuntimeJavaVersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.vegardit.maven.parent.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* @author Sebastian Thomschke | ||
*/ | ||
class RuntimeJavaVersionTest { | ||
|
||
/** | ||
* This tests if the following config in the pom.xml is effective | ||
* <pre>{@code | ||
* <properties> | ||
* <java.version.unit-tests>21</java.version.unit-tests> | ||
* </properties> | ||
* }</pre> | ||
*/ | ||
@Test | ||
void ensureJava21IsUsed() { | ||
final String javaVersion = System.getProperty("java.version"); | ||
System.out.println("java.version = " + javaVersion); | ||
assertTrue(javaVersion.startsWith("21."), "Java 21 is expected for unit tests."); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/test/project/src/test/java/com/vegardit/maven/parent/test/ShapeTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.vegardit.maven.parent.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.vegardit.maven.parent.test.Shape.Circle; | ||
import com.vegardit.maven.parent.test.Shape.Rectangle; | ||
|
||
/** | ||
* @author Sebastian Thomschke | ||
*/ | ||
class ShapeTests { | ||
private Shape circle; | ||
private Shape rectangle; | ||
|
||
@BeforeEach | ||
void setup() { | ||
circle = new Circle(5.0); | ||
rectangle = new Rectangle(10.0, 20.0); | ||
} | ||
|
||
@Test | ||
void testDescribeCircle() { | ||
final String description = Shape.describeShape(circle); | ||
assertEquals("Circle with radius: 5.0", description); | ||
} | ||
|
||
@Test | ||
void testDescribeRectangle() { | ||
final String description = Shape.describeShape(rectangle); | ||
assertEquals("Rectangle with length: 10.0 and width: 20.0", description); | ||
} | ||
} |