Skip to content

Commit

Permalink
feat(objectionary#348): WithoutLines.java
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Jul 29, 2024
1 parent c2af398 commit 312804a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/test/java/it/DetectiveIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ void compare(final Xmir other) throws CompareException {
try {
this.results.oneMore();
final List<XmlMethod> gmethods = new XmlProgram(
SameXml.withoutLines(this.xml(gpath))
new SameXml.WithoutLines(this.xml(gpath)).value()
).top().methods();
final List<XmlMethod> bmethods = new XmlProgram(
SameXml.withoutLines(this.xml(rpath))
new SameXml.WithoutLines(this.xml(gpath)).value()
).top().methods();
final int size = gmethods.size();
for (int index = 0; index < size; ++index) {
Expand Down
50 changes: 32 additions & 18 deletions src/test/java/org/eolang/opeo/SameXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import org.cactoos.Scalar;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.xembly.Directives;
Expand Down Expand Up @@ -66,8 +67,8 @@ public SameXml(final String expected) {

@Override
public boolean matchesSafely(final String item) {
return SameXml.withoutLines(new XMLDocument(this.expected))
.equals(SameXml.withoutLines(new XMLDocument(item)));
return new SameXml.WithoutLines(new XMLDocument(this.expected)).value()
.equals(new SameXml.WithoutLines(new XMLDocument(item)).value());
}

@Override
Expand All @@ -78,23 +79,36 @@ public void describeTo(final Description description) {
}

/**
* Remove 'line' attributes from the XML document.
* @param original Original XML document.
* @return XML document without 'line' attributes.
* @todo #329:30min Avoid Using Public Static Method From SameXml Class.
* I exposed this method to avoid the problem with XMIR comparision in {@link it.DetectiveIT}
* test. But it's much better to hide this static method and invent more OOP-suitable solution.
* The same XML, but without lines.
*/
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static XML withoutLines(final XML original) {
try {
return new XMLDocument(
new Xembler(
new Directives().xpath(".//o[@line]/@line").remove()
).apply(original.node())
);
} catch (final ImpossibleModificationException exception) {
throw new IllegalStateException("Failed to remove 'line' attributes", exception);
public static final class WithoutLines implements Scalar<XML> {

/**
* The original.
*/
private final XML original;

/**
* Constructor.
* @param orgnl original XML
*/
public WithoutLines(final XML orgnl) {
this.original = orgnl;
}

@Override
public XML value() {
try {
return new XMLDocument(
new Xembler(
new Directives().xpath(".//o[@line]/@line").remove()
).apply(this.original.node())
);
} catch (final ImpossibleModificationException exception) {
throw new IllegalStateException(
"Failed to remove 'line' attributes", exception
);
}
}
}
}

0 comments on commit 312804a

Please sign in to comment.