Skip to content

Commit

Permalink
Merge pull request #38 from miniwolf/upgrade-gradle-java-kotlin-fix-t…
Browse files Browse the repository at this point in the history
…ests

Upgrade gradle java kotlin fix tests
  • Loading branch information
miniwolf authored Jun 23, 2024
2 parents e1f268a + 37745e9 commit 3dcfc1d
Show file tree
Hide file tree
Showing 36 changed files with 636 additions and 380 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
image: Visual Studio 2019
build_script:
- set JAVA_HOME="C:\Program Files\Java\jdk16"
- set JAVA_HOME="C:\Program Files\Java\jdk21"
test_script:
- ./gradlew.bat clean test --info
notifications:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ users
*.config
*.fagi
.gradle/*
*/build/*
*/build/*
buildSrc/.gradle
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: java
install: true
jdk: openjdk16
jdk: openjdk21

matrix:
include:
Expand Down
79 changes: 0 additions & 79 deletions build.gradle

This file was deleted.

50 changes: 50 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import com.fagi.test.TestResultsService
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

allprojects {
group = "com.fagi"
version = "1.0-snapshot"
}

subprojects {
apply(plugin = "java")

repositories {
mavenCentral()
}

tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_21.toString()
targetCompatibility = JavaVersion.VERSION_21.toString()
}
}

// Register the custom build service
val testResultsServiceProvider = gradle.sharedServices.registerIfAbsent("testResultsService", TestResultsService::class.java) {}

// Configure all projects to use the custom build service
allprojects {
tasks.withType<Test> {
testLogging {
events = setOf(
TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR
)
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}

// After a test suite is done running this is called to register the result
afterSuite(KotlinClosure2<TestDescriptor, TestResult, Unit>({ desc, result ->
if (desc.parent == null) {
val testResultsService = testResultsServiceProvider.get()
testResultsService.addTestResult(desc, result)
}
}))
}
}
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.24"
}

repositories {
mavenCentral()
}
36 changes: 36 additions & 0 deletions buildSrc/src/main/kotlin/com/fagi/test/TestResultsService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.fagi.test

import groovy.time.TimeCategory
import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import org.gradle.api.tasks.testing.TestDescriptor
import org.gradle.api.tasks.testing.TestResult
import java.util.*

abstract class TestResultsService : BuildService<BuildServiceParameters.None>, AutoCloseable {
private val testsResults = mutableListOf<String>()

fun addTestResult(desc: TestDescriptor, result: TestResult) {
val summary = "${desc.name} results: ${result.resultType} " +
"(" +
"${result.testCount} tests, " +
"${result.successfulTestCount} successes, " +
"${result.failedTestCount} failures, " +
"${result.skippedTestCount} skipped" +
") " +
"in ${TimeCategory.minus(Date(result.endTime), Date(result.startTime))}"
testsResults.add(summary)
}

override fun close() {
if (testsResults.isNotEmpty()) {
printResults(testsResults)
}
}

private fun printResults(allResults: List<String>) {
println(allResults.joinToString("\n\n") {
it.lines().joinToString("\n")
})
}
}
34 changes: 0 additions & 34 deletions fagiClient/build.gradle

This file was deleted.

36 changes: 36 additions & 0 deletions fagiClient/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
id("application")
id("org.openjfx.javafxplugin") version "0.1.0"
}

application {
mainClass.set("com.fagi.main.FagiApp")
}

repositories {
mavenCentral()
flatDir {
dirs("libs")
}
}

tasks.test {
useJUnitPlatform()
}

javafx {
version = "21"
modules = mutableListOf("javafx.controls", "javafx.fxml", "javafx.web", "javafx.graphics")
}

dependencies {
implementation(project(":shared"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
testImplementation("org.mockito:mockito-core:5.12.0")
testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("org.testfx:testfx-core:4.0.18")
testImplementation("org.testfx:testfx-junit5:4.0.18")
testImplementation("org.openjfx:javafx-swing:21.0.3")
testImplementation("org.testfx:openjfx-monocle:21.0.2")
}
3 changes: 2 additions & 1 deletion fagiClient/src/main/java/com/fagi/network/ChatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.fagi.main.FagiApp;
import com.fagi.model.CreateUser;
import com.fagi.model.InviteCode;
import com.fagi.model.Logout;
import com.fagi.model.UserNameAvailableRequest;
import com.fagi.responses.AllIsWell;
Expand Down Expand Up @@ -83,7 +84,7 @@ public static boolean handleCreateUser(
return false;
}

CreateUser createUser = new CreateUser(username, password, toInteger(inviteCode));
CreateUser createUser = new CreateUser(username, password, new InviteCode(inviteCode));
communication.sendObject(createUser);

Response response = communication.getNextResponse();
Expand Down
24 changes: 10 additions & 14 deletions fagiClient/src/test/java/com/fagi/guitests/ConversationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,16 @@ void PressingEnterInConversationField_WillSendMessageToServer(FxRobot robot) {
robot
.clickOn("#conversationTextarea")
.write("Hello")
.press(KeyCode.ENTER);
.push(KeyCode.ENTER);
WaitForAsyncUtils.waitForFxEvents();

var textMessageCaptor = ArgumentCaptor.forClass(TextMessage.class);
Mockito
.verify(communication, Mockito.times(4))
.verify(communication, Mockito.times(1))
.sendObject(textMessageCaptor.capture());

var message = textMessageCaptor
.getAllValues()
.get(3);
.getValue();
Assertions.assertEquals("Hello\n", message.data(), "Message should be send to server");
}

Expand All @@ -248,7 +247,7 @@ void SendMessageFromConversation_ClearsMessageField(FxRobot robot) {
robot
.clickOn("#conversationTextarea")
.write("Hello")
.press(KeyCode.ENTER);
.push(KeyCode.ENTER);
WaitForAsyncUtils.waitForFxEvents();

FxAssert.verifyThat("#conversationTextarea",
Expand Down Expand Up @@ -277,7 +276,7 @@ void PressingShiftEnter_WillInsertNewLine(FxRobot robot) {
robot
.clickOn("#conversationTextarea")
.write("Hello")
.press(KeyCode.SHIFT, KeyCode.ENTER)
.push(KeyCode.SHIFT, KeyCode.ENTER)
.write("Dimmer");
WaitForAsyncUtils.waitForFxEvents();

Expand Down Expand Up @@ -307,17 +306,16 @@ void VerifyTextMessageFormat(FxRobot robot) {
robot
.clickOn("#conversationTextarea")
.write("Hello")
.press(KeyCode.ENTER);
.push(KeyCode.ENTER);
WaitForAsyncUtils.waitForFxEvents();

var textMessageCaptor = ArgumentCaptor.forClass(TextMessage.class);
Mockito
.verify(communication, Mockito.times(4))
.verify(communication, Mockito.times(1))
.sendObject(textMessageCaptor.capture());

var message = textMessageCaptor
.getAllValues()
.get(3);
.getValue();
Assertions.assertAll(() -> Assertions.assertEquals("Hello\n",
message.data(),
"Message should be send to server"
Expand Down Expand Up @@ -392,7 +390,7 @@ public void start(Stage stage) {
var fagiApp = Mockito.mock(FagiApp.class);
var draggable = new Draggable(stage);

communication = Mockito.mock(Communication.class);
communication = Mockito.spy(Communication.class);
inputHandler = Mockito.mock(InputHandler.class);

Mockito
Expand Down Expand Up @@ -427,11 +425,9 @@ public void start(Stage stage) {
.doAnswer(invocationOnMock -> new MasterLogin(fagiApp, communication, stage, draggable))
.when(fagiApp)
.showLoginScreen();

var comspy = Mockito.spy(communication);
Mockito
.doNothing()
.when(comspy)
.when(communication)
.sendObject(Mockito.any());

threadPool.startThread(inputHandler, "InputHandler - ConversationTests");
Expand Down
Loading

0 comments on commit 3dcfc1d

Please sign in to comment.