Skip to content

Commit 93f6300

Browse files
authored
Finalize migration to JUnit 5 (#237)
1 parent 3cfdb78 commit 93f6300

File tree

12 files changed

+598
-589
lines changed

12 files changed

+598
-589
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# EditorConfig: https://editorconfig.org/
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
charset = utf-8
11+
12+
# 2 space indentation for java, xml and yml files
13+
[*.{java,xml,yml,sh}]
14+
indent_style = space
15+
indent_size = 2
16+
17+
# Maven POM code convention
18+
[pom.xml]
19+
max_line_length = 205

pom.xml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2727
<!-- Needed to properly bring in the Maven dependencies, see http://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html -->
2828
<surefire.useSystemClassLoader>false</surefire.useSystemClassLoader>
29+
<!-- Dependency versions overriding -->
30+
<junit-jupiter.version>5.11.1</junit-jupiter.version>
2931
</properties>
3032

3133
<dependencyManagement>
@@ -35,12 +37,6 @@
3537
<artifactId>guava</artifactId>
3638
<version>33.3.1-jre</version>
3739
</dependency>
38-
<dependency>
39-
<groupId>org.junit</groupId>
40-
<artifactId>junit-bom</artifactId>
41-
<version>5.11.1</version>
42-
<scope>test</scope>
43-
</dependency>
4440
</dependencies>
4541
</dependencyManagement>
4642
<dependencies>
@@ -70,6 +66,12 @@
7066
<artifactId>compile-testing</artifactId>
7167
<version>0.21.0</version>
7268
<scope>test</scope>
69+
<exclusions>
70+
<exclusion>
71+
<artifactId>junit</artifactId>
72+
<groupId>junit</groupId>
73+
</exclusion>
74+
</exclusions>
7375
</dependency>
7476
<dependency>
7577
<groupId>commons-io</groupId>
@@ -88,11 +90,6 @@
8890
<artifactId>junit-jupiter</artifactId>
8991
<scope>test</scope>
9092
</dependency>
91-
<dependency>
92-
<groupId>org.junit.vintage</groupId>
93-
<artifactId>junit-vintage-engine</artifactId>
94-
<scope>test</scope>
95-
</dependency>
9693
</dependencies>
9794

9895
<build>

src/main/java/org/assertj/assertions/generator/BaseAssertionGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ public BaseAssertionGenerator() throws IOException {
192192
* Creates a new <code>{@link BaseAssertionGenerator}</code> with the templates from the given directory.
193193
*
194194
* @param templatesDirectory path where to find templates
195-
* @throws IOException if some template file could not be found or read
196195
*/
197-
public BaseAssertionGenerator(String templatesDirectory) throws IOException {
196+
public BaseAssertionGenerator(String templatesDirectory) {
198197
templateRegistry = DefaultTemplateRegistryProducer.create(templatesDirectory);
199198
}
200199

src/test/java/org/assertj/assertions/generator/AssertionGeneratorOverrideTemplateTest.java

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,62 @@
1414

1515
import org.assertj.assertions.generator.data.cars.Car;
1616
import org.assertj.assertions.generator.description.converter.ClassToClassDescriptionConverter;
17-
import org.junit.Before;
18-
import org.junit.Rule;
19-
import org.junit.Test;
17+
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.io.TempDir;
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.nio.file.Path;
2324
import java.nio.file.Paths;
2425

25-
public class AssertionGeneratorOverrideTemplateTest {
26+
import static org.assertj.assertions.generator.Template.Type.ABSTRACT_ASSERT_CLASS;
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
29+
import static org.assertj.core.api.Assertions.assertThatRuntimeException;
30+
31+
class AssertionGeneratorOverrideTemplateTest {
32+
2633
private BaseAssertionGenerator assertionGenerator;
2734
private ClassToClassDescriptionConverter converter;
35+
private GenerationHandler genHandle;
2836

29-
@Rule
30-
public final GenerationPathHandler genHandle = new GenerationPathHandler(AssertionGeneratorOverrideTemplateTest.class,
31-
Paths.get("src/test/resources"));
32-
33-
@Before
34-
public void before() throws IOException {
35-
assertionGenerator = genHandle.buildAssertionGenerator();
37+
@BeforeEach
38+
void before(@TempDir Path tempDir) throws IOException {
39+
assertionGenerator = new BaseAssertionGenerator();
40+
assertionGenerator.setDirectoryWhereAssertionFilesAreGenerated(tempDir.toFile());
3641
converter = new ClassToClassDescriptionConverter();
42+
genHandle = new GenerationHandler(tempDir, Paths.get("src/test/resources"));
3743
}
3844

39-
@Test(expected = NullPointerException.class)
40-
public void should_fail_if_custom_template_is_null() {
41-
assertionGenerator.register(null);
45+
@Test
46+
void should_fail_if_custom_template_is_null() {
47+
assertThatNullPointerException().isThrownBy(() -> assertionGenerator.register(null));
4248
}
4349

44-
@Test(expected = NullPointerException.class)
45-
public void should_fail_if_custom_template_content_is_null() {
46-
assertionGenerator.register(new Template(Template.Type.ABSTRACT_ASSERT_CLASS, (File) null));
50+
@Test
51+
void should_fail_if_custom_template_content_is_null() {
52+
assertThatNullPointerException().isThrownBy(() -> assertionGenerator.register(new Template(ABSTRACT_ASSERT_CLASS, (File) null)));
4753
}
4854

49-
@Test(expected = RuntimeException.class)
50-
public void should_fail_if_custom_template_content_cant_be_read() {
51-
assertionGenerator.register(new Template(Template.Type.ABSTRACT_ASSERT_CLASS, new File("not_existing.template")));
55+
@Test
56+
void should_fail_if_custom_template_content_cant_be_read() {
57+
assertThatRuntimeException().isThrownBy(() -> assertionGenerator.register(new Template(ABSTRACT_ASSERT_CLASS, new File("not_existing.template"))));
5258
}
5359

5460
@Test
55-
public void should_generate_assertion_with_custom_template() throws IOException {
61+
void should_generate_assertion_with_custom_template() throws IOException {
5662
assertionGenerator.register(new Template(Template.Type.HAS_FOR_WHOLE_NUMBER,
5763
new File("customtemplates" + File.separator,
5864
"custom_has_assertion_template_for_whole_number.txt")));
5965

6066
assertionGenerator.generateCustomAssertionFor(converter.convertToClassDescription(Car.class));
61-
genHandle.assertGeneratedAssertClass(Car.class, "CarAssert.expected.txt", true);
67+
File expectedFile = genHandle.getResourcesDir().resolve("CarAssert.expected.txt").toAbsolutePath().toFile();
68+
File actualFile = genHandle.fileGeneratedFor(Car.class);
69+
// compile it!
70+
genHandle.compileGeneratedFilesFor(Car.class);
71+
72+
assertThat(actualFile).hasSameTextualContentAs(expectedFile);
6273
}
74+
6375
}

0 commit comments

Comments
 (0)