Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions apptbook/johnFile
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
John
Meeting with Asha,7/3/21 12:00 AM,7/4/21 2:00 PM
Meeting with Casandra,7/13/21 12:00 AM,7/14/21 2:00 PM
Meeting with Elon,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with One,7/1/21 12:00 AM,7/3/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with THree,7/10/21 12:00 AM,7/11/21 2:00 PM
abc,7/10/21 12:00 AM,7/11/21 2:00 PM
bcd,7/10/21 12:00 AM,7/11/21 2:00 PM
Meeting with Four,7/12/21 12:00 AM,7/13/21 2:00 PM
Meeting with Four,7/12/21 12:00 AM,7/13/21 2:00 PM
Meeting with Four,7/12/21 12:00 AM,7/13/21 2:00 PM
Meeting with Four,7/12/21 12:00 AM,7/13/21 2:00 PM
Meeting with Four,7/12/21 12:00 AM,7/13/21 2:00 PM
Meeting with Four,7/12/21 12:00 AM,7/13/21 2:00 PM
Meeting with Four,7/12/21 12:00 AM,7/13/21 2:00 PM
Meeting with Four,7/12/21 12:00 AM,7/13/21 2:00 PM
Meeting with Four,7/12/21 12:00 AM,7/13/21 2:00 PM
18 changes: 13 additions & 5 deletions apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project3IT.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void correctRunWithPrettyPrintSelectedAndAFileGiven(@TempDir File tempDir) throw

MainMethodResult result = invokeMain("-pretty",filePretty.getPath(),"-textFile",fileStor.getPath(), "John","Meeting with Matthew","07/15/2021", "12:00", "am","07/15/2021", "2:00","pm");
assertThat(result.getTextWrittenToStandardError(), emptyString());
assertThat(result.getTextWrittenToStandardOut(), containsString("John's appointment book with "));
assertThat(result.getTextWrittenToStandardOut(), containsString("John's appointment book with "));
assertThat(result.getExitCode(), equalTo(0));
}

Expand All @@ -255,21 +255,29 @@ void correctRunWithPrettyPrintSelectedAndNoFileGiven(@TempDir File tempDir) thro

MainMethodResult result = invokeMain("-pretty","-","-textFile", fileStor.getPath(), "John","Meeting with Aruna","07/15/2021", "12:00", "am","07/15/2021", "2:00","pm");
assertThat(result.getTextWrittenToStandardError(), emptyString());
assertThat(result.getTextWrittenToStandardOut(), containsString("John's appointment book with "));
assertThat(result.getTextWrittenToStandardOut(), containsString("John's appointment book with "));
assertThat(result.getTextWrittenToStandardOut(), containsString("******************************************\n" +
"John's Appointment Book"));
assertThat(result.getExitCode(), equalTo(0));
}

@Test
void testWithStartDateAfterEndDate() {
MainMethodResult result = invokeMain("-pretty","-","-textFile","johnFile","John", "Meeting with Casandra", "07/13/2021", "12:00", "am","07/14/2021", "2:00","pm");
MainMethodResult result = invokeMain("-pretty","-","-textFile","johnFile","John", "Meeting with THree", "07/11/2021", "12:00", "am","07/10/2021", "2:00","pm");
assertThat(result.getTextWrittenToStandardError(), containsString("The start time cannot be after the end time"));
assertThat(result.getTextWrittenToStandardOut(), emptyString());
assertThat(result.getExitCode(), equalTo(1));
}

@Test
void verifyThatTheOrderingAlgorithmIsWorking() {
MainMethodResult result = invokeMain("-pretty","-","-textFile","johnFile","John", "Meeting with THree", "07/10/2021", "12:00", "am","07/11/2021", "2:00","pm");
assertThat(result.getTextWrittenToStandardError(), emptyString());
assertThat(result.getTextWrittenToStandardOut(), containsString("John's app"));
assertThat(result.getExitCode(), equalTo(0));
MainMethodResult result2 = invokeMain("-pretty","-","-textFile","johnFile","John", "Meeting with Elon", "07/10/2021", "12:00", "am","07/11/2021", "2:00","pm");
MainMethodResult result2 = invokeMain("-pretty","-","-textFile","johnFile","John", "Meeting with Four", "07/12/2021", "12:00", "am","07/13/2021", "2:00","pm");
assertThat(result2.getTextWrittenToStandardError(), emptyString());
assertThat(result2.getTextWrittenToStandardOut(), containsString("***Hi****"));
assertThat(result2.getTextWrittenToStandardOut(), containsString("******"));
assertThat(result2.getExitCode(), equalTo(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@ public void addAppointment(AbstractAppointment abstractAppointment) {
appointments.add((Appointment) abstractAppointment);
return;
}
if(appointments.get(0).compareTo((Appointment) abstractAppointment) < 0) {
appointments.add((Appointment) abstractAppointment);
if(appointments.get(0).compareTo((Appointment) abstractAppointment) > 0) {
appointments.add(0,(Appointment) abstractAppointment);
return;
}
if(size == 1) { //Add at beginning of LL with one listing
appointments.add(0,(Appointment) abstractAppointment);
if(size == 1) { //Add at end of LL with one listing
appointments.add((Appointment) abstractAppointment);
return;
}
for(int i = 0; i < appointments.size(); i++) {
if((i+1) >= size) {
if((i+1) == size) {
appointments.add((Appointment) abstractAppointment);
return;
}
if((appointments.get(i).compareTo((Appointment) abstractAppointment)==-1)&&(appointments.get(i).compareTo((Appointment) abstractAppointment)==1)) {
if((appointments.get(i).compareTo((Appointment) abstractAppointment)<=0)&&(appointments.get(i+1).compareTo((Appointment) abstractAppointment)>=0)) {
appointments.add((i+1),(Appointment) abstractAppointment);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ private Appointment parseAppointmentString(String appointment) {
}
start = validateTime(startString);
end = validateTime(endString);
if(start.compareTo(end) != -1) {
if(start == null || end == null) {
return null;
}
if(start == null || end == null) {
if(start.compareTo(end) != -1) {
return null;
}
Appointment app = new Appointment(start,end,description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,38 @@ void verifyCorrectConstructorWithParametersIsCalled(@TempDir File tempDir) throw
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));
PrettyPrinter printer = new PrettyPrinter(file.getPath(),true);
assertThat(printer.fileVerification(), equalTo(true));
}

@Test
void verifyThatTheWriterDoesntWriteToABadFileName() {
TextDumper dumper = new TextDumper();
PrettyPrinter printer = new PrettyPrinter();
AppointmentBook book = new AppointmentBook();
assertThat(dumper.writeToFile(book), equalTo(false));
assertThat(printer.prettyPrintToFile(book), equalTo(false));
}

@Test
void verifyTheReturnValueFromACorrectFileWriterRun(@TempDir File tempDir) {
String fileName = "name";
File file = new File(tempDir, fileName);

TextDumper dumper = new TextDumper(file.getPath());
PrettyPrinter printer = new PrettyPrinter(file.getPath(),true);
AppointmentBook book = createAppointmentBook();
assertThat(dumper.writeToFile(book), equalTo(true));
assertThat(printer.prettyPrintToFile(book), equalTo(true));
}

@Test
void verifyThatIfPrinterIsPassedABadFileNameExceptionIsThrown() {
PrettyPrinter printer = new PrettyPrinter();
AppointmentBook book = new AppointmentBook();
assertThrows(IOException.class, () -> {printer.dump(book);});
assertDoesNotThrow(() -> {printer.dump(book);});
}

@Test
void verifyThatIfDumpIsPassedABadFileNameExceptionIsThrown() {
PrettyPrinter printer = new PrettyPrinter();
AppointmentBook book = new AppointmentBook();
//assertDoesN(IOException.class, () -> {printer.dumpToStandardOut(book);});
assertDoesNotThrow(() -> {printer.dump(book);});
}

Expand All @@ -85,9 +83,9 @@ void verifyThatNoExceptionsAreThrownWhenCorrectInformationIsPassed(@TempDir File
File file = new File(tempDir, fileName);
assertThat(file.createNewFile(), equalTo(true));

TextDumper dumper = new TextDumper(file.getPath());
PrettyPrinter printer = new PrettyPrinter(file.getPath(),true);
AppointmentBook book = createAppointmentBook();
assertDoesNotThrow(() -> {dumper.dump(book);});
assertDoesNotThrow(() -> {printer.dump(book);});
}


Expand Down
20 changes: 10 additions & 10 deletions apptbook/src/test/java/edu/pdx/cs410J/bdesmond/TextParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ void verifyThatNoExceptionIsThrownWhenEmptyFileIsPassed(@TempDir File tempDir) {
}

@Test
void verifyThatTrueIsPassedWhenACorrectTimeIsPassedWithLeadingNumbers() {
void verifyThatNullIsPassedWhenAnIncorrectTimeIsPassedThatIsIn24HourTime() {
TextParser parser = new TextParser();
assertThat(parser.validateTime("07/11/2021 14:39"), equalTo(true));
assertThat(parser.validateTime("07/11/2021 14:39"), equalTo(null));
}

@Test
void verifyThatTrueIsPassedWhenACorrectTimeIsPassedWithNoLeadingNumbers() {
void verifyThatNullIsPassedWhenAnIncorrectTimeIsPassedWithoutTheTimePeriod() {
TextParser parser = new TextParser();
assertThat(parser.validateTime("7/11/2021 4:39"), equalTo(true));
assertThat(parser.validateTime("7/11/2021 4:39"), equalTo(null));
}

@Test
void verifyThatTrueIsPassedWhenACorrectTimeIsPassedWithNoLeadingNumbersOnFirst() {
TextParser parser = new TextParser();
assertThat(parser.validateTime("7/11/2021 14:39"), equalTo(true));
assertThat(parser.validateTime("7/11/2021 12:39 pm"), notNullValue());
}

@Test
void verifyThatTrueIsPassedWhenACorrectTimeIsPassedWithNoLeadingNumbersOnSecond() {
void verifyThatNullIsPassedWhenAnIncorrectTimeIsPassedWithoutTheTimePeriodPartButWithTwoDigitMonth() {
TextParser parser = new TextParser();
assertThat(parser.validateTime("12/11/2021 4:39"), equalTo(true));
assertThat(parser.validateTime("12/11/2021 4:39"), equalTo(null));
}

@Test
Expand All @@ -61,15 +61,15 @@ void verifyThatFalseIsPassedWhenAnIncorrectTimeIsPassed() {
}

@Test
void verifyThatFalseIsPassedWhenAnIncorrectDateIsPassedDay() {
void verifyThatNullIsPassedWhenAnIncorrectDateIsPassedDay() {
TextParser parser = new TextParser();
assertThat(parser.validateTime("12/32/2021 12:39"), equalTo(false));
assertThat(parser.validateTime("12/32/2021 12:39 aM"), equalTo(null));
}

@Test
void verifyThatFalseIsPassedWhenAnIncorrectDateIsPassedMonth() {
TextParser parser = new TextParser();
assertThat(parser.validateTime("13/31/2021 12:39"), equalTo(false));
assertThat(parser.validateTime("13/31/2021 12:39 am"), equalTo(null));
}

//Write IT Tests once the dumper is implemented
Expand Down
12 changes: 6 additions & 6 deletions apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/john
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
John
Meeting with Jake,08/15/2021 23:00,09/15/2021 22:00
Meeting with Aruna,08/15/2021 23:00,09/15/2021 22:00
Meeting with Aruna,08/15/2021 23:00,09/15/2021 22:00
Meeting with Aruna,08/15/2021 23:00,09/15/2021 22:00
Meeting with Aruna,08/15/2021 23:00,09/15/2021 22:00
Meeting with Aruna,08/15/2021 23:00,09/15/2021 22:00
Meeting with Jake,08/15/2021 9:00 PM,09/15/2021 10:00 PM
Meeting with Aruna,08/15/2021 9:00 PM,09/15/2021 10:00 PM
Meeting with Aruna,08/15/2021 9:00 PM,09/15/2021 10:00 PM
Meeting with Aruna,08/15/2021 9:00 PM,09/15/2021 10:00 PM
Meeting with Aruna,08/15/2021 9:00 PM,09/15/2021 10:00 PM
Meeting with Aruna,08/15/2021 9:00 PM,09/15/2021 10:00 PM
4 changes: 4 additions & 0 deletions apptbook/src/test/resources/edu/pdx/cs410J/bdesmond/johnFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
John
Meeting with Asha,7/3/21 12:00 AM,7/4/21 2:00 PM
Meeting with Casandra,7/13/21 12:00 AM,7/14/21 2:00 PM
Meeting with Elon,7/10/21 12:00 AM,7/11/21 2:00 PM
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
John
Meeting with Aruna,08/15/2021 23:00,09/15/2021 22:00
Meeting with Aruna,08/15/2021 23:00,09/15/2021 22:00
Meeting with Aruna,08/15/2021 23:00,09/15/2021 22:00
Meeting with Aruna,08/13/2021 3:00 pm,09/15/2021 2:00 am
Meeting with Aruna,08/12/2021 2:00 Pm,09/15/2021 2:00 am
Meeting with Aruna,08/13/2021 3:00 pM,09/15/2021 2:00 am
8 changes: 7 additions & 1 deletion koans/src/advanced/AboutMocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ public void simpleAnonymousMock() {
// HINT: pass a safe Collaborator implementation to constructor
// new ClassUnderTest(new Collaborator(){... it should not be the
// objective of this test to test that collaborator, so replace it
new ClassUnderTest().doSomething();
Collaborator c = new Collaborator() {
@Override
public void doBusinessStuff() {

}
};
new ClassUnderTest(c).doSomething();
}

}
16 changes: 13 additions & 3 deletions koans/src/intermediate/AboutEquality.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ public boolean equals(Object other) {
return true;
}

public boolean equals(String str) {
// Change this implementation to match the equals contract
// Car objects with same horsepower and name values should be considered equal
// http://download.oracle.com/javase/6/docs/api/java/lang/Object.html#equals(java.lang.Object)
if(!this.name.equals(str)) {
return false;
}
return true;
}

@Override
public int hashCode() {
// @see http://download.oracle.com/javase/6/docs/api/java/lang/Object.html#hashCode()
return super.hashCode();
return (int) 3 * horsepower;
}
}

Expand Down Expand Up @@ -126,8 +136,8 @@ public void ownHashCodeImplementationPartTwo() {
Chicken chicken1 = new Chicken();
chicken1.color = "black";
Chicken chicken2 = new Chicken();
assertEquals(chicken1.equals(chicken2), __);
assertEquals(chicken1.hashCode() == chicken2.hashCode(), __);
assertEquals(chicken1.equals(chicken2), false);
assertEquals(chicken1.hashCode() == chicken2.hashCode(), true);
// Does this still fit the hashCode contract? Why (not)?
// Fix the Chicken class to correct this.
}
Expand Down
27 changes: 18 additions & 9 deletions koans/src/intermediate/AboutFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public class AboutFileIO {
@Koan
public void fileObjectDoesntCreateFile() {
File f = new File("i-never.exist");
assertEquals(f.exists(), __);
assertEquals(f.exists(), false);
}

@Koan
public void fileCreationAndDeletion() throws IOException {
File f = new File("foo.txt");
f.createNewFile();
assertEquals(f.exists(), __);
assertEquals(f.exists(), true);
f.delete();
assertEquals(f.exists(), __);
assertEquals(f.exists(), false);
}

@Koan
Expand All @@ -40,10 +40,10 @@ public void basicFileWritingAndReading() throws IOException {
size = fr.read(in);
// No flush necessary!
fr.close();
assertEquals(size, __);
assertEquals(size, 22);
String expected = new String(in);
assertEquals(expected.length(), __);
assertEquals(expected, __);
assertEquals(expected.length(), 22);
assertEquals(expected, "First line\nSecond line");
file.delete();
}

Expand All @@ -61,9 +61,9 @@ public void betterFileWritingAndReading() throws IOException {
BufferedReader br = null;
try {
br = new BufferedReader(fr);
assertEquals(br.readLine(), __); // first line
assertEquals(br.readLine(), __); // second line
assertEquals(br.readLine(), __); // what now?
assertEquals(br.readLine(), "First line"); // first line
assertEquals(br.readLine(), "Second line"); // second line
assertEquals(br.readLine(), null); // what now?
} finally {
// anytime you open access to a file, you should close it or you may
// lock it from other processes (ie frustrate people)
Expand Down Expand Up @@ -92,6 +92,15 @@ public void directChainingForReadingAndWriting() throws IOException {
StringBuffer sb = new StringBuffer();
// Add the loop to go through the file line by line and add the line
// to the StringBuffer
final BufferedReader br = new BufferedReader(new FileReader("file.txt"));
String nextLine = br.readLine();
while(nextLine != null) {
sb.append(nextLine);
nextLine = br.readLine();
if(nextLine != null) {
sb.append("\n");
}
}
assertEquals(sb.toString(), "1. line\n2. line");
}
}
Expand Down
Loading