-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
27f31b2
commit d741095
Showing
20 changed files
with
365 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# Linux start script should use lf | ||
/gradlew text eol=lf | ||
|
||
# These are Windows script files and should use crlf | ||
*.bat text eol=crlf | ||
|
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,5 @@ | ||
# Ignore Gradle project-specific cache directory | ||
.gradle | ||
|
||
# Ignore Gradle build output directory | ||
build |
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,45 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
* | ||
* This generated file contains a sample Java application project to get you started. | ||
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.3/userguide/building_java_projects.html in the Gradle documentation. | ||
* This project uses @Incubating APIs which are subject to change. | ||
*/ | ||
|
||
plugins { | ||
// Apply the application plugin to add support for building a CLI application in Java. | ||
id 'application' | ||
} | ||
|
||
repositories { | ||
// Use Maven Central for resolving dependencies. | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
// This dependency is used by the application. | ||
implementation 'com.google.guava:guava:32.1.1-jre' | ||
testImplementation "org.assertj:assertj-core:3.25.0" | ||
} | ||
|
||
testing { | ||
suites { | ||
// Configure the built-in test suite | ||
test { | ||
// Use JUnit Jupiter test framework | ||
useJUnitJupiter('5.9.3') | ||
} | ||
} | ||
} | ||
|
||
// Apply a specific Java toolchain to ease working on different environments. | ||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
|
||
application { | ||
// Define the main class for the application. | ||
mainClass = 'records.App' | ||
} |
Empty file.
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,14 @@ | ||
/* | ||
* This Java source file was generated by the Gradle 'init' task. | ||
*/ | ||
package records; | ||
|
||
public class App { | ||
public String getGreeting() { | ||
return "Hello World!"; | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println(new App().getGreeting()); | ||
} | ||
} |
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,14 @@ | ||
/* | ||
* This Java source file was generated by the Gradle 'init' task. | ||
*/ | ||
package records; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class AppTest { | ||
@Test void appHasAGreeting() { | ||
App classUnderTest = new App(); | ||
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting"); | ||
} | ||
} |
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,94 @@ | ||
package records; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
// https://www.baeldung.com/java-record-keyword | ||
@DisplayName("#record") | ||
class recordTest { | ||
|
||
@DisplayName("it should be instantiated") | ||
@Test | ||
void test1() { | ||
|
||
// given | ||
record Person(String name) {} | ||
; | ||
|
||
// when | ||
Person john = new Person("john"); | ||
|
||
// then | ||
assertEquals(john.name(), "john"); | ||
} | ||
|
||
@DisplayName("it cannot be mutated") | ||
@Test | ||
void test2() { | ||
|
||
// given | ||
record Person(String name) {} | ||
; | ||
Person john = new Person("john"); | ||
|
||
// when | ||
// Cannot assign a value to final variable 'name' | ||
// john.name = "Mary"; | ||
|
||
// then | ||
assertEquals(john.name(), "john"); | ||
} | ||
|
||
@DisplayName("it can be compared") | ||
@Nested | ||
class comparison { | ||
@DisplayName("using equals") | ||
@Test | ||
void test3() { | ||
|
||
// given | ||
record Person(String name) {} | ||
; | ||
Person johnDoe = new Person("john"); | ||
Person johnWayne = new Person("john"); | ||
|
||
// when | ||
// then | ||
assertEquals(johnDoe, johnWayne); | ||
} | ||
|
||
@DisplayName("using hasCode") | ||
@Test | ||
void test3b() { | ||
|
||
// given | ||
record Person(String name) {} | ||
; | ||
Person johnDoe = new Person("john"); | ||
Person johnWayne = new Person("john"); | ||
|
||
// when | ||
// then | ||
assertEquals(johnDoe.hashCode(), johnWayne.hashCode()); | ||
} | ||
} | ||
|
||
@DisplayName("it can be serialized") | ||
@Test | ||
void test4() { | ||
|
||
// given | ||
record Person(String name) {} | ||
; | ||
Person john = new Person("john"); | ||
|
||
// when | ||
String data = john.toString(); | ||
|
||
// then | ||
assertEquals(data, "Person[name=john]"); | ||
} | ||
} |
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,6 @@ | ||
# This file was generated by the Gradle 'init' task. | ||
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties | ||
|
||
org.gradle.parallel=true | ||
org.gradle.caching=true | ||
|
Binary file not shown.
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,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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,15 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
* | ||
* The settings file is used to specify which projects to include in your build. | ||
* For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.3/userguide/building_swift_projects.html in the Gradle documentation. | ||
* This project uses @Incubating APIs which are subject to change. | ||
*/ | ||
|
||
plugins { | ||
// Apply the foojay-resolver plugin to allow automatic download of JDKs | ||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' | ||
} | ||
|
||
rootProject.name = 'record' | ||
include('app') |
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,9 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# Linux start script should use lf | ||
/gradlew text eol=lf | ||
|
||
# These are Windows script files and should use crlf | ||
*.bat text eol=crlf | ||
|
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,5 @@ | ||
# Ignore Gradle project-specific cache directory | ||
.gradle | ||
|
||
# Ignore Gradle build output directory | ||
build |
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,44 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
* | ||
* This generated file contains a sample Java application project to get you started. | ||
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.3/userguide/building_java_projects.html in the Gradle documentation. | ||
* This project uses @Incubating APIs which are subject to change. | ||
*/ | ||
|
||
plugins { | ||
// Apply the application plugin to add support for building a CLI application in Java. | ||
application | ||
} | ||
|
||
repositories { | ||
// Use Maven Central for resolving dependencies. | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
// This dependency is used by the application. | ||
implementation("com.google.guava:guava:32.1.1-jre") | ||
} | ||
|
||
testing { | ||
suites { | ||
// Configure the built-in test suite | ||
val test by getting(JvmTestSuite::class) { | ||
// Use JUnit Jupiter test framework | ||
useJUnitJupiter("5.9.3") | ||
} | ||
} | ||
} | ||
|
||
// Apply a specific Java toolchain to ease working on different environments. | ||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(17)) | ||
} | ||
} | ||
|
||
application { | ||
// Define the main class for the application. | ||
mainClass.set("sorting.App") | ||
} |
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,14 @@ | ||
/* | ||
* This Java source file was generated by the Gradle 'init' task. | ||
*/ | ||
package sorting; | ||
|
||
public class App { | ||
public String getGreeting() { | ||
return "Hello World!"; | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println(new App().getGreeting()); | ||
} | ||
} |
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,56 @@ | ||
package sorting; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class AppTest { | ||
|
||
public class Player implements Comparable<Player> { | ||
private int ranking; | ||
private String name; | ||
private int age; | ||
public Player(int ranking, String name, int age){ | ||
this.ranking = ranking; | ||
this.name = name; | ||
this.age = age; | ||
} | ||
private int getRanking(){ | ||
return this.ranking; | ||
} | ||
|
||
@Override | ||
public int compareTo(Player otherPlayer) { | ||
return Integer.compare(getRanking(), otherPlayer.getRanking()); | ||
} | ||
|
||
} | ||
|
||
@DisplayName("Using Comparable interface") | ||
@Test void sortByProperty() { | ||
// given | ||
List<Player> footballTeam = new ArrayList<>(); | ||
Player john = new Player(2, "John", 20); | ||
Player roger = new Player(1, "Roger", 22); | ||
Player steven = new Player(3, "Steven", 24); | ||
footballTeam.add(john); | ||
footballTeam.add(roger); | ||
footballTeam.add(steven); | ||
|
||
// when | ||
Collections.sort(footballTeam); | ||
|
||
// then | ||
List<Player> expected = new ArrayList<>(); | ||
expected.add(roger); | ||
expected.add(john); | ||
expected.add(steven); | ||
|
||
assertEquals(footballTeam, expected); | ||
} | ||
} |
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,6 @@ | ||
# This file was generated by the Gradle 'init' task. | ||
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties | ||
|
||
org.gradle.parallel=true | ||
org.gradle.caching=true | ||
|
Binary file not shown.
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,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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,15 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
* | ||
* The settings file is used to specify which projects to include in your build. | ||
* For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.3/userguide/building_swift_projects.html in the Gradle documentation. | ||
* This project uses @Incubating APIs which are subject to change. | ||
*/ | ||
|
||
plugins { | ||
// Apply the foojay-resolver plugin to allow automatic download of JDKs | ||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0" | ||
} | ||
|
||
rootProject.name = "sorting" | ||
include("app") |