001package edu.pdx.cs.joy.phonebill; 002 003import edu.pdx.cs.joy.ParserException; 004import org.junit.jupiter.api.Test; 005 006import java.io.InputStream; 007import java.io.InputStreamReader; 008 009import static org.hamcrest.MatcherAssert.assertThat; 010import static org.hamcrest.Matchers.equalTo; 011import static org.hamcrest.Matchers.notNullValue; 012import static org.junit.jupiter.api.Assertions.assertThrows; 013 014public class TextParserTest { 015 016 @Test 017 void validTextFileCanBeParsed() throws ParserException { 018 InputStream resource = getClass().getResourceAsStream("valid-phonebill.txt"); 019 assertThat(resource, notNullValue()); 020 021 TextParser parser = new TextParser(new InputStreamReader(resource)); 022 PhoneBill bill = parser.parse(); 023 assertThat(bill.getCustomer(), equalTo("Test Phone Bill")); 024 } 025 026 @Test 027 void invalidTextFileThrowsParserException() { 028 InputStream resource = getClass().getResourceAsStream("empty-phonebill.txt"); 029 assertThat(resource, notNullValue()); 030 031 TextParser parser = new TextParser(new InputStreamReader(resource)); 032 assertThrows(ParserException.class, parser::parse); 033 } 034}