001package edu.pdx.cs.joy.apptbook;
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-apptbook.txt");
019    assertThat(resource, notNullValue());
020
021    TextParser parser = new TextParser(new InputStreamReader(resource));
022    AppointmentBook book = parser.parse();
023    assertThat(book.getOwnerName(), equalTo("Test Appointment Book"));
024  }
025
026  @Test
027  void invalidTextFileThrowsParserException() {
028    InputStream resource = getClass().getResourceAsStream("empty-apptbook.txt");
029    assertThat(resource, notNullValue());
030
031    TextParser parser = new TextParser(new InputStreamReader(resource));
032    assertThrows(ParserException.class, parser::parse);
033  }
034}