001package edu.pdx.cs.joy.apptbookweb; 002 003import edu.pdx.cs.joy.ParserException; 004import org.junit.jupiter.api.Test; 005 006import java.io.StringReader; 007import java.io.StringWriter; 008import java.util.Collections; 009import java.util.Map; 010 011import static org.hamcrest.MatcherAssert.assertThat; 012import static org.hamcrest.Matchers.equalTo; 013 014public class TextDumperParserTest { 015 016 @Test 017 void emptyMapCanBeDumpedAndParsed() throws ParserException { 018 Map<String, String> map = Collections.emptyMap(); 019 Map<String, String> read = dumpAndParse(map); 020 assertThat(read, equalTo(map)); 021 } 022 023 private Map<String, String> dumpAndParse(Map<String, String> map) throws ParserException { 024 StringWriter sw = new StringWriter(); 025 TextDumper dumper = new TextDumper(sw); 026 dumper.dump(map); 027 028 String text = sw.toString(); 029 030 TextParser parser = new TextParser(new StringReader(text)); 031 return parser.parse(); 032 } 033 034 @Test 035 void dumpedTextCanBeParsed() throws ParserException { 036 Map<String, String> map = Map.of("one", "1", "two", "2"); 037 Map<String, String> read = dumpAndParse(map); 038 assertThat(read, equalTo(map)); 039 } 040}