From 09d251a02a2d0c33daf11c71bdd50fe93ae4ed00 Mon Sep 17 00:00:00 2001 From: kske Date: Sun, 9 Jan 2022 09:27:44 +0100 Subject: [PATCH 1/2] Add Jenkinsfile The Jenkinsfile performs packaging and testing on the project. When on the develop branch, a SonarQube analysis is conducted. --- Jenkinsfile | 41 +++++++++++++++++++++++++++++++++++++++++ core/pom.xml | 30 +++++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..7787aec --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,41 @@ +pipeline { + agent any + + options { + ansiColor('xterm') + } + + stages { + stage('Build') { + steps { + sh 'mvn -DskipTests clean package' + } + } + stage('Test') { + steps { + sh 'mvn test' + } + post { + always { + junit '*/target/surefire-reports/*.xml' + publishCoverage adapters: [jacocoAdapter(mergeToOneReport: true, path: '*/target/site/jacoco/jacoco.xml')] + } + } + } + stage('SonarQube Analysis') { + when { + branch 'develop' + } + steps { + withSonarQubeEnv('KSKE SonarQube') { + sh "$SONAR_MAVEN_GOAL" + } + } + } + } + post { + success { + archiveArtifacts artifacts: '*/target/event-bus-*.jar' + } + } +} diff --git a/core/pom.xml b/core/pom.xml index 629523e..e484f03 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -1,6 +1,4 @@ - + 4.0.0 event-bus-core @@ -26,14 +24,36 @@ - + + org.apache.maven.plugins maven-surefire-plugin 3.0.0-M5 - + + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + + prepare-agent + + + + report + test + + report + + + + + + \ No newline at end of file From ebb2191f4a37ca5de979cdc418fb951d1d8661fe Mon Sep 17 00:00:00 2001 From: kske Date: Sun, 9 Jan 2022 09:37:27 +0100 Subject: [PATCH 2/2] Make unit tests package-private --- core/pom.xml | 7 +++++++ core/src/test/java/dev/kske/eventbus/core/CancelTest.java | 6 +++--- core/src/test/java/dev/kske/eventbus/core/DeadTest.java | 6 +++--- .../test/java/dev/kske/eventbus/core/DispatchTest.java | 8 ++++---- .../test/java/dev/kske/eventbus/core/ExceptionTest.java | 6 +++--- .../java/dev/kske/eventbus/core/ExceptionWrapperTest.java | 4 ++-- core/src/test/java/dev/kske/eventbus/core/NestedTest.java | 6 +++--- .../src/test/java/dev/kske/eventbus/core/SimpleEvent.java | 2 +- .../test/java/dev/kske/eventbus/core/SimpleEventSub.java | 2 +- 9 files changed, 27 insertions(+), 20 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index e484f03..956667e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -31,6 +31,13 @@ org.apache.maven.plugins maven-surefire-plugin 3.0.0-M5 + + + ${argLine} + --add-opens dev.kske.eventbus.core/dev.kske.eventbus.core=ALL-UNNAMED + --add-opens dev.kske.eventbus.core/dev.kske.eventbus.core.handler=ALL-UNNAMED + + diff --git a/core/src/test/java/dev/kske/eventbus/core/CancelTest.java b/core/src/test/java/dev/kske/eventbus/core/CancelTest.java index 581f300..5f715c7 100644 --- a/core/src/test/java/dev/kske/eventbus/core/CancelTest.java +++ b/core/src/test/java/dev/kske/eventbus/core/CancelTest.java @@ -11,7 +11,7 @@ import org.junit.jupiter.api.*; * @author Leon Hofmeister * @since 0.1.0 */ -public class CancelTest { +class CancelTest { EventBus bus; int hits; @@ -22,7 +22,7 @@ public class CancelTest { * @since 0.1.0 */ @BeforeEach - public void registerListener() { + void registerListener() { bus = new EventBus(); bus.registerListener(this); } @@ -34,7 +34,7 @@ public class CancelTest { * @since 0.1.0 */ @Test - public void testCancellation() { + void testCancellation() { bus.dispatch(new SimpleEvent()); assertEquals(1, hits); } diff --git a/core/src/test/java/dev/kske/eventbus/core/DeadTest.java b/core/src/test/java/dev/kske/eventbus/core/DeadTest.java index ac4d862..ccef35c 100644 --- a/core/src/test/java/dev/kske/eventbus/core/DeadTest.java +++ b/core/src/test/java/dev/kske/eventbus/core/DeadTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test; * @author Kai S. K. Engelbart * @since 1.1.0 */ -public class DeadTest { +class DeadTest { EventBus bus = new EventBus(); String event = "This event has no handler"; @@ -22,7 +22,7 @@ public class DeadTest { * @since 1.1.0 */ @Test - public void testDeadEvent() { + void testDeadEvent() { bus.registerListener(this); bus.dispatch(event); assertTrue(deadEventHandled); @@ -36,7 +36,7 @@ public class DeadTest { * @since 1.1.0 */ @Test - public void testUnhandledDeadEvent() { + void testUnhandledDeadEvent() { bus.dispatch(event); } diff --git a/core/src/test/java/dev/kske/eventbus/core/DispatchTest.java b/core/src/test/java/dev/kske/eventbus/core/DispatchTest.java index 7e8e412..cfd4de1 100644 --- a/core/src/test/java/dev/kske/eventbus/core/DispatchTest.java +++ b/core/src/test/java/dev/kske/eventbus/core/DispatchTest.java @@ -12,7 +12,7 @@ import org.junit.jupiter.api.*; */ @Polymorphic @Priority(150) -public class DispatchTest { +class DispatchTest { EventBus bus; static int hits; @@ -23,7 +23,7 @@ public class DispatchTest { * @since 0.0.1 */ @BeforeEach - public void registerListener() { + void registerListener() { bus = new EventBus(); bus.registerListener(this); bus.registerListener(SimpleEvent.class, e -> { @@ -39,7 +39,7 @@ public class DispatchTest { * @since 0.0.1 */ @Test - public void testDispatch() { + void testDispatch() { bus.dispatch(new SimpleEventSub()); bus.dispatch(new SimpleEvent()); } @@ -50,7 +50,7 @@ public class DispatchTest { * @since 1.2.0 */ @Test - public void testDebugExecutionOrder() { + void testDebugExecutionOrder() { String executionOrder = bus.debugExecutionOrder(SimpleEvent.class); System.out.println(executionOrder); assertEquals( diff --git a/core/src/test/java/dev/kske/eventbus/core/ExceptionTest.java b/core/src/test/java/dev/kske/eventbus/core/ExceptionTest.java index fcc4b61..8bef526 100644 --- a/core/src/test/java/dev/kske/eventbus/core/ExceptionTest.java +++ b/core/src/test/java/dev/kske/eventbus/core/ExceptionTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test; * @author Kai S. K. Engelbart * @since 1.1.0 */ -public class ExceptionTest { +class ExceptionTest { EventBus bus = new EventBus(); String event = "This event will cause an exception"; @@ -23,7 +23,7 @@ public class ExceptionTest { * @since 1.1.0 */ @Test - public void testExceptionEvent() { + void testExceptionEvent() { bus.registerListener(this); bus.registerListener(new ExceptionListener()); bus.dispatch(event); @@ -38,7 +38,7 @@ public class ExceptionTest { * @since 1.1.0 */ @Test - public void testUnhandledExceptionEvent() { + void testUnhandledExceptionEvent() { bus.registerListener(this); bus.dispatch(event); bus.removeListener(this); diff --git a/core/src/test/java/dev/kske/eventbus/core/ExceptionWrapperTest.java b/core/src/test/java/dev/kske/eventbus/core/ExceptionWrapperTest.java index 56f2bd9..04b4a69 100644 --- a/core/src/test/java/dev/kske/eventbus/core/ExceptionWrapperTest.java +++ b/core/src/test/java/dev/kske/eventbus/core/ExceptionWrapperTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test; * @author Kai S. K. Engelbart * @since 1.2.1 */ -public class ExceptionWrapperTest { +class ExceptionWrapperTest { EventBus bus = new EventBus(); String event = "This event will cause an exception"; @@ -21,7 +21,7 @@ public class ExceptionWrapperTest { * @since 1.2.1 */ @Test - public void testExceptionWrapper() { + void testExceptionWrapper() { bus.registerListener(this); assertThrows(ExceptionWrapper.class, () -> bus.dispatch(event)); } diff --git a/core/src/test/java/dev/kske/eventbus/core/NestedTest.java b/core/src/test/java/dev/kske/eventbus/core/NestedTest.java index c8d3862..bb0670e 100644 --- a/core/src/test/java/dev/kske/eventbus/core/NestedTest.java +++ b/core/src/test/java/dev/kske/eventbus/core/NestedTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.*; * @author Kai S. K. Engelbart * @since 1.2.0 */ -public class NestedTest { +class NestedTest { EventBus bus; boolean nestedHit; @@ -21,7 +21,7 @@ public class NestedTest { * @since 1.2.0 */ @BeforeEach - public void registerListener() { + void registerListener() { bus = new EventBus(); bus.registerListener(this); } @@ -34,7 +34,7 @@ public class NestedTest { * @since 1.2.0 */ @Test - public void testNestedDispatch() { + void testNestedDispatch() { bus.dispatch(new SimpleEvent()); assertTrue(nestedHit); } diff --git a/core/src/test/java/dev/kske/eventbus/core/SimpleEvent.java b/core/src/test/java/dev/kske/eventbus/core/SimpleEvent.java index bed60bc..2baf080 100644 --- a/core/src/test/java/dev/kske/eventbus/core/SimpleEvent.java +++ b/core/src/test/java/dev/kske/eventbus/core/SimpleEvent.java @@ -6,4 +6,4 @@ package dev.kske.eventbus.core; * @author Kai S. K. Engelbart * @since 0.0.1 */ -public class SimpleEvent {} +class SimpleEvent {} diff --git a/core/src/test/java/dev/kske/eventbus/core/SimpleEventSub.java b/core/src/test/java/dev/kske/eventbus/core/SimpleEventSub.java index c519fc8..909836e 100644 --- a/core/src/test/java/dev/kske/eventbus/core/SimpleEventSub.java +++ b/core/src/test/java/dev/kske/eventbus/core/SimpleEventSub.java @@ -6,4 +6,4 @@ package dev.kske.eventbus.core; * @author Kai S. K. Engelbart * @since 0.0.4 */ -public class SimpleEventSub extends SimpleEvent {} +class SimpleEventSub extends SimpleEvent {}