Skip to content

Commit abb092d

Browse files
committed
test: add unit test for ResourceFileLoaderUtil
1 parent c8b8fde commit abb092d

File tree

6 files changed

+197
-5
lines changed

6 files changed

+197
-5
lines changed

annotationprocessor/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ dependencies {
3333

3434
annotationProcessor 'org.projectlombok:lombok:1.18.38'
3535
annotationProcessor 'com.google.auto.service:auto-service:1.1.1'
36+
37+
testImplementation 'com.google.testing.compile:compile-testing:0.21.0'
38+
39+
testImplementation project(':api')
40+
testImplementation project(':common')
3641
}

annotationprocessor/src/main/java/com/interguess/autoimpl/annotationprocessor/utils/ResourceFileLoaderUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import lombok.experimental.UtilityClass;
2828
import org.jetbrains.annotations.NotNull;
2929

30+
import java.io.FileNotFoundException;
3031
import java.io.InputStream;
3132

3233
@UtilityClass
@@ -35,10 +36,10 @@ public class ResourceFileLoaderUtil {
3536
public static @NotNull String load(final @NotNull String resourceFileName) {
3637
try (final InputStream inputStream = ResourceFileLoaderUtil.class.getResourceAsStream(resourceFileName)) {
3738
if (inputStream == null) {
38-
throw new RuntimeException("Failed to load resource file: " + resourceFileName);
39+
throw new FileNotFoundException("Failed to load resource file: " + resourceFileName);
3940
}
4041

41-
return new String(inputStream.readAllBytes());
42+
return new String(inputStream.readAllBytes()).replace("\r\n", "\n").replace("\r", "\n");
4243
} catch (Exception e) {
4344
throw new RuntimeException("Error reading resource file: " + resourceFileName, e);
4445
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Interguess.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.interguess.autoimpl.annotationprocessor.utils;
26+
27+
import org.junit.jupiter.api.Assertions;
28+
import org.junit.jupiter.api.Test;
29+
30+
public class ResourceFileLoaderUtilTest {
31+
32+
@Test
33+
public void testLoadResourceFile() {
34+
Assertions.assertEquals(
35+
"""
36+
FZ wv3&AlFx1PR|im 5m7bNL
37+
Ff1UIdPOe|NR/ gw TpAAvfh
38+
KE7U nU| L$yMeykZxGogsl9
39+
lNDiFcnWgE5O e4|d GOjjG
40+
oJF Q oDb7xqf|/we5Bso1bM
41+
GgX5cp4qb|§c AL i0x1HN3r
42+
ZzvoRGTZufTfke! uX|KQKN
43+
noTFnreOI 7ga 74Lkr|J^WL
44+
4mpBA I4G 7p|cMAH9_4cQ3Z
45+
piWZAUSZ:Jtt6a8qF N |Bfy""",
46+
ResourceFileLoaderUtil.load("/test-1.txt")
47+
);
48+
49+
Assertions.assertEquals("sLyurr0tIQrIAjx6ClS7", ResourceFileLoaderUtil.load("/test-2.txt"));
50+
51+
Assertions.assertThrows(RuntimeException.class, () -> ResourceFileLoaderUtil.load("test1.txt"));
52+
Assertions.assertThrows(RuntimeException.class, () -> ResourceFileLoaderUtil.load("test-2.txt"));
53+
Assertions.assertThrows(RuntimeException.class, () -> ResourceFileLoaderUtil.load("tes/t"));
54+
}
55+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FZ wv3&AlFx1PR|im 5m7bNL
2+
Ff1UIdPOe|NR/ gw TpAAvfh
3+
KE7U nU| L$yMeykZxGogsl9
4+
lNDiFcnWgE5O e4|d GOjjG
5+
oJF Q oDb7xqf|/we5Bso1bM
6+
GgX5cp4qb|§c AL i0x1HN3r
7+
ZzvoRGTZufTfke! uX|KQKN
8+
noTFnreOI 7ga 74Lkr|J^WL
9+
4mpBA I4G 7p|cMAH9_4cQ3Z
10+
piWZAUSZ:Jtt6a8qF N |Bfy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sLyurr0tIQrIAjx6ClS7

build.gradle

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,133 @@
2222
* SOFTWARE.
2323
*/
2424

25+
plugins {
26+
id 'java'
27+
id 'jacoco'
28+
}
29+
30+
repositories {
31+
mavenCentral()
32+
}
33+
34+
jacoco {
35+
toolVersion = '0.8.12'
36+
}
37+
2538
group 'com.interguess'
2639
version 'unknown'
2740

28-
allprojects {
41+
subprojects {
2942
apply plugin: 'java'
30-
43+
apply plugin: 'jacoco'
44+
3145
repositories {
3246
mavenCentral()
3347
}
34-
}
48+
49+
dependencies {
50+
testImplementation platform('org.junit:junit-bom:5.13.3')
51+
testImplementation 'org.junit.jupiter:junit-jupiter'
52+
53+
// Plattform-Module explizit hinzufügen
54+
testImplementation 'org.junit.platform:junit-platform-engine:1.13.3'
55+
testImplementation 'org.junit.platform:junit-platform-launcher:1.13.3'
56+
testImplementation 'org.junit.platform:junit-platform-commons:1.13.3'
57+
58+
testAnnotationProcessor 'org.projectlombok:lombok:1.18.38'
59+
60+
testImplementation 'org.mockito:mockito-core:5.18.0'
61+
testImplementation 'org.mockito:mockito-junit-jupiter:5.18.0'
62+
63+
testImplementation('com.google.testing.compile:compile-testing:0.21.0') {
64+
exclude group: 'junit', module: 'junit'
65+
}
66+
}
67+
68+
69+
// Erzwinge gleiche Versionen für JUnit-Komponenten
70+
configurations.all {
71+
resolutionStrategy.eachDependency { details ->
72+
if (details.requested.group == 'org.junit.platform') {
73+
details.useVersion '1.13.3'
74+
details.because 'Align all JUnit Platform modules to same version to avoid discovery errors'
75+
}
76+
if (details.requested.group == 'org.junit.jupiter') {
77+
details.useVersion '5.13.3'
78+
details.because 'Align all JUnit Jupiter modules to same version'
79+
}
80+
if (details.requested.group == 'org.opentest4j') {
81+
details.useVersion '1.3.0'
82+
details.because 'Compatible version for JUnit 5.13.3'
83+
}
84+
}
85+
86+
// JUnit Vintage Engine ausschließen
87+
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
88+
}
89+
90+
jacoco {
91+
toolVersion = '0.8.12'
92+
}
93+
94+
java {
95+
toolchain {
96+
languageVersion = JavaLanguageVersion.of(21)
97+
}
98+
}
99+
100+
test {
101+
useJUnitPlatform()
102+
finalizedBy jacocoTestReport
103+
javaLauncher.set(javaToolchains.launcherFor {
104+
languageVersion = JavaLanguageVersion.of(21)
105+
})
106+
}
107+
108+
jacocoTestReport {
109+
dependsOn test
110+
reports {
111+
xml.required = true
112+
html.required = true
113+
csv.required = false
114+
}
115+
}
116+
}
117+
118+
java {
119+
toolchain {
120+
languageVersion = JavaLanguageVersion.of(21)
121+
}
122+
}
123+
124+
tasks.named('test') {
125+
useJUnitPlatform()
126+
javaLauncher.set(javaToolchains.launcherFor {
127+
languageVersion = JavaLanguageVersion.of(21)
128+
})
129+
}
130+
131+
task jacocoRootReport(type: JacocoReport) {
132+
dependsOn subprojects.jacocoTestReport
133+
134+
def coverageSourceDirs = files()
135+
def classDirs = files()
136+
def execFiles = files()
137+
138+
subprojects.each { subproject ->
139+
coverageSourceDirs += subproject.sourceSets.main.allSource.srcDirs
140+
classDirs += subproject.sourceSets.main.output
141+
execFiles += fileTree(dir: subproject.buildDir, includes: [
142+
'jacoco/test.exec'
143+
])
144+
}
145+
146+
sourceDirectories.setFrom coverageSourceDirs
147+
classDirectories.setFrom classDirs
148+
executionData.setFrom execFiles
149+
150+
reports {
151+
html.required = true
152+
xml.required = true
153+
}
154+
}

0 commit comments

Comments
 (0)