@@ -25,38 +25,44 @@ class ManifestResourceExtractorTest {
2525 @ ParameterizedTest (name = "{0}" )
2626 @ MethodSource ("extractResourceCases" )
2727 void extractResource (
28- String name , String expectedName , String expectedVersion , InputStream input ) {
29- Resource resource =
30- new ManifestResourceExtractor (
31- new MainJarPathFinder (
32- () -> JarServiceNameResourceExtractorTest .getArgs ("app.jar" ),
33- prop -> null ,
34- JarServiceNameResourceExtractorTest ::failPath ),
35- p -> {
36- if (input == null ) {
37- return Optional .empty ();
38- }
39- try {
40- Manifest manifest = new Manifest ();
41- manifest .read (input );
42- return Optional .of (manifest );
43- } catch (IOException ignored ) {
44- return Optional .empty ();
45- }
46- })
47- .extract ();
48- assertThat (resource .getAttribute (SERVICE_NAME )).isEqualTo (expectedName );
49- assertThat (resource .getAttribute (SERVICE_VERSION )).isEqualTo (expectedVersion );
28+ String name , String expectedName , String expectedVersion , String resourceName )
29+ throws IOException {
30+ try (InputStream input = openClasspathResource (resourceName )) {
31+ Resource resource =
32+ new ManifestResourceExtractor (
33+ new MainJarPathFinder (
34+ () -> JarServiceNameResourceExtractorTest .getArgs ("app.jar" ),
35+ prop -> null ,
36+ JarServiceNameResourceExtractorTest ::failPath ),
37+ p -> {
38+ if (input == null ) {
39+ return Optional .empty ();
40+ }
41+ try {
42+ Manifest manifest = new Manifest ();
43+ manifest .read (input );
44+ return Optional .of (manifest );
45+ } catch (IOException ignored ) {
46+ return Optional .empty ();
47+ }
48+ })
49+ .extract ();
50+ assertThat (resource .getAttribute (SERVICE_NAME )).isEqualTo (expectedName );
51+ assertThat (resource .getAttribute (SERVICE_VERSION )).isEqualTo (expectedVersion );
52+ }
5053 }
5154
5255 private static Stream <Arguments > extractResourceCases () {
5356 return Stream .of (
54- arguments ("name ok" , "demo" , "0.0.1-SNAPSHOT" , openClasspathResource ( "MANIFEST.MF" ) ),
57+ arguments ("name ok" , "demo" , "0.0.1-SNAPSHOT" , "MANIFEST.MF" ),
5558 arguments ("name - no resource" , null , null , null ),
56- arguments ("name - empty resource" , null , null , openClasspathResource ( "empty-MANIFEST.MF" ) ));
59+ arguments ("name - empty resource" , null , null , "empty-MANIFEST.MF" ));
5760 }
5861
5962 private static InputStream openClasspathResource (String resource ) {
63+ if (resource == null ) {
64+ return null ;
65+ }
6066 return ManifestResourceExtractorTest .class .getClassLoader ().getResourceAsStream (resource );
6167 }
6268}
0 commit comments