Skip to content

Commit

Permalink
Reverting NewlineText singleton (Sonar, no like).
Browse files Browse the repository at this point in the history
Testing parent null (which will never occur in reality)
  • Loading branch information
Björn Ekryd committed Feb 20, 2024
1 parent e79e319 commit 5e57e8b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 0 additions & 3 deletions sorter/src/main/java/sortpom/content/NewlineText.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
* in XmlProcessor.PatchedXMLWriter
*/
public class NewlineText extends AbstractText {
public static final NewlineText INSTANCE = new NewlineText();
private static final long serialVersionUID = -7552189498553321263L;

private NewlineText() {}

/**
* This returns a <code>String</code> representation of the <code>NewlineText</code>, suitable for
* debugging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Wrapper<Node> createWrapper(Text text) {
return new UnsortedWrapper<>(text);
}

private boolean isElementSpacePreserved(Element element) {
boolean isElementSpacePreserved(Element element) {
if (element == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/** A wrapper that lets is element be unsorted */
public class UnsortedWrapper<T extends Node> implements Wrapper<T> {
public static final UnsortedWrapper<Node> NEWLINE_TEXT_WRAPPER_INSTANCE =
new UnsortedWrapper<>(NewlineText.INSTANCE);
new UnsortedWrapper<>(new NewlineText());

/** The wrapped dom content. */
private final T content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.dom4j.dom.DOMText;
import org.dom4j.tree.DefaultText;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -40,4 +41,10 @@ void testIsEmptyLine() {
assertTrue(textWrapperCreator.isBlankLineOrLines(new DefaultText("\r\n\r\n")));
assertFalse(textWrapperCreator.isBlankLineOrLines(new DefaultText(" ")));
}

@Test
void textNodeWithNullParentShouldNotCrash() {
var text = new DOMText("Hi!");
assertFalse(textWrapperCreator.isElementSpacePreserved(text.getParent()));
}
}

0 comments on commit 5e57e8b

Please sign in to comment.