-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #612: fix Code smells, removes junit-vintag
* increases test coverage * fixes codesmells from Java17 upgrade * adding more useful ArchUnitTests * changes related to new ArchUnitTest * removes junit-vintage dependency
- Loading branch information
Showing
28 changed files
with
804 additions
and
141 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
105 changes: 105 additions & 0 deletions
105
...a-outbox-example-boot/src/test/java/pro/taskana/camunda/spring/boot/ArchitectureTest.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,105 @@ | ||
package pro.taskana.camunda.spring.boot; | ||
|
||
import static com.tngtech.archunit.core.domain.JavaCall.Predicates.target; | ||
import static com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates.annotatedWith; | ||
import static com.tngtech.archunit.core.domain.properties.HasName.Predicates.nameMatching; | ||
import static com.tngtech.archunit.lang.conditions.ArchPredicates.are; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; | ||
|
||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.core.importer.ImportOption.OnlyIncludeTests; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestFactory; | ||
import org.junit.jupiter.api.TestTemplate; | ||
|
||
class ArchitectureTest { | ||
|
||
public static final String[] PACKAGE_NAMES = {"pro.taskana", "acceptance"}; | ||
private static final JavaClasses IMPORTED_CLASSES = | ||
new ClassFileImporter().importPackages(PACKAGE_NAMES); | ||
|
||
private static final JavaClasses IMPORTED_TEST_CLASSES = | ||
new ClassFileImporter(List.of(new OnlyIncludeTests())).importPackages(PACKAGE_NAMES); | ||
|
||
@Test | ||
void testMethodNamesShouldMatchAccordingToOurGuidelines() { | ||
methods() | ||
.that( | ||
are( | ||
annotatedWith(Test.class) | ||
.or(annotatedWith(TestFactory.class)) | ||
.or(annotatedWith(TestTemplate.class)))) | ||
.and() | ||
.areNotDeclaredIn(ArchitectureTest.class) | ||
.should() | ||
.haveNameMatching("^should_[A-Z][^_]+(_(For|When)_[A-Z][^_]+)?$") | ||
.check(IMPORTED_TEST_CLASSES); | ||
} | ||
|
||
@Test | ||
void testClassesAndTestMethodsShouldBePackagePrivate() { | ||
classes() | ||
.that() | ||
.haveSimpleNameStartingWith("Test") | ||
.or() | ||
.haveSimpleNameEndingWith("Test") | ||
.should() | ||
.bePackagePrivate() | ||
.check(IMPORTED_TEST_CLASSES); | ||
methods() | ||
.that() | ||
.areDeclaredInClassesThat() | ||
.haveSimpleNameStartingWith("Test") | ||
.or() | ||
.areDeclaredInClassesThat() | ||
.haveSimpleNameEndingWith("Test") | ||
.should() | ||
.bePackagePrivate() | ||
.orShould() | ||
.bePrivate() | ||
.check(IMPORTED_TEST_CLASSES); | ||
} | ||
|
||
@Test | ||
void noMethodsShouldUseThreadSleep() { | ||
noClasses() | ||
.should() | ||
.callMethod(Thread.class, "sleep", long.class) | ||
.orShould() | ||
.callMethod(Thread.class, "sleep", long.class, int.class) | ||
.check(IMPORTED_CLASSES); | ||
} | ||
|
||
@Test | ||
void noMethodsShouldUsePrintln() { | ||
noClasses() | ||
.should() | ||
.callMethodWhere(target(nameMatching("println"))) | ||
.check(IMPORTED_CLASSES); | ||
} | ||
|
||
@Test | ||
void noImportsForOldJunitClasses() { | ||
noClasses() | ||
.should() | ||
.dependOnClassesThat() | ||
.haveFullyQualifiedName("org.junit.Test") | ||
.orShould() | ||
.dependOnClassesThat() | ||
.haveFullyQualifiedName("org.junit.Assert") | ||
.check(IMPORTED_TEST_CLASSES); | ||
} | ||
|
||
@Test | ||
void noImportsForJunitAssertionsWeWantAssertJ() { | ||
noClasses() | ||
.should() | ||
.dependOnClassesThat() | ||
.haveFullyQualifiedName("org.junit.jupiter.api.Assertions") | ||
.check(IMPORTED_TEST_CLASSES); | ||
} | ||
} |
37 changes: 34 additions & 3 deletions
37
...rc/test/java/pro/taskana/camunda/spring/boot/CamundaSpringBootExampleIntegrationTest.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 |
---|---|---|
@@ -1,16 +1,47 @@ | ||
package pro.taskana.camunda.spring.boot; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import pro.taskana.adapter.camunda.outbox.rest.config.OutboxRestServiceConfig; | ||
import pro.taskana.adapter.camunda.outbox.rest.controller.CamundaTaskEventsController; | ||
import pro.taskana.adapter.camunda.parselistener.TaskanaParseListenerProcessEnginePlugin; | ||
|
||
@SpringBootTest(classes = CamundaSpringBootExample.class, webEnvironment = RANDOM_PORT) | ||
class CamundaSpringBootExampleIntegrationTest { | ||
|
||
private final OutboxRestServiceConfig outboxRestServiceConfig; | ||
|
||
private final CamundaTaskEventsController camundaTaskEventsController; | ||
|
||
private final TaskanaParseListenerProcessEnginePlugin taskanaParseListenerProcessEnginePlugin; | ||
|
||
CamundaSpringBootExampleIntegrationTest( | ||
@Autowired(required = false) OutboxRestServiceConfig outboxRestServiceConfig, | ||
@Autowired(required = false) CamundaTaskEventsController camundaTaskEventsController, | ||
@Autowired(required = false) | ||
TaskanaParseListenerProcessEnginePlugin taskanaParseListenerProcessEnginePlugin) { | ||
this.outboxRestServiceConfig = outboxRestServiceConfig; | ||
this.camundaTaskEventsController = camundaTaskEventsController; | ||
this.taskanaParseListenerProcessEnginePlugin = taskanaParseListenerProcessEnginePlugin; | ||
} | ||
|
||
@Test | ||
void should_AutowireOutboxRestServiceConfig_When_ApplicationIsStarting() { | ||
assertThat(outboxRestServiceConfig).isNotNull(); | ||
} | ||
|
||
@Test | ||
void should_AutowireCamundaTaskEventsController_When_ApplicationIsStarting() { | ||
assertThat(camundaTaskEventsController).isNotNull(); | ||
} | ||
|
||
@Test | ||
void module_context_can_be_started() { | ||
// there is no test code here, | ||
// because creating the configuration to run this method is the actual test | ||
void should_AutowireTaskanaParseListenerProcessEnginePlugin_When_ApplicationIsStarting() { | ||
assertThat(taskanaParseListenerProcessEnginePlugin).isNotNull(); | ||
} | ||
|
||
} |
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
105 changes: 105 additions & 0 deletions
105
...apter-camunda-spring-boot-example/src/test/java/pro/taskana/adapter/ArchitectureTest.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,105 @@ | ||
package pro.taskana.adapter; | ||
|
||
import static com.tngtech.archunit.core.domain.JavaCall.Predicates.target; | ||
import static com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates.annotatedWith; | ||
import static com.tngtech.archunit.core.domain.properties.HasName.Predicates.nameMatching; | ||
import static com.tngtech.archunit.lang.conditions.ArchPredicates.are; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; | ||
|
||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.core.importer.ImportOption.OnlyIncludeTests; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestFactory; | ||
import org.junit.jupiter.api.TestTemplate; | ||
|
||
class ArchitectureTest { | ||
|
||
public static final String[] PACKAGE_NAMES = {"pro.taskana", "acceptance"}; | ||
private static final JavaClasses IMPORTED_CLASSES = | ||
new ClassFileImporter().importPackages(PACKAGE_NAMES); | ||
|
||
private static final JavaClasses IMPORTED_TEST_CLASSES = | ||
new ClassFileImporter(List.of(new OnlyIncludeTests())).importPackages(PACKAGE_NAMES); | ||
|
||
@Test | ||
void testMethodNamesShouldMatchAccordingToOurGuidelines() { | ||
methods() | ||
.that( | ||
are( | ||
annotatedWith(Test.class) | ||
.or(annotatedWith(TestFactory.class)) | ||
.or(annotatedWith(TestTemplate.class)))) | ||
.and() | ||
.areNotDeclaredIn(ArchitectureTest.class) | ||
.should() | ||
.haveNameMatching("^should_[A-Z][^_]+(_(For|When)_[A-Z][^_]+)?$") | ||
.check(IMPORTED_TEST_CLASSES); | ||
} | ||
|
||
@Test | ||
void testClassesAndTestMethodsShouldBePackagePrivate() { | ||
classes() | ||
.that() | ||
.haveSimpleNameStartingWith("Test") | ||
.or() | ||
.haveSimpleNameEndingWith("Test") | ||
.should() | ||
.bePackagePrivate() | ||
.check(IMPORTED_TEST_CLASSES); | ||
methods() | ||
.that() | ||
.areDeclaredInClassesThat() | ||
.haveSimpleNameStartingWith("Test") | ||
.or() | ||
.areDeclaredInClassesThat() | ||
.haveSimpleNameEndingWith("Test") | ||
.should() | ||
.bePackagePrivate() | ||
.orShould() | ||
.bePrivate() | ||
.check(IMPORTED_TEST_CLASSES); | ||
} | ||
|
||
@Test | ||
void noMethodsShouldUseThreadSleep() { | ||
noClasses() | ||
.should() | ||
.callMethod(Thread.class, "sleep", long.class) | ||
.orShould() | ||
.callMethod(Thread.class, "sleep", long.class, int.class) | ||
.check(IMPORTED_CLASSES); | ||
} | ||
|
||
@Test | ||
void noMethodsShouldUsePrintln() { | ||
noClasses() | ||
.should() | ||
.callMethodWhere(target(nameMatching("println"))) | ||
.check(IMPORTED_CLASSES); | ||
} | ||
|
||
@Test | ||
void noImportsForOldJunitClasses() { | ||
noClasses() | ||
.should() | ||
.dependOnClassesThat() | ||
.haveFullyQualifiedName("org.junit.Test") | ||
.orShould() | ||
.dependOnClassesThat() | ||
.haveFullyQualifiedName("org.junit.Assert") | ||
.check(IMPORTED_TEST_CLASSES); | ||
} | ||
|
||
@Test | ||
void noImportsForJunitAssertionsWeWantAssertJ() { | ||
noClasses() | ||
.should() | ||
.dependOnClassesThat() | ||
.haveFullyQualifiedName("org.junit.jupiter.api.Assertions") | ||
.check(IMPORTED_TEST_CLASSES); | ||
} | ||
} |
33 changes: 30 additions & 3 deletions
33
...-spring-boot-example/src/test/java/pro/taskana/adapter/TaskanaAdapterApplicationTest.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 |
---|---|---|
@@ -1,14 +1,41 @@ | ||
package pro.taskana.adapter; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import pro.taskana.common.api.TaskanaEngine; | ||
import pro.taskana.spi.routing.api.TaskRoutingProvider; | ||
import pro.taskana.spi.routing.internal.TaskRoutingManager; | ||
import pro.taskana.taskrouting.ExampleTaskRouter; | ||
|
||
@SpringBootTest(classes = TaskanaAdapterApplication.class) | ||
class TaskanaAdapterApplicationTest { | ||
|
||
private final List<TaskRoutingProvider> taskRoutingProviders; | ||
|
||
TaskanaAdapterApplicationTest(@Autowired TaskanaEngine taskanaEngine) throws Exception { | ||
TaskRoutingManager taskRoutingManager = | ||
(TaskRoutingManager) getValueFromPrivateField(taskanaEngine, "taskRoutingManager"); | ||
this.taskRoutingProviders = | ||
(List<TaskRoutingProvider>) | ||
getValueFromPrivateField(taskRoutingManager, "taskRoutingProviders"); | ||
} | ||
|
||
@Test | ||
void module_context_can_be_started_and_outbox_rest_events_are_fetched() { | ||
// there is no test code here, | ||
// because creating the configuration to run this method is the actual test | ||
void should_AutowireExampleTaskRouter_When_ApplicationIsStarting() { | ||
assertThat(taskRoutingProviders).isNotNull().hasSize(1); | ||
assertThat(taskRoutingProviders.get(0)).isInstanceOf(ExampleTaskRouter.class); | ||
} | ||
|
||
private Object getValueFromPrivateField(Object obj, String fieldName) | ||
throws NoSuchFieldException, IllegalAccessException { | ||
Field nameField = obj.getClass().getDeclaredField(fieldName); | ||
nameField.setAccessible(true); | ||
|
||
return nameField.get(obj); | ||
} | ||
} |
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
Oops, something went wrong.