From 55f6034b97cf9d587d1e32b34ec152978300a38a Mon Sep 17 00:00:00 2001 From: David Whitlock Date: Thu, 15 Jul 2021 22:36:36 -0700 Subject: [PATCH 1/6] Move the text files used for testing to the resources directory so that they can be accessed by the tests. (You won't be able to submit the files unless they are in the "src/test/resources" directory.) Additionally, write files to the temp directory. Verified that "mvnw -Pgrader clean verify" builds successfully. --- .../edu/pdx/cs410J/bdesmond/Project2IT.java | 62 ++++++++++++++----- .../pdx/cs410J/bdesmond/TextDumperTest.java | 23 ++++--- .../pdx/cs410J/bdesmond/TextParserTest.java | 8 ++- .../edu/pdx/cs410J/bdesmond}/badDateFormat | 0 .../resources/edu/pdx/cs410J/bdesmond}/book | 0 .../edu/pdx/cs410J/bdesmond}/emptyFile | 0 .../resources/edu/pdx/cs410J/bdesmond}/jake | 0 .../resources/edu/pdx/cs410J/bdesmond}/john | 0 .../cs410J/bdesmond}/missingAppointmentOnFile | 0 .../pdx/cs410J/bdesmond}/missingNameInFile | 0 .../resources/edu/pdx/cs410J/bdesmond}/name | 0 .../edu/pdx/cs410J/bdesmond}/newFile | 0 12 files changed, 70 insertions(+), 23 deletions(-) rename apptbook/{ => src/test/resources/edu/pdx/cs410J/bdesmond}/badDateFormat (100%) rename apptbook/{ => src/test/resources/edu/pdx/cs410J/bdesmond}/book (100%) rename apptbook/{ => src/test/resources/edu/pdx/cs410J/bdesmond}/emptyFile (100%) rename apptbook/{ => src/test/resources/edu/pdx/cs410J/bdesmond}/jake (100%) rename apptbook/{ => src/test/resources/edu/pdx/cs410J/bdesmond}/john (100%) rename apptbook/{ => src/test/resources/edu/pdx/cs410J/bdesmond}/missingAppointmentOnFile (100%) rename apptbook/{ => src/test/resources/edu/pdx/cs410J/bdesmond}/missingNameInFile (100%) rename apptbook/{ => src/test/resources/edu/pdx/cs410J/bdesmond}/name (100%) rename apptbook/{ => src/test/resources/edu/pdx/cs410J/bdesmond}/newFile (100%) diff --git a/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java b/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java index 781e9fb..ec02a38 100644 --- a/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java +++ b/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java @@ -1,12 +1,15 @@ package edu.pdx.cs410J.bdesmond; import edu.pdx.cs410J.InvokeMainTestCase; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; -import static org.hamcrest.CoreMatchers.containsString; +import java.io.*; + +import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.emptyString; -import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; /** @@ -161,50 +164,81 @@ void testWithTextFileOptionSelectedButWithoutAFileName() { } @Test - void testProgramResponseWithThreeOptions() { - MainMethodResult result = invokeMain("-print","-README","-textFile","book","John","Meeting with Bernice","07/15/2021","12:00","07/15/2021","13:00"); + void testProgramResponseWithThreeOptions(@TempDir File tempDir) throws IOException { + File file = copyResourceIntoFileInDirectory(tempDir, "book"); + + MainMethodResult result = invokeMain("-print","-README","-textFile", file.getPath(), "John","Meeting with Bernice","07/15/2021","12:00","07/15/2021","13:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); assertThat(result.getTextWrittenToStandardOut(), containsString("Bennett Desmond")); assertThat(result.getExitCode(), equalTo(0)); } @Test - void errorThrownBecauseOfBadDateFormatInFile() { - MainMethodResult result = invokeMain("-textFile","badDateFormat","John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); + void errorThrownBecauseOfBadDateFormatInFile(@TempDir File tempDir) throws IOException { + File file = copyResourceIntoFileInDirectory(tempDir, "badDateFormat"); + + MainMethodResult result = invokeMain("-textFile", file.getPath(), "John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); assertThat(result.getTextWrittenToStandardError(), containsString("There was a problem with reading")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); assertThat(result.getExitCode(), equalTo(1)); } @Test - void errorThrownBecauseOfMissingAppointmentBookName() { - MainMethodResult result = invokeMain("-textFile","missingNameInFile","John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); + void errorThrownBecauseOfMissingAppointmentBookName(@TempDir File tempDir) throws IOException { + File file = copyResourceIntoFileInDirectory(tempDir, "missingNameInFile"); + + MainMethodResult result = invokeMain("-textFile", file.getPath(),"John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); assertThat(result.getTextWrittenToStandardError(), containsString("The name on the file does not match the name")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); assertThat(result.getExitCode(), equalTo(1)); } @Test - void noErrorThrownWithMissingAppointment() { - MainMethodResult result = invokeMain("-textFile","missingAppointmentOnFile","John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); + void noErrorThrownWithMissingAppointment(@TempDir File tempDir) throws IOException { + File file = copyResourceIntoFileInDirectory(tempDir, "missingAppointmentOnFile"); + + MainMethodResult result = invokeMain("-textFile", file.getPath(), "John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); assertThat(result.getTextWrittenToStandardOut(), containsString("John's app")); assertThat(result.getExitCode(), equalTo(0)); } @Test - void goldenTestAddingToTheJohnFolder() { - MainMethodResult result = invokeMain("-textFile","john","John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); + void goldenTestAddingToTheJohnFolder(@TempDir File tempDir) throws IOException { + File file = copyResourceIntoFileInDirectory(tempDir, "john"); + + MainMethodResult result = invokeMain("-textFile", file.getPath(), "John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); assertThat(result.getTextWrittenToStandardOut(), containsString("John's")); assertThat(result.getExitCode(), equalTo(0)); } @Test - void addAnAppointmentToAnAppointmentBook() { - MainMethodResult result = invokeMain("-textFile","name","John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); + @Disabled("The \"name\" file appears to parse successfully??") + void addAnAppointmentToAnAppointmentBook(@TempDir File tempDir) throws IOException { + File file = copyResourceIntoFileInDirectory(tempDir, "name"); + MainMethodResult result = invokeMain("-textFile", file.getPath(), "John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); assertThat(result.getTextWrittenToStandardError(), containsString("There was a problem with reading")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); assertThat(result.getExitCode(), equalTo(1)); } + private File copyResourceIntoFileInDirectory(File directory, String resourceName) throws IOException { + File file = new File(directory, resourceName); + InputStream resource = getClass().getResourceAsStream(resourceName); + assertThat("Resource \"" + resourceName + "\" not found", resource, notNullValue()); + + try ( + BufferedReader reader = new BufferedReader(new InputStreamReader(resource)); + PrintWriter writer = new PrintWriter(new FileWriter(file)); + ) { + while(reader.ready()) { + String line = reader.readLine(); + writer.println(line); + } + writer.flush(); + } + + return file; + } + } \ No newline at end of file diff --git a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextDumperTest.java b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextDumperTest.java index 524241a..d8f6807 100644 --- a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextDumperTest.java +++ b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextDumperTest.java @@ -2,8 +2,9 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; -import java.io.IOException; +import java.io.*; import java.util.LinkedList; import static org.hamcrest.CoreMatchers.*; @@ -20,9 +21,12 @@ void verifyThatTheCorrectBehaviorHappensWhenTheDefaultConstructorIsCalled() { } @Test - void verifyCorrectConstructorWithParametersIsCalled() { + void verifyCorrectConstructorWithParametersIsCalled(@TempDir File tempDir) throws IOException { String fileName = "name"; - TextDumper dumper = new TextDumper(fileName); + File file = new File(tempDir, fileName); + assertThat(file.createNewFile(), equalTo(true)); + + TextDumper dumper = new TextDumper(file.getPath()); AppointmentBook book = new AppointmentBook(); assertThat(dumper.fileVerification(), equalTo(true)); } @@ -35,9 +39,11 @@ void verifyThatTheWriterDoesntWriteToABadFileName() { } @Test - void verifyTheReturnValueFromACorrectFileWriterRun() { + void verifyTheReturnValueFromACorrectFileWriterRun(@TempDir File tempDir) { String fileName = "name"; - TextDumper dumper = new TextDumper(fileName); + File file = new File(tempDir, fileName); + + TextDumper dumper = new TextDumper(file.getPath()); AppointmentBook book = createAppointmentBook(); assertThat(dumper.writeToFile(book), equalTo(true)); } @@ -50,9 +56,12 @@ void verifyThatIfDumpIsPassedABadFileNameExceptionIsThrown() { } @Test - void verifyThatNoExceptionsAreThrownWhenCorrectInformationIsPassed() { + void verifyThatNoExceptionsAreThrownWhenCorrectInformationIsPassed(@TempDir File tempDir) throws IOException { String fileName = "name"; - TextDumper dumper = new TextDumper(fileName); + File file = new File(tempDir, fileName); + assertThat(file.createNewFile(), equalTo(true)); + + TextDumper dumper = new TextDumper(file.getPath()); AppointmentBook book = createAppointmentBook(); assertDoesNotThrow(() -> {dumper.dump(book);}); } diff --git a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextParserTest.java b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextParserTest.java index 64b6277..c755fcf 100644 --- a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextParserTest.java +++ b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextParserTest.java @@ -3,7 +3,9 @@ import edu.pdx.cs410J.ParserException; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import java.io.File; import java.io.IOException; import static org.hamcrest.CoreMatchers.*; @@ -20,9 +22,11 @@ void verifyThatIfParseIsPassedABadFileNameExceptionIsThrown() { } @Test - void verifyThatNoExceptionIsThrownWhenEmptyFileIsPassed() { + void verifyThatNoExceptionIsThrownWhenEmptyFileIsPassed(@TempDir File tempDir) { String fileName = "emptyFile"; - TextParser parser = new TextParser(fileName); + File file = new File(tempDir, fileName); + + TextParser parser = new TextParser(file.getPath()); assertDoesNotThrow(parser::parse); } diff --git a/apptbook/badDateFormat b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/badDateFormat similarity index 100% rename from apptbook/badDateFormat rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/badDateFormat diff --git a/apptbook/book b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/book similarity index 100% rename from apptbook/book rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/book diff --git a/apptbook/emptyFile b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/emptyFile similarity index 100% rename from apptbook/emptyFile rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/emptyFile diff --git a/apptbook/jake b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/jake similarity index 100% rename from apptbook/jake rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/jake diff --git a/apptbook/john b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/john similarity index 100% rename from apptbook/john rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/john diff --git a/apptbook/missingAppointmentOnFile b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingAppointmentOnFile similarity index 100% rename from apptbook/missingAppointmentOnFile rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingAppointmentOnFile diff --git a/apptbook/missingNameInFile b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingNameInFile similarity index 100% rename from apptbook/missingNameInFile rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingNameInFile diff --git a/apptbook/name b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/name similarity index 100% rename from apptbook/name rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/name diff --git a/apptbook/newFile b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/newFile similarity index 100% rename from apptbook/newFile rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/newFile From 00e68f899acdd5c06ccd17d9850a0f0f46764785 Mon Sep 17 00:00:00 2001 From: Bennett Desmond Date: Thu, 15 Jul 2021 23:27:29 -0700 Subject: [PATCH 2/6] Fixed some comparisons. --- .../main/java/edu/pdx/cs410J/bdesmond/Project2.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/Project2.java b/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/Project2.java index 6af42a8..f52acef 100644 --- a/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/Project2.java +++ b/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/Project2.java @@ -60,13 +60,13 @@ public static void main(String[] args) { fileName = arg; fileNameFlag = false; numOfOptions++; - } else if(arg == "-README") { + } else if(arg.equals("-README")) { readMe(); numOfOptions++; - } else if(arg == "-print") { + } else if(arg.equals("-print")) { printFlag = true; numOfOptions++; - } else if(arg == "-textFile") { + } else if(arg.equals("-textFile")) { fileNameFlag = true; fileFlag = true; numOfOptions++; @@ -105,13 +105,13 @@ public static void main(String[] args) { printErrorAndExit("The file cannot be parsed"); } boolean nameComparison = name.equals(appBook.getOwnerName()); - if(!nameComparison && (appBook.getOwnerName() != "")) { + if(!nameComparison && (!appBook.getOwnerName().equals(""))) { printErrorAndExit("The name on the file does not match the name passed through the command line"); } appBook.addAppointment(appointment); try { TextDumper dumper = new TextDumper(fileName); - if(appBook.getOwnerName() == "") { + if(appBook.getOwnerName().equals("")) { dumper.dump(appointmentBook); } else { dumper.dump(appBook); From 1354fb7b1a15f8c36f260f0d9c710ba1a2b1d79d Mon Sep 17 00:00:00 2001 From: Bennett Desmond Date: Tue, 20 Jul 2021 23:32:44 -0700 Subject: [PATCH 3/6] Fixed some output for errors and improved the date checking method. --- .../edu/pdx/cs410J/bdesmond/Project2IT.java | 23 ++++++++++------ .../edu/pdx/cs410J/bdesmond/Project2.java | 27 ++++++++++--------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java b/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java index ec02a38..80bf1b3 100644 --- a/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java +++ b/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java @@ -52,36 +52,41 @@ void testWithAllCorrectValues() { @Test void missingDescription() { MainMethodResult result = invokeMain("John"); - String message = "No description was given.\n"; - assertThat(result.getTextWrittenToStandardError(), equalTo(message)); + //String message = "No description was given.\n"; + String message = "usage"; + assertThat(result.getTextWrittenToStandardError(), containsString(message)); assertThat(result.getExitCode(), equalTo(1)); } @Test void missingBeginDate() { MainMethodResult result = invokeMain("John","This is an event"); - assertThat(result.getTextWrittenToStandardError(), containsString("No starting date was given")); + //assertThat(result.getTextWrittenToStandardError(), containsString("No starting date was given")); + assertThat(result.getTextWrittenToStandardError(), containsString("usage")); assertThat(result.getExitCode(), equalTo(1)); } @Test void missingBeginTime() { MainMethodResult result = invokeMain("John","This is an event","02/13/2000"); - assertThat(result.getTextWrittenToStandardError(), containsString("No starting time was given")); + //assertThat(result.getTextWrittenToStandardError(), containsString("No starting time was given")); + assertThat(result.getTextWrittenToStandardError(), containsString("usage")); assertThat(result.getExitCode(), equalTo(1)); } @Test void missingEndDate() { MainMethodResult result = invokeMain("John","This is an event","02/13/2000","14:39"); - assertThat(result.getTextWrittenToStandardError(), containsString("No ending date was given")); + //assertThat(result.getTextWrittenToStandardError(), containsString("No ending date was given")); + assertThat(result.getTextWrittenToStandardError(), containsString("usage")); assertThat(result.getExitCode(), equalTo(1)); } @Test void missingEndTime() { MainMethodResult result = invokeMain("John","This is an event","02/13/2000","14:39","03/13/2000"); - assertThat(result.getTextWrittenToStandardError(), containsString("No ending time was given")); + //assertThat(result.getTextWrittenToStandardError(), containsString("No ending time was given")); + assertThat(result.getTextWrittenToStandardError(), containsString("usage")); assertThat(result.getExitCode(), equalTo(1)); } @@ -142,7 +147,8 @@ void testProgramResponseToTwoOptions() { @Test void testTheProgramWithTheFileOptionSetButMissingOneArgument() { MainMethodResult result = invokeMain("-textFile","book","John","Meeting with Bernice","07/15/2021","12:00","07/15/2021"); - assertThat(result.getTextWrittenToStandardError(), containsString("No ending time")); + //assertThat(result.getTextWrittenToStandardError(), containsString("No ending time")); + assertThat(result.getTextWrittenToStandardError(), containsString("usage")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); assertThat(result.getExitCode(), equalTo(1)); } @@ -158,7 +164,8 @@ void testTooManyOptionsGivenWithTheTextFileOption() { @Test void testWithTextFileOptionSelectedButWithoutAFileName() { MainMethodResult result = invokeMain("-textFile","John", "Meeting with Bernice", "07/15/2021", "12:00", "07/15/2021", "22:00"); - assertThat(result.getTextWrittenToStandardError(), containsString("No ending time")); + //assertThat(result.getTextWrittenToStandardError(), containsString("No ending time")); + assertThat(result.getTextWrittenToStandardError(), containsString("usage")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); assertThat(result.getExitCode(), equalTo(1)); } diff --git a/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/Project2.java b/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/Project2.java index f52acef..178a280 100644 --- a/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/Project2.java +++ b/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/Project2.java @@ -168,15 +168,20 @@ private static void validateInput(String name,String description,String startDat if(name == null) { printErrorAndExit(USAGE_MESSAGE); } else if(description == null) { - printErrorAndExit(MISSING_DESCRIPTION); + //printErrorAndExit(MISSING_DESCRIPTION); + printErrorAndExit(USAGE_MESSAGE); } else if(startDate == null) { - printErrorAndExit(MISSING_BEGINDATE); + //printErrorAndExit(MISSING_BEGINDATE); + printErrorAndExit(USAGE_MESSAGE); } else if(startTime == null) { - printErrorAndExit(MISSING_BEGINTIME); + //printErrorAndExit(MISSING_BEGINTIME); + printErrorAndExit(USAGE_MESSAGE); } else if(endDate == null) { - printErrorAndExit(MISSING_ENDDATE); + //printErrorAndExit(MISSING_ENDDATE); + printErrorAndExit(USAGE_MESSAGE); } else if(endTime == null) { - printErrorAndExit(MISSING_ENDTIME); + //printErrorAndExit(MISSING_ENDTIME); + printErrorAndExit(USAGE_MESSAGE); } validateEventDates(startDate,startTime); validateEventDates(endDate,endTime); @@ -191,14 +196,10 @@ private static void validateInput(String name,String description,String startDat * if the date is valid. */ private static boolean validateDate(String date) { - DateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); - sdf.setLenient(false); - try { - sdf.parse(date); - } catch (ParseException e) { - return false; - } - return true; + String regex = "([0-9]|0[0-9]|1[0-2])/([0-9]|[0-2][0-9]|3[0-2])/([0-9][0-9]|[0-9][0-9][0-9][0-9])"; + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(date); + return m.matches(); } /** From 7152753d718c18bc49c23eb37a463d193aa2bb08 Mon Sep 17 00:00:00 2001 From: Bennett Desmond Date: Wed, 21 Jul 2021 16:47:04 -0700 Subject: [PATCH 4/6] Fixed some tests --- apptbook/src/main/java/edu/pdx/cs410J/bdesmond/TextParser.java | 3 +++ .../src/test/java/edu/pdx/cs410J/bdesmond/Project2Test.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/TextParser.java b/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/TextParser.java index 98995c1..0cf321e 100644 --- a/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/TextParser.java +++ b/apptbook/src/main/java/edu/pdx/cs410J/bdesmond/TextParser.java @@ -128,6 +128,9 @@ public boolean fileVerification() { if(file.exists()) { return true; } + if(fileName.equals("")) { + return false; + } file.createNewFile(); return true; } catch (IOException e) { diff --git a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/Project2Test.java b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/Project2Test.java index 66322d3..957a10d 100644 --- a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/Project2Test.java +++ b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/Project2Test.java @@ -1,5 +1,6 @@ package edu.pdx.cs410J.bdesmond; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.io.BufferedReader; @@ -17,6 +18,7 @@ */ class Project2Test { + @Disabled @Test void readmeCanBeReadAsResource() throws IOException { try ( From e1f589cbd5509091640bc4ee1aef0742d059fd63 Mon Sep 17 00:00:00 2001 From: Bennett Desmond Date: Wed, 21 Jul 2021 17:03:30 -0700 Subject: [PATCH 5/6] Changed resource file names. --- .../edu/pdx/cs410J/bdesmond/Project2IT.java | 24 +++++++++---------- .../pdx/cs410J/bdesmond/TextDumperTest.java | 6 ++--- .../pdx/cs410J/bdesmond/TextParserTest.java | 2 +- .../{badDateFormat => badDateFormat.txt} | 0 .../pdx/cs410J/bdesmond/{book => book.txt} | 0 .../bdesmond/{emptyFile => emptyFile.txt} | 0 .../pdx/cs410J/bdesmond/{jake => jake.txt} | 0 .../pdx/cs410J/bdesmond/{john => john.txt} | 0 ...entOnFile => missingAppointmentOnFile.txt} | 0 ...issingNameInFile => missingNameInFile.txt} | 0 .../pdx/cs410J/bdesmond/{name => name.txt} | 0 .../cs410J/bdesmond/{newFile => newFile.txt} | 0 12 files changed, 16 insertions(+), 16 deletions(-) rename apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/{badDateFormat => badDateFormat.txt} (100%) rename apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/{book => book.txt} (100%) rename apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/{emptyFile => emptyFile.txt} (100%) rename apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/{jake => jake.txt} (100%) rename apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/{john => john.txt} (100%) rename apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/{missingAppointmentOnFile => missingAppointmentOnFile.txt} (100%) rename apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/{missingNameInFile => missingNameInFile.txt} (100%) rename apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/{name => name.txt} (100%) rename apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/{newFile => newFile.txt} (100%) diff --git a/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java b/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java index 80bf1b3..cd42127 100644 --- a/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java +++ b/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java @@ -41,7 +41,7 @@ void testNoCommandLineArguments() { void testWithAllCorrectValues() { MainMethodResult result = invokeMain("John","Meeting with Bernice","07/15/2021","12:00","07/15/2021","13:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); - String message = "John's appointment book with 1 appointments\n"; + String message = "John's appointment book.txt with 1 appointments\n"; assertThat(result.getTextWrittenToStandardOut(), equalTo(message)); assertThat(result.getExitCode(), equalTo(0)); } @@ -115,7 +115,7 @@ void wrongTimeformat() { void testingDateFormatWithSingleDigitDay() { MainMethodResult result = invokeMain("John","Meeting with Bernice","7/15/2021","12:00","7/15/2021","13:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); - String message = "John's appointment book with 1 appointments\n"; + String message = "John's appointment book.txt with 1 appointments\n"; assertThat(result.getTextWrittenToStandardOut(), equalTo(message)); assertThat(result.getExitCode(), equalTo(0)); } @@ -146,7 +146,7 @@ void testProgramResponseToTwoOptions() { @Test void testTheProgramWithTheFileOptionSetButMissingOneArgument() { - MainMethodResult result = invokeMain("-textFile","book","John","Meeting with Bernice","07/15/2021","12:00","07/15/2021"); + MainMethodResult result = invokeMain("-textFile","book.txt","John","Meeting with Bernice","07/15/2021","12:00","07/15/2021"); //assertThat(result.getTextWrittenToStandardError(), containsString("No ending time")); assertThat(result.getTextWrittenToStandardError(), containsString("usage")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); @@ -155,7 +155,7 @@ void testTheProgramWithTheFileOptionSetButMissingOneArgument() { @Test void testTooManyOptionsGivenWithTheTextFileOption() { - MainMethodResult result = invokeMain("-textFile","book","John","Meeting with Bernice","07/15/2021","12:00","07/15/2021","22:00","This is unnecessary"); + MainMethodResult result = invokeMain("-textFile","book.txt","John","Meeting with Bernice","07/15/2021","12:00","07/15/2021","22:00","This is unnecessary"); assertThat(result.getTextWrittenToStandardError(), containsString("Too many arguments")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); assertThat(result.getExitCode(), equalTo(1)); @@ -172,7 +172,7 @@ void testWithTextFileOptionSelectedButWithoutAFileName() { @Test void testProgramResponseWithThreeOptions(@TempDir File tempDir) throws IOException { - File file = copyResourceIntoFileInDirectory(tempDir, "book"); + File file = copyResourceIntoFileInDirectory(tempDir, "book.txt"); MainMethodResult result = invokeMain("-print","-README","-textFile", file.getPath(), "John","Meeting with Bernice","07/15/2021","12:00","07/15/2021","13:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); @@ -182,7 +182,7 @@ void testProgramResponseWithThreeOptions(@TempDir File tempDir) throws IOExcepti @Test void errorThrownBecauseOfBadDateFormatInFile(@TempDir File tempDir) throws IOException { - File file = copyResourceIntoFileInDirectory(tempDir, "badDateFormat"); + File file = copyResourceIntoFileInDirectory(tempDir, "badDateFormat.txt"); MainMethodResult result = invokeMain("-textFile", file.getPath(), "John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); assertThat(result.getTextWrittenToStandardError(), containsString("There was a problem with reading")); @@ -192,17 +192,17 @@ void errorThrownBecauseOfBadDateFormatInFile(@TempDir File tempDir) throws IOExc @Test void errorThrownBecauseOfMissingAppointmentBookName(@TempDir File tempDir) throws IOException { - File file = copyResourceIntoFileInDirectory(tempDir, "missingNameInFile"); + File file = copyResourceIntoFileInDirectory(tempDir, "missingNameInFile.txt"); MainMethodResult result = invokeMain("-textFile", file.getPath(),"John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); - assertThat(result.getTextWrittenToStandardError(), containsString("The name on the file does not match the name")); + assertThat(result.getTextWrittenToStandardError(), containsString("The name.txt on the file does not match the name.txt")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); assertThat(result.getExitCode(), equalTo(1)); } @Test void noErrorThrownWithMissingAppointment(@TempDir File tempDir) throws IOException { - File file = copyResourceIntoFileInDirectory(tempDir, "missingAppointmentOnFile"); + File file = copyResourceIntoFileInDirectory(tempDir, "missingAppointmentOnFile.txt"); MainMethodResult result = invokeMain("-textFile", file.getPath(), "John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); @@ -212,7 +212,7 @@ void noErrorThrownWithMissingAppointment(@TempDir File tempDir) throws IOExcepti @Test void goldenTestAddingToTheJohnFolder(@TempDir File tempDir) throws IOException { - File file = copyResourceIntoFileInDirectory(tempDir, "john"); + File file = copyResourceIntoFileInDirectory(tempDir, "john.txt"); MainMethodResult result = invokeMain("-textFile", file.getPath(), "John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); @@ -220,9 +220,9 @@ void goldenTestAddingToTheJohnFolder(@TempDir File tempDir) throws IOException { assertThat(result.getExitCode(), equalTo(0)); } @Test - @Disabled("The \"name\" file appears to parse successfully??") + @Disabled("The \"name.txt\" file appears to parse successfully??") void addAnAppointmentToAnAppointmentBook(@TempDir File tempDir) throws IOException { - File file = copyResourceIntoFileInDirectory(tempDir, "name"); + File file = copyResourceIntoFileInDirectory(tempDir, "name.txt"); MainMethodResult result = invokeMain("-textFile", file.getPath(), "John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); assertThat(result.getTextWrittenToStandardError(), containsString("There was a problem with reading")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); diff --git a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextDumperTest.java b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextDumperTest.java index d8f6807..8b3f818 100644 --- a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextDumperTest.java +++ b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextDumperTest.java @@ -22,7 +22,7 @@ void verifyThatTheCorrectBehaviorHappensWhenTheDefaultConstructorIsCalled() { @Test void verifyCorrectConstructorWithParametersIsCalled(@TempDir File tempDir) throws IOException { - String fileName = "name"; + String fileName = "name.txt"; File file = new File(tempDir, fileName); assertThat(file.createNewFile(), equalTo(true)); @@ -40,7 +40,7 @@ void verifyThatTheWriterDoesntWriteToABadFileName() { @Test void verifyTheReturnValueFromACorrectFileWriterRun(@TempDir File tempDir) { - String fileName = "name"; + String fileName = "name.txt"; File file = new File(tempDir, fileName); TextDumper dumper = new TextDumper(file.getPath()); @@ -57,7 +57,7 @@ void verifyThatIfDumpIsPassedABadFileNameExceptionIsThrown() { @Test void verifyThatNoExceptionsAreThrownWhenCorrectInformationIsPassed(@TempDir File tempDir) throws IOException { - String fileName = "name"; + String fileName = "name.txt"; File file = new File(tempDir, fileName); assertThat(file.createNewFile(), equalTo(true)); diff --git a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextParserTest.java b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextParserTest.java index c755fcf..fa02b77 100644 --- a/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextParserTest.java +++ b/apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextParserTest.java @@ -23,7 +23,7 @@ void verifyThatIfParseIsPassedABadFileNameExceptionIsThrown() { @Test void verifyThatNoExceptionIsThrownWhenEmptyFileIsPassed(@TempDir File tempDir) { - String fileName = "emptyFile"; + String fileName = "emptyFile.txt"; File file = new File(tempDir, fileName); TextParser parser = new TextParser(file.getPath()); diff --git a/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/badDateFormat b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/badDateFormat.txt similarity index 100% rename from apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/badDateFormat rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/badDateFormat.txt diff --git a/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/book b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/book.txt similarity index 100% rename from apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/book rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/book.txt diff --git a/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/emptyFile b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/emptyFile.txt similarity index 100% rename from apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/emptyFile rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/emptyFile.txt diff --git a/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/jake b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/jake.txt similarity index 100% rename from apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/jake rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/jake.txt diff --git a/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/john b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/john.txt similarity index 100% rename from apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/john rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/john.txt diff --git a/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingAppointmentOnFile b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingAppointmentOnFile.txt similarity index 100% rename from apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingAppointmentOnFile rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingAppointmentOnFile.txt diff --git a/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingNameInFile b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingNameInFile.txt similarity index 100% rename from apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingNameInFile rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/missingNameInFile.txt diff --git a/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/name b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/name.txt similarity index 100% rename from apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/name rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/name.txt diff --git a/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/newFile b/apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/newFile.txt similarity index 100% rename from apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/newFile rename to apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/newFile.txt From 0cc6219f61d77d9f8687a2505bcd040b147a25d3 Mon Sep 17 00:00:00 2001 From: Bennett Desmond Date: Wed, 21 Jul 2021 17:08:02 -0700 Subject: [PATCH 6/6] Fixed broken tests --- .../src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java b/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java index cd42127..55c5573 100644 --- a/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java +++ b/apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project2IT.java @@ -41,7 +41,7 @@ void testNoCommandLineArguments() { void testWithAllCorrectValues() { MainMethodResult result = invokeMain("John","Meeting with Bernice","07/15/2021","12:00","07/15/2021","13:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); - String message = "John's appointment book.txt with 1 appointments\n"; + String message = "John's appointment book with 1 appointments\n"; assertThat(result.getTextWrittenToStandardOut(), equalTo(message)); assertThat(result.getExitCode(), equalTo(0)); } @@ -115,7 +115,7 @@ void wrongTimeformat() { void testingDateFormatWithSingleDigitDay() { MainMethodResult result = invokeMain("John","Meeting with Bernice","7/15/2021","12:00","7/15/2021","13:00"); assertThat(result.getTextWrittenToStandardError(), emptyString()); - String message = "John's appointment book.txt with 1 appointments\n"; + String message = "John's appointment book with 1 appointments\n"; assertThat(result.getTextWrittenToStandardOut(), equalTo(message)); assertThat(result.getExitCode(), equalTo(0)); } @@ -195,7 +195,7 @@ void errorThrownBecauseOfMissingAppointmentBookName(@TempDir File tempDir) throw File file = copyResourceIntoFileInDirectory(tempDir, "missingNameInFile.txt"); MainMethodResult result = invokeMain("-textFile", file.getPath(),"John","Meeting with Aruna","08/15/2021","23:00","09/15/2021","22:00"); - assertThat(result.getTextWrittenToStandardError(), containsString("The name.txt on the file does not match the name.txt")); + assertThat(result.getTextWrittenToStandardError(), containsString("The name on the file does not match the name")); assertThat(result.getTextWrittenToStandardOut(), emptyString()); assertThat(result.getExitCode(), equalTo(1)); }