Skip to content

Commit a83ac5b

Browse files
Fix empty arguments for parameterized tests (#1133)
1 parent d356cbe commit a83ac5b

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/main/java/org/jvnet/hudson/test/injected/JellyTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.jvnet.hudson.test.injected;
22

33
import static org.junit.jupiter.api.Assertions.fail;
4+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
45

56
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
67
import java.io.File;
8+
import java.net.URI;
79
import java.net.URL;
10+
import java.util.Map;
811
import java.util.stream.Stream;
912
import org.dom4j.Document;
1013
import org.dom4j.ProcessingInstruction;
@@ -33,8 +36,12 @@ public class JellyTest extends InjectedTest {
3336

3437
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN")
3538
static Stream<Arguments> resources() throws Exception {
36-
return scan(new File(outputDirectory), "jelly").entrySet().stream()
37-
.map(e -> Arguments.of(Named.of(e.getKey(), e.getValue())));
39+
Map<String, URL> resources = scan(new File(outputDirectory), "jelly");
40+
if (resources.isEmpty()) {
41+
return Stream.of(Arguments.of(Named.of("empty", new URI("file:///empty.jelly").toURL())));
42+
} else {
43+
return resources.entrySet().stream().map(e -> Arguments.of(Named.of(e.getKey(), e.getValue())));
44+
}
3845
}
3946

4047
@BeforeEach
@@ -45,6 +52,8 @@ void beforeEach(JenkinsRule rule) {
4552
@ParameterizedTest
4653
@MethodSource("resources")
4754
void testParseJelly(URL resource) throws Exception {
55+
assumeFalse(resource.toURI().equals(new URI("file:///empty.jelly")), "No jelly file found - skipping test");
56+
4857
jenkinsRule.executeOnServer(() -> {
4958
jct.createContext().compileScript(resource);
5059
Document dom = new SAXReader().read(resource);

src/main/java/org/jvnet/hudson/test/injected/PropertiesTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
import static org.junit.jupiter.api.Assertions.assertNull;
44
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
56

67
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
78
import java.io.File;
89
import java.io.InputStream;
10+
import java.net.URI;
911
import java.net.URL;
1012
import java.nio.ByteBuffer;
1113
import java.nio.charset.CharacterCodingException;
1214
import java.nio.charset.Charset;
1315
import java.nio.charset.CharsetDecoder;
1416
import java.nio.charset.CodingErrorAction;
1517
import java.nio.charset.StandardCharsets;
18+
import java.util.Map;
1619
import java.util.Properties;
1720
import java.util.PropertyResourceBundle;
1821
import java.util.stream.Stream;
@@ -28,14 +31,22 @@ public class PropertiesTest extends InjectedTest {
2831

2932
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN")
3033
static Stream<Arguments> resources() throws Exception {
31-
return scan(new File(outputDirectory), "properties").entrySet().stream()
32-
.map(e -> Arguments.of(Named.of(e.getKey(), e.getValue())));
34+
Map<String, URL> resources = scan(new File(outputDirectory), "properties");
35+
if (resources.isEmpty()) {
36+
return Stream.of(Arguments.of(Named.of("empty", new URI("file:///empty.properties").toURL())));
37+
} else {
38+
return resources.entrySet().stream().map(e -> Arguments.of(Named.of(e.getKey(), e.getValue())));
39+
}
3340
}
3441

3542
@ParameterizedTest
3643
@MethodSource("resources")
3744
@SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD")
3845
void testProperties(URL resource) throws Exception {
46+
assumeFalse(
47+
resource.toURI().equals(new URI("file:///empty.properties")),
48+
"No properties file found - skipping test");
49+
3950
Properties props = new Properties() {
4051
@Override
4152
public synchronized Object put(Object key, Object value) {

0 commit comments

Comments
 (0)