Skip to content

Commit d1f89db

Browse files
committed
Merge branch '2.7.x' into 3.0.x
2 parents f28bb22 + d39c94f commit d1f89db

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

spring-boot-tests/spring-boot-integration-tests/spring-boot-configuration-processor-tests/src/test/java/org/springframework/boot/configurationprocessor/tests/ConfigurationProcessorIntegrationTests.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,15 +17,17 @@
1717
package org.springframework.boot.configurationprocessor.tests;
1818

1919
import java.io.IOException;
20+
import java.net.URL;
21+
import java.util.ArrayList;
22+
import java.util.List;
2023

2124
import org.junit.jupiter.api.BeforeAll;
2225
import org.junit.jupiter.api.Test;
2326

2427
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
2528
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository;
2629
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder;
27-
import org.springframework.core.io.ClassPathResource;
28-
import org.springframework.core.io.Resource;
30+
import org.springframework.util.CollectionUtils;
2931

3032
import static org.assertj.core.api.Assertions.assertThat;
3133

@@ -40,12 +42,20 @@ class ConfigurationProcessorIntegrationTests {
4042

4143
@BeforeAll
4244
static void readMetadata() throws IOException {
43-
Resource resource = new ClassPathResource("META-INF/spring-configuration-metadata.json");
44-
assertThat(resource.exists()).isTrue();
45-
// Make sure the right file is detected
46-
assertThat(resource.getURL().toString()).contains("spring-boot-configuration-processor-tests");
47-
repository = ConfigurationMetadataRepositoryJsonBuilder.create(resource.getInputStream()).build();
45+
repository = ConfigurationMetadataRepositoryJsonBuilder.create(getResource().openStream()).build();
46+
}
4847

48+
private static URL getResource() throws IOException {
49+
ClassLoader classLoader = ConfigurationProcessorIntegrationTests.class.getClassLoader();
50+
List<URL> urls = new ArrayList<>();
51+
CollectionUtils.toIterator(classLoader.getResources("META-INF/spring-configuration-metadata.json"))
52+
.forEachRemaining(urls::add);
53+
for (URL url : urls) {
54+
if (url.toString().contains("spring-boot-configuration-processor-tests")) {
55+
return url;
56+
}
57+
}
58+
throw new IllegalStateException("Unable to find correct configuration-metadata resource from " + urls);
4959
}
5060

5161
@Test

0 commit comments

Comments
 (0)