Skip to content

Commit 2005446

Browse files
committed
add tests for checkConfiguration()
1 parent f234f26 commit 2005446

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

Diff for: opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/ConfigurationTest.java

+37-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.configuration;
@@ -33,17 +33,23 @@
3333
import java.io.InputStreamReader;
3434
import java.lang.reflect.Field;
3535
import java.lang.reflect.Modifier;
36+
import java.nio.file.Files;
37+
import java.nio.file.Path;
3638
import java.util.LinkedList;
3739
import java.util.stream.Collectors;
40+
import java.util.stream.Stream;
3841
import javax.xml.XMLConstants;
3942
import javax.xml.parsers.SAXParser;
4043
import javax.xml.parsers.SAXParserFactory;
4144

4245
import org.junit.jupiter.api.Test;
4346
import org.junit.jupiter.params.ParameterizedTest;
47+
import org.junit.jupiter.params.provider.Arguments;
48+
import org.junit.jupiter.params.provider.MethodSource;
4449
import org.junit.jupiter.params.provider.ValueSource;
4550
import org.opengrok.indexer.util.ClassUtil;
4651

52+
import org.opengrok.indexer.util.IOUtils;
4753
import org.xml.sax.Attributes;
4854
import org.xml.sax.ext.DefaultHandler2;
4955

@@ -234,4 +240,34 @@ void testLoadingValidConfiguration() throws IOException {
234240
}
235241
}
236242

243+
private static Stream<Arguments> getArgsForTestCheckConfigurationBugPage() {
244+
return Stream.of(
245+
Arguments.of(true, true),
246+
Arguments.of(true, false),
247+
Arguments.of(false, true),
248+
Arguments.of(false, false)
249+
);
250+
}
251+
252+
@ParameterizedTest
253+
@MethodSource("getArgsForTestCheckConfigurationBugPage")
254+
void testCheckConfigurationBugPage(boolean valid, boolean bugPage) throws IOException {
255+
Configuration cfg = new Configuration();
256+
Path tmpSourceRoot = Files.createTempDirectory("sourceRoot");
257+
cfg.setSourceRoot(tmpSourceRoot.toString());
258+
Path tmpDataRoot = Files.createTempDirectory("dataRoot");
259+
cfg.setDataRoot(tmpDataRoot.toString());
260+
if (bugPage) {
261+
cfg.setBugPage("http://example.org/bug?" + (valid ? "" : "\""));
262+
} else {
263+
cfg.setReviewPage("http://example.org/review?" + (valid ? "" : "\""));
264+
}
265+
if (!valid) {
266+
assertThrows(Configuration.ConfigurationException.class, cfg::checkConfiguration);
267+
} else {
268+
assertDoesNotThrow(cfg::checkConfiguration);
269+
}
270+
IOUtils.removeRecursive(tmpSourceRoot);
271+
IOUtils.removeRecursive(tmpDataRoot);
272+
}
237273
}

0 commit comments

Comments
 (0)