Skip to content

Commit 51ce716

Browse files
committed
[refactor] Improve XQsuite code..
1 parent a3d385b commit 51ce716

File tree

5 files changed

+15
-74
lines changed

5 files changed

+15
-74
lines changed

exist-core/src/main/java/org/exist/test/runner/AbstractTestRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected static Sequence executeQuery(final BrokerPool brokerPool, final Source
119119
}
120120
}
121121

122-
protected static String checkDescription(Object source, String description) {
122+
protected static String checkDescription(final Object source, final String description) {
123123
if (description == null) {
124124
throw new IllegalArgumentException(source + " description is null");
125125
}

exist-core/src/main/java/org/exist/test/runner/ExtTestErrorFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private XPathException errorMapAsXPathException(final MapType errorMap) throws X
154154
final String methodName = matcherAt.group(2);
155155
final String fileName = matcherAt.group(3);
156156
final String lineNumber = matcherAt.group(4);
157-
return new StackTraceElement(declaringClass, methodName, fileName, Integer.valueOf(lineNumber));
157+
return new StackTraceElement(declaringClass, methodName, fileName, Integer.parseInt(lineNumber));
158158
} else {
159159
return null;
160160
}

exist-core/src/main/java/org/exist/test/runner/XMLTestRunner.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ private static XMLTestInfo extractTestInfo(final Path path, final Document doc)
164164
}
165165

166166
private String getSuiteName() {
167-
return "xmlts." + info.getName();
167+
return "xmlts." + info.name();
168168
}
169169

170170
@Override
171171
public Description getDescription() {
172172
final String suiteName = checkDescription(info, getSuiteName());
173173
final Description description = Description.createSuiteDescription(suiteName);
174-
for (final String childName : info.getChildNames()) {
174+
for (final String childName : info.childNames()) {
175175
description.addChild(Description.createTestDescription(suiteName, checkDescription(info, childName)));
176176
}
177177
return description;
@@ -225,29 +225,6 @@ private static Document parse(final Path path) throws ParserConfigurationExcepti
225225
return adapter.getDocument();
226226
}
227227

228-
private static class XMLTestInfo {
229-
@Nullable private final String name;
230-
@Nullable private final String description;
231-
private final List<String> childNames;
232-
233-
private XMLTestInfo(@Nullable final String name, @Nullable final String description, final List<String> childNames) {
234-
this.name = name;
235-
this.description = description;
236-
this.childNames = childNames;
237-
}
238-
239-
@Nullable
240-
public String getName() {
241-
return name;
242-
}
243-
244-
@Nullable
245-
public String getDescription() {
246-
return description;
247-
}
248-
249-
public List<String> getChildNames() {
250-
return childNames;
251-
}
228+
private record XMLTestInfo(@Nullable String name, @Nullable String description, List<String> childNames) {
252229
}
253230
}

exist-core/src/main/java/org/exist/test/runner/XQueryTestRunner.java

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ private static XQueryTestInfo extractTestInfo(final Path path) throws Initializa
173173
}
174174

175175
private String getSuiteName() {
176-
if (info.getNamespace() == null) {
176+
if (info.namespace() == null) {
177177
return path.getFileName().toString();
178178
}
179179

180-
return namespaceToPackageName(info.getNamespace());
180+
return namespaceToPackageName(info.namespace());
181181
}
182182

183183
private String namespaceToPackageName(final String namespace) {
@@ -220,8 +220,8 @@ private void pathToPackageName(String path, final StringBuilder buffer) {
220220
public Description getDescription() {
221221
final String suiteName = checkDescription(this, getSuiteName());
222222
final Description description = Description.createSuiteDescription(suiteName);
223-
for (final XQueryTestInfo.TestFunctionDef testFunctionDef : info.getTestFunctions()) {
224-
description.addChild(Description.createTestDescription(suiteName, checkDescription(testFunctionDef, testFunctionDef.getLocalName())));
223+
for (final XQueryTestInfo.TestFunctionDef testFunctionDef : info.testFunctions()) {
224+
description.addChild(Description.createTestDescription(suiteName, checkDescription(testFunctionDef, testFunctionDef.localName())));
225225
}
226226
return description;
227227
}
@@ -257,45 +257,9 @@ public void run(final RunNotifier notifier) {
257257
}
258258
}
259259

260-
private static class XQueryTestInfo {
261-
private final String prefix;
262-
private final String namespace;
263-
private final List<TestFunctionDef> testFunctions;
260+
private record XQueryTestInfo(String prefix, String namespace, List<TestFunctionDef> testFunctions) {
264261

265-
private XQueryTestInfo(final String prefix, final String namespace, final List<TestFunctionDef> testFunctions) {
266-
this.prefix = prefix;
267-
this.namespace = namespace;
268-
this.testFunctions = testFunctions;
269-
}
270-
271-
public String getPrefix() {
272-
return prefix;
273-
}
274-
275-
public String getNamespace() {
276-
return namespace;
277-
}
278-
279-
public List<TestFunctionDef> getTestFunctions() {
280-
return testFunctions;
281-
}
282-
283-
private static class TestFunctionDef {
284-
private final String localName;
285-
private final int arity;
286-
287-
private TestFunctionDef(final String localName, final int arity) {
288-
this.localName = localName;
289-
this.arity = arity;
290-
}
291-
292-
public String getLocalName() {
293-
return localName;
294-
}
295-
296-
public int getArity() {
297-
return arity;
262+
private record TestFunctionDef(String localName, int arity) {
298263
}
299264
}
300-
}
301265
}

exist-core/src/main/java/org/exist/test/runner/XSuite.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
/**
4848
* Using <code>XSuite</code> as a runner allows you to manually
4949
* build a suite containing tests from both:
50-
*
50+
* <p>
5151
* 1. XQSuite - as defined in $EXIST_HOME/src/org/exist/xquery/lib/xqsuite/xqsuite.xql
5252
* 2. XML Test - as defined in $EXIST_HOME/src/org/exist/xquery/lib/test.xq
53-
*
53+
* <p>
5454
* To use it, annotate a class
5555
* with <code>@RunWith(XSuite.class)</code> and <code>@XSuiteClasses({"extensions/my-extension/src/test/xquery", ...})</code>.
5656
* When you run this class, it will run all the tests in all the suite classes.
@@ -67,7 +67,7 @@ public class XSuite extends ParentRunner<Runner> {
6767
public static Runner emptySuite() {
6868
try {
6969
return new XSuite((Class<?>) null, new String[0]);
70-
} catch (InitializationError e) {
70+
} catch (final InitializationError e) {
7171
throw new RuntimeException("This shouldn't be possible");
7272
}
7373
}
@@ -204,7 +204,7 @@ private static List<Runner> getRunners(final String[] suites, final boolean para
204204
if (Files.isDirectory(path)) {
205205
// directory of files of test(s)
206206
try (final Stream<Path> children = Files.list(path)) {
207-
for(final Path child : children.collect(Collectors.toList())) {
207+
for(final Path child : children.toList()) {
208208
if(!Files.isDirectory(child)) {
209209
final Runner runner = getRunner(child, parallel);
210210
if(runner != null) {

0 commit comments

Comments
 (0)