Skip to content

Commit

Permalink
Merge #406 from '379-fixDefaultValueTagInEncoder' of https://github.c…
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed Oct 7, 2021
2 parents f048c33 + c1d58cc commit 8184d8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
public final class SimpleXmlEncoder extends DefaultStreamPipe<ObjectReceiver<String>> {

public static final String ATTRIBUTE_MARKER = "~";
public static final String DEFAULT_VALUE_TAG = "";

private static final String NEW_LINE = "\n";
private static final String INDENT = "\t";
Expand All @@ -73,7 +74,7 @@ public final class SimpleXmlEncoder extends DefaultStreamPipe<ObjectReceiver<Str
private String attributeMarker = ATTRIBUTE_MARKER;
private String rootTag = DefaultXmlPipe.DEFAULT_ROOT_TAG;
private String recordTag = DefaultXmlPipe.DEFAULT_RECORD_TAG;
private String valueTag = DefaultXmlPipe.DEFAULT_VALUE_TAG;
private String valueTag = DEFAULT_VALUE_TAG;
private Map<String, String> namespaces = new HashMap<String, String>();
private boolean writeRootTag = true;
private boolean writeXmlHeader = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.metafacture.framework.helpers.DefaultObjectReceiver;
import org.metafacture.framework.helpers.DefaultXmlPipe;

import java.util.HashMap;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.metafacture.framework.helpers.DefaultObjectReceiver;

/**
* Tests for class {@link SimpleXmlEncoder}.
Expand Down Expand Up @@ -251,6 +253,22 @@ public void issue379_testShouldEncodeConfiguredValueLiteralsAsText() {
getResultXml());
}

@Test
public void issue379_testShouldNotEncodeUnconfiguredValueLiteralsAsText() {
simpleXmlEncoder.startRecord("");
simpleXmlEncoder.literal(DefaultXmlPipe.DEFAULT_VALUE_TAG, VALUE);
simpleXmlEncoder.endRecord();
simpleXmlEncoder.closeStream();

assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<records>" +
"<record>" +
"<value>value</value>" +
"</record>" +
"</records>",
getResultXml());
}

@Test
public void testShouldEncodeMarkedLiteralsAsAttributes() {
simpleXmlEncoder.startRecord("");
Expand Down

0 comments on commit 8184d8d

Please sign in to comment.