001package edu.pdx.cs.joy.phonebill; 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 phoneBillOwnerIsDumpedInTextFormat() { 017 String customer = "Test Phone Bill"; 018 PhoneBill bill = new PhoneBill(customer); 019 020 StringWriter sw = new StringWriter(); 021 TextDumper dumper = new TextDumper(sw); 022 dumper.dump(bill); 023 024 String text = sw.toString(); 025 assertThat(text, containsString(customer)); 026 } 027 028 @Test 029 void canParseTextWrittenByTextDumper(@TempDir File tempDir) throws IOException, ParserException { 030 String customer = "Test Phone Bill"; 031 PhoneBill bill = new PhoneBill(customer); 032 033 File textFile = new File(tempDir, "apptbook.txt"); 034 TextDumper dumper = new TextDumper(new FileWriter(textFile)); 035 dumper.dump(bill); 036 037 TextParser parser = new TextParser(new FileReader(textFile)); 038 PhoneBill read = parser.parse(); 039 assertThat(read.getCustomer(), equalTo(customer)); 040 } 041}