Skip to content

Commit

Permalink
Merge pull request #161 from AY2122S1-CS2103T-W15-3/fix-description-bug
Browse files Browse the repository at this point in the history
Fix empty description bug
  • Loading branch information
pcgiang authored Oct 28, 2021
2 parents 6c9a7b3 + 0b66134 commit 698e676
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ public static EndDateTime parseEndDateTime(String endDateTime) throws ParseExcep
* Leading and trailing whitespaces will be trimmed.
*
*/
public static Description parseDescription(String description) {
public static Description parseDescription(String description) throws ParseException {
requireNonNull(description);
String trimmedDescription = description.trim();

if (!Description.isValidDescription(trimmedDescription)) {
throw new ParseException(Description.MESSAGE_CONSTRAINTS);
}
return new Description(trimmedDescription);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/common/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Address(String address) {
}

/**
* Returns true if a given string is a valid email.
* Returns true if a given string is a valid address.
*/
public static boolean isValidAddress(String test) {
return test.matches(VALIDATION_REGEX);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/seedu/address/model/event/Description.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.model.event;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import java.util.List;

Expand All @@ -12,6 +13,14 @@
*/
public class Description {

public static final String MESSAGE_CONSTRAINTS = "Description can take any values, and it should not be blank";

/*
* The first character of the description must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[^\\s].*";

public final String value;

/**
Expand All @@ -21,9 +30,17 @@ public class Description {
*/
public Description(String remark) {
requireNonNull(remark);
checkArgument(isValidDescription(remark), MESSAGE_CONSTRAINTS);
value = remark;
}

/**
* Returns true if a given string is a valid description.
*/
public static boolean isValidDescription(String test) {
return test.matches(VALIDATION_REGEX);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/testutil/EventBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class EventBuilder {
public static final String DEFAULT_NAME = "Midterms";
public static final String DEFAULT_START_DATE_AND_TIME = "13-10-2021 21:00";
public static final String DEFAULT_END_DATE_AND_TIME = "13-10-2021 23:00";
public static final String DEFAULT_DESCRIPTION = "";
public static final String DEFAULT_DESCRIPTION = "Important";
public static final String DEFAULT_ADDRESS = "COM2, SR1, #02-11";
public static final String DEFAULT_ZOOM_LINK = "https://nus-sg.zoom.us/j/0123456789?pwd=ABCDEFG";

Expand Down

0 comments on commit 698e676

Please sign in to comment.