|
14 | 14 |
|
15 | 15 | import org.assertj.assertions.generator.data.cars.Car; |
16 | 16 | 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; |
20 | 20 |
|
21 | 21 | import java.io.File; |
22 | 22 | import java.io.IOException; |
| 23 | +import java.nio.file.Path; |
23 | 24 | import java.nio.file.Paths; |
24 | 25 |
|
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 | + |
26 | 33 | private BaseAssertionGenerator assertionGenerator; |
27 | 34 | private ClassToClassDescriptionConverter converter; |
| 35 | + private GenerationHandler genHandle; |
28 | 36 |
|
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()); |
36 | 41 | converter = new ClassToClassDescriptionConverter(); |
| 42 | + genHandle = new GenerationHandler(tempDir, Paths.get("src/test/resources")); |
37 | 43 | } |
38 | 44 |
|
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)); |
42 | 48 | } |
43 | 49 |
|
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))); |
47 | 53 | } |
48 | 54 |
|
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")))); |
52 | 58 | } |
53 | 59 |
|
54 | 60 | @Test |
55 | | - public void should_generate_assertion_with_custom_template() throws IOException { |
| 61 | + void should_generate_assertion_with_custom_template() throws IOException { |
56 | 62 | assertionGenerator.register(new Template(Template.Type.HAS_FOR_WHOLE_NUMBER, |
57 | 63 | new File("customtemplates" + File.separator, |
58 | 64 | "custom_has_assertion_template_for_whole_number.txt"))); |
59 | 65 |
|
60 | 66 | 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); |
62 | 73 | } |
| 74 | + |
63 | 75 | } |
0 commit comments