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
17 changes: 11 additions & 6 deletions apptbook/src/it/java/edu/pdx/cs410J/bdesmond/Project1IT.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,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));
}

Expand Down
31 changes: 16 additions & 15 deletions apptbook/src/main/java/edu/pdx/cs410J/bdesmond/Project1.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public static void main(String[] args) {
printErrorAndExit(USAGE_MESSAGE);
}
for (String arg : args) {
if(arg == "-README") {
if(arg.equals("-README")) {
readMe();
numOfOptions++;
} else if(arg == "-print") {
} else if(arg.equals("-print")) {
printFlag = true;
numOfOptions++;
} else if(name == null) {
Expand Down Expand Up @@ -117,15 +117,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);
Expand All @@ -140,14 +145,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();
}

/**
Expand Down

This file was deleted.

This file was deleted.