Skip to content

Commit

Permalink
upgrading tests to Junit 5 (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-fuchs authored Nov 26, 2023
1 parent b1bc2ad commit cdc0eeb
Show file tree
Hide file tree
Showing 47 changed files with 151 additions and 152 deletions.
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,7 @@
<include>**/*Test.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
</dependencies>

</plugin>

<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ConditionEvents;
import com.tngtech.archunit.lang.SimpleConditionEvent;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;

Expand Down Expand Up @@ -133,7 +133,7 @@ private boolean isThereAtLeastOneMethodAnnotedWithTest(JavaClass javaClass) {

private boolean isAnnotedWithTest(JavaMethod method) {

return method.isAnnotatedWith(Test.class);
return method.isAnnotatedWith(Test.class) || method.isAnnotatedWith(org.junit.Test.class);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ConditionEvents;
import com.tngtech.archunit.lang.SimpleConditionEvent;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;

Expand Down Expand Up @@ -44,7 +44,7 @@ public class TestMethodsNamingRuleTest implements ArchRuleTest {
@Override
public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection<String> excludedPaths) {

methods().that().areAnnotatedWith(Test.class).should(respectNamingConvention())
methods().that().areAnnotatedWith(Test.class).or().areAnnotatedWith(org.junit.Test.class).should(respectNamingConvention())
.allowEmptyShould(true)
.check(ArchUtils.importAllClassesInPackage( scopePathProvider.getTestClassesPath(), packagePath, excludedPaths));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ClassTestWithCorrectName1Test {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

public class ClassTestWithCorrectName2Test {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ClassTestWithIncorrectName1 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

public class ClassTestWithIncorrectName2 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class MethodWithCorrectNameStartingWithShouldTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class MethodWithCorrectNameStartingWithTestTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class MethodWithIncorrectNameTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.societegenerale.aut.test;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.societegenerale.commons.plugin.utils.ArchUtils;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaClasses;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.societegenerale.aut.test.TestSpecificScopeProvider;
import com.societegenerale.commons.plugin.SilentLog;
import com.societegenerale.commons.plugin.utils.ArchUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static com.societegenerale.commons.plugin.rules.ConstantsAndStaticNonFinalFieldsNamesRuleTest.CONSTANTS_VIOLATION_MESSAGE;
import static com.societegenerale.commons.plugin.rules.ConstantsAndStaticNonFinalFieldsNamesRuleTest.ENUM_CONSTANTS_VIOLATION_MESSAGE;
Expand All @@ -27,7 +27,7 @@ public class ConstantsAndStaticNonFinalFieldsNamesRuleTestTest {

private String pathEnumWithValuesWrittenCorrectly = "com/societegenerale/aut/main/EnumWithValuesWrittenCorrectly.class";

@Before
@BeforeEach
public void setup() {
// in the normal lifecycle, ArchUtils is instantiated, which enables a static
// field there to be initialized
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.societegenerale.commons.plugin.rules;

import com.societegenerale.aut.test.TestSpecificScopeProvider;
import com.societegenerale.commons.plugin.SilentLog;
import com.societegenerale.commons.plugin.utils.ArchUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static java.util.Collections.emptySet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.catchThrowable;

import com.societegenerale.aut.test.TestSpecificScopeProvider;
import com.societegenerale.commons.plugin.SilentLog;
import com.societegenerale.commons.plugin.utils.ArchUtils;
import org.junit.Before;
import org.junit.Test;

public class DontReturnNullCollectionTestTest {

String pathObjectWithAmethodReturningAnullList = "com/societegenerale/aut/main/ObjectWithMethodsReturningNullCollections.class";
Expand All @@ -21,7 +21,7 @@ public class DontReturnNullCollectionTestTest {

String pathObjectWithLombokBuilder = "com/societegenerale/aut/main/ObjectWithLombokBuilder.class$ObjectWithLombokBuilderBuilder";

@Before
@BeforeEach
public void setup(){
//in the normal lifecycle, ArchUtils is instantiated, which enables a static field there to be initialized
new ArchUtils(new SilentLog());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@
import com.societegenerale.aut.test.TestSpecificScopeProvider;
import com.societegenerale.commons.plugin.SilentLog;
import com.societegenerale.commons.plugin.utils.ArchUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static java.util.Collections.emptySet;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class FinalNonStaticFieldsHaveToBeStaticFinalFieldsRuleTestTest {

private String pathClassWithFinalNonStaticFields = "com/societegenerale/aut/main/ClassWithFinalNonStaticFields.class";

private String pathClassWithStaticFinalFields = "com/societegenerale/aut/main/ClassWithStaticFinalFields.class";

@Before
@BeforeEach
public void setup() {
// in the normal lifecycle, ArchUtils is instantiated, which enables a static
// field there to be initialized
ArchUtils archUtils = new ArchUtils(new SilentLog());
}

@Test(expected = AssertionError.class)
@Test
public void shouldThrowViolation() {

new FinalNonStaticFieldsHaveToBeStaticFinalFieldsRuleTest().execute(pathClassWithFinalNonStaticFields,
new TestSpecificScopeProvider(), emptySet());

assertThatThrownBy(() -> {
new FinalNonStaticFieldsHaveToBeStaticFinalFieldsRuleTest().execute(pathClassWithFinalNonStaticFields,
new TestSpecificScopeProvider(), emptySet());
}).isInstanceOf(AssertionError.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.societegenerale.commons.plugin.Log;
import com.societegenerale.commons.plugin.SilentLog;
import com.societegenerale.commons.plugin.utils.ArchUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static com.societegenerale.commons.plugin.rules.HexagonalArchitectureTest.WHEN_FOLLOWING_HEXAGONAL_ARCHITECTURE;
import static java.util.Collections.emptySet;
Expand Down Expand Up @@ -37,7 +37,7 @@ public class HexagonalArchitectureTestTest {

private Log silentLogger=new SilentLog();

@Before
@BeforeEach
public void setup(){
//in the normal lifecycle, ArchUtils is instantiated, which enables a static field there to be initialized
ArchUtils archUtils=new ArchUtils(new SilentLog());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.societegenerale.aut.test.TestSpecificScopeProvider;
import com.societegenerale.commons.plugin.SilentLog;
import com.societegenerale.commons.plugin.utils.ArchUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static com.societegenerale.commons.plugin.rules.NoAutowiredFieldTest.NO_AUTOWIRED_FIELD_MESSAGE;
import static java.util.Collections.emptySet;
Expand All @@ -20,7 +20,7 @@ public class NoAutowiredFieldTestTest {
// injected fields should not trigger autowired violation - they have their own rule
private String pathTestClassWithInjectedField = "com/societegenerale/aut/main/ClassWithInjectedField.class";

@Before
@BeforeEach
public void setup() {
// in the normal lifecycle, ArchUtils is instantiated, which enables a static
// field there to be initialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.societegenerale.aut.test.TestSpecificScopeProvider;
import com.societegenerale.commons.plugin.SilentLog;
import com.societegenerale.commons.plugin.utils.ArchUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static com.societegenerale.commons.plugin.rules.NoInjectedFieldTest.NO_INJECTED_FIELD_MESSAGE;
import static java.util.Collections.emptySet;
Expand All @@ -20,7 +20,7 @@ public class NoInjectedFieldTestTest {

private String pathTestClassWithInjectedField = "com/societegenerale/aut/main/ClassWithInjectedField.class";

@Before
@BeforeEach
public void setup() {
// in the normal lifecycle, ArchUtils is instantiated, which enables a static
// field there to be initialized
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.societegenerale.commons.plugin.rules;

import static com.societegenerale.commons.plugin.rules.NoJavaUtilDateRuleTest.NO_JAVA_UTIL_DATE_VIOLATION_MESSAGE;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.junit.Test;

import com.societegenerale.aut.main.ObjectWithAdateField;
import com.societegenerale.aut.main.ObjectWithJava8TimeLib;
import com.societegenerale.aut.main.ObjectWithJavaTextDateFormat;
import com.societegenerale.aut.main.ObjectWithJavaUtilGregorianCalendar;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import org.junit.jupiter.api.Test;

import static com.societegenerale.commons.plugin.rules.NoJavaUtilDateRuleTest.NO_JAVA_UTIL_DATE_VIOLATION_MESSAGE;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class NoJavaUtilDateRuleTestTest {

Expand Down
Loading

0 comments on commit cdc0eeb

Please sign in to comment.