Skip to content

Commit

Permalink
Add test case to improve the YamlWriter line coverage (EsotericSoftwa…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr14huashao authored Jul 14, 2020
1 parent 817df21 commit 15a6a3d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/com/esotericsoftware/yamlbeans/YamlWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ private void writeInternal (Object object) throws YamlException {
}
}

/** Returns the YAML emitter, which allows the YAML output to be configured. */
public Emitter getEmitter () {
return emitter;
}

/** Writes any buffered objects, then resets the list of anchored objects.
* @see WriteConfig#setAutoAnchor(boolean) */
public void clearAnchors () throws YamlException {
Expand Down
9 changes: 5 additions & 4 deletions test/com/esotericsoftware/yamlbeans/YamlConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,16 @@ public void testSetTagSuffix() throws YamlException {
YamlWriter yamlWriter = new YamlWriter(stringWriter, yamlConfig);
Map<String, String> map = new HashMap<String, String>();
map.put("a", "111");
map.put("btag", "222");
map.put("atag", "!222");
yamlWriter.write(map);
yamlWriter.close();

assertEquals("a: !222 111" + LINE_SEPARATOR, stringWriter.toString());

yamlConfig.setClassTag("!222", String.class);
YamlReader yamlReader = new YamlReader(stringWriter.toString(), yamlConfig);
Map<String, String> result = yamlReader.read(Map.class);
assertTrue(result.containsKey("a"));
assertFalse(result.containsKey("btag"));
assertTrue(result.containsKey("atag"));
assertEquals(map.toString(), result.toString());
}

@Test
Expand Down
18 changes: 18 additions & 0 deletions test/com/esotericsoftware/yamlbeans/YamlWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -309,6 +310,23 @@ public String write (File file) throws YamlException {
assertEquals(object.file, roundTrip.file);
}

public void testSetAlias() throws YamlException {
Map<String, Test> map = new LinkedHashMap<String, Test>();
Test test = new Test();
test.stringValue = "test";
map.put("key1", test);
map.put("key2", test);

StringWriter sw = new StringWriter();
YamlWriter yamlWriter = new YamlWriter(sw);
yamlWriter.setAlias(test, "t");
yamlWriter.write(map);
yamlWriter.close();
assertEquals("!java.util.LinkedHashMap" + LINE_SEPARATOR
+ "key1: &t !com.esotericsoftware.yamlbeans.YamlWriterTest$Test" + LINE_SEPARATOR
+ " stringValue: test" + LINE_SEPARATOR + "key2: *t" + LINE_SEPARATOR, sw.toString());
}

private Object roundTrip (Object object) throws Exception {
return roundTrip(object, null, new YamlConfig());
}
Expand Down

0 comments on commit 15a6a3d

Please sign in to comment.