Skip to content

Commit bc53cca

Browse files
committed
[refactor] Make functions reusable
1 parent 92f5c8b commit bc53cca

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

exist-core/src/main/java/org/exist/test/DiffMatcher.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
import org.exist.xquery.value.Sequence;
3838
import org.hamcrest.Description;
3939
import org.hamcrest.DiagnosingMatcher;
40+
import org.w3c.dom.Node;
4041
import org.xmlunit.builder.DiffBuilder;
4142
import org.xmlunit.builder.Input;
4243
import org.xmlunit.diff.Diff;
44+
import org.xmlunit.util.Convert;
4345

4446
import javax.xml.transform.Source;
4547

@@ -142,4 +144,28 @@ public void describeTo(final Description description) {
142144
.appendText("nodes match ")
143145
.appendValue(expectedSource);
144146
}
147+
148+
/**
149+
* Creates an Document Source form an XML String.
150+
*
151+
* @param str a string representation of XML.
152+
*
153+
* @return a Document Source.
154+
*/
155+
public static Source docSource(final String str) {
156+
return Input.fromString(str).build();
157+
}
158+
159+
/**
160+
* Creates an Element Source form an XML String.
161+
*
162+
* @param str a string representation of XML.
163+
*
164+
* @return an Element Source.
165+
*/
166+
public static Source elemSource(final String str) {
167+
final Node documentNode = Convert.toNode(docSource(str));
168+
final Node firstElement = documentNode.getFirstChild();
169+
return Input.fromNode(firstElement).build();
170+
}
145171
}

exist-core/src/test/java/org/exist/xquery/AbsolutePathTests.java

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
import org.exist.xquery.value.IntegerValue;
2929
import org.exist.xquery.value.Sequence;
3030
import org.junit.Test;
31-
import org.w3c.dom.Node;
32-
import org.xmlunit.builder.Input;
33-
import org.xmlunit.util.Convert;
3431

3532
import javax.xml.transform.Source;
3633

34+
import static org.exist.test.DiffMatcher.docSource;
35+
import static org.exist.test.DiffMatcher.elemSource;
3736
import static org.exist.test.XQueryAssertions.assertThatXQResult;
3837
import static org.exist.test.XQueryAssertions.assertXQStaticError;
38+
import static org.exist.test.XQueryAssertions.assertXQResultIdentical;
3939
import static org.exist.test.XQueryAssertions.assertXQResultSimilar;
4040
import static org.hamcrest.Matchers.equalTo;
4141

@@ -95,7 +95,7 @@ public void immediateLambdaWithDocumentAndDoubleSlash() throws EXistException, P
9595
" <result>{ $f($d) }</result>";
9696
final Either<XPathException, Sequence> actual = executeQuery(query);
9797

98-
assertXQResultSimilar(expected, actual);
98+
assertXQResultIdentical(expected, actual);
9999
}
100100

101101
@Test
@@ -108,7 +108,7 @@ public void immediateLambdaWithDocumentAndSlash() throws EXistException, Permiss
108108
" $f($d)";
109109
final Either<XPathException, Sequence> actual = executeQuery(query);
110110

111-
assertXQResultSimilar(expected, actual);
111+
assertXQResultIdentical(expected, actual);
112112
}
113113

114114
@Test
@@ -133,28 +133,4 @@ public void topLevelAbsolutePath() throws EXistException, PermissionDeniedExcept
133133

134134
assertThatXQResult(actual, equalTo(expected));
135135
}
136-
137-
/**
138-
* Creates an Document6 Source form an XML String.
139-
*
140-
* @param str a string representation of XML.
141-
*
142-
* @return a Document Source.
143-
*/
144-
private static Source docSource(final String str) {
145-
return Input.fromString(str).build();
146-
}
147-
148-
/**
149-
* Creates an Element Source form an XML String.
150-
*
151-
* @param str a string representation of XML.
152-
*
153-
* @return an Element Source.
154-
*/
155-
private static Source elemSource(final String str) {
156-
final Node documentNode = Convert.toNode(docSource(str));
157-
final Node firstElement = documentNode.getFirstChild();
158-
return Input.fromNode(firstElement).build();
159-
}
160136
}

0 commit comments

Comments
 (0)