|
20 | 20 | public class TransformHbmTestIT { |
21 | 21 |
|
22 | 22 | public static final String MVN_HOME = "maven.multiModuleProjectDirectory"; |
23 | | - private static File baseFolder; |
24 | 23 | private static File localRepo; |
25 | 24 |
|
26 | 25 | @TempDir |
27 | 26 | private Path projectPath; |
28 | 27 |
|
29 | 28 | @BeforeAll |
30 | 29 | public static void beforeAll() throws Exception { |
31 | | - // The needed resource for this test are put in place |
32 | | - // in the 'baseFolder' (normally 'target/test-classes') |
33 | | - // by the 'build-helper-maven-plugin' execution. |
34 | | - // See the 'pom.xml' |
35 | | - baseFolder = determineBaseFolder(); |
36 | | - localRepo = new File(baseFolder.getParentFile(), "local-repo"); |
| 30 | + localRepo = new File(determineBaseFolder().getParentFile(), "local-repo"); |
37 | 31 | } |
38 | 32 | @Test |
39 | 33 | public void testSimpleHbmTransformation() throws Exception { |
@@ -75,17 +69,21 @@ private void runTransformHbmToOrm() throws Exception { |
75 | 69 | projectPath.toAbsolutePath().toString(), |
76 | 70 | null, |
77 | 71 | null); |
78 | | - // Check the existaence of the transformed file |
| 72 | + // Check the existence of the transformed file |
79 | 73 | assertTrue(ormXmlFile.exists()); |
80 | 74 | // Check if it's pretty printed |
81 | 75 | assertTrue(Files.readString(ormXmlFile.toPath()).contains("\n <table name=\"Foo\"/>\n")); |
82 | 76 | } |
83 | 77 |
|
84 | 78 | private static File determineBaseFolder() throws Exception { |
85 | | - URL classUrl = TransformHbmTestIT.class.getResource( |
86 | | - "/" + TransformHbmTestIT.class.getName().replace(".", "/") + ".class"); |
87 | | - return new File(classUrl.toURI()) |
88 | | - .getParentFile().getParentFile().getParentFile().getParentFile().getParentFile(); |
| 79 | + Class<?> thisClass = TransformHbmTestIT.class; |
| 80 | + URL classUrl = thisClass.getResource("/" + thisClass.getName().replace(".", "/") + ".class"); |
| 81 | + assert classUrl != null; |
| 82 | + File result = new File(classUrl.toURI()); |
| 83 | + for (int i = 0; i < thisClass.getName().chars().filter(ch -> ch == '.').count() + 1; i++) { |
| 84 | + result = result.getParentFile(); |
| 85 | + } |
| 86 | + return result; |
89 | 87 | } |
90 | 88 |
|
91 | 89 | private static final String simplePomContents = |
|
0 commit comments