001package edu.pdx.cs.joy.apptbook; 002 003import edu.pdx.cs.joy.ParserException; 004import org.junit.jupiter.api.Test; 005import org.junit.jupiter.api.io.TempDir; 006 007import java.io.*; 008 009import static org.hamcrest.MatcherAssert.assertThat; 010import static org.hamcrest.Matchers.containsString; 011import static org.hamcrest.Matchers.equalTo; 012 013public class TextDumperTest { 014 015 @Test 016 void appointmentBookOwnerIsDumpedInTextFormat() { 017 String owner = "Test Appointment Book"; 018 AppointmentBook book = new AppointmentBook(owner); 019 020 StringWriter sw = new StringWriter(); 021 TextDumper dumper = new TextDumper(sw); 022 dumper.dump(book); 023 024 String text = sw.toString(); 025 assertThat(text, containsString(owner)); 026 } 027 028 @Test 029 void canParseTextWrittenByTextDumper(@TempDir File tempDir) throws IOException, ParserException { 030 String owner = "Test Appointment Book"; 031 AppointmentBook book = new AppointmentBook(owner); 032 033 File textFile = new File(tempDir, "apptbook.txt"); 034 TextDumper dumper = new TextDumper(new FileWriter(textFile)); 035 dumper.dump(book); 036 037 TextParser parser = new TextParser(new FileReader(textFile)); 038 AppointmentBook read = parser.parse(); 039 assertThat(read.getOwnerName(), equalTo(owner)); 040 } 041}