Skip to content

Commit

Permalink
Merge pull request #153 from AY2324S2-CS2103T-W12-3/91-revert-tests
Browse files Browse the repository at this point in the history
Improve code coverage
  • Loading branch information
bryanyee33 authored Mar 28, 2024
2 parents bde432f + d8de4f1 commit b73766c
Show file tree
Hide file tree
Showing 57 changed files with 255 additions and 93 deletions.
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/AppParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Represents the parsed command-line parameters given to the application.
*/
public class AppParameters {

private static final Logger logger = LogsCenter.getLogger(AppParameters.class);

private Path configPath;
Expand Down Expand Up @@ -61,7 +62,7 @@ public boolean equals(Object other) {

@Override
public int hashCode() {
return configPath.hashCode();
return Objects.hash(configPath); // supports null values
}

@Override
Expand All @@ -70,4 +71,5 @@ public String toString() {
.add("configPath", configPath)
.toString();
}

}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* to be the entry point of the application, we avoid this issue.
*/
public class Main {

private static Logger logger = LogsCenter.getLogger(Main.class);

public static void main(String[] args) {
Expand All @@ -38,4 +39,5 @@ public static void main(String[] args) {
logger.warning("The warning about Unsupported JavaFX configuration below can be ignored.");
Application.launch(MainApp.class, args);
}

}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ public String toString() {
.add("windowCoordinates", windowCoordinates)
.toString();
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/LogsCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* file reaches 5MB big, up to a maximum of 5 files.<br>
*/
public class LogsCenter {

private static final int MAX_FILE_COUNT = 5;
private static final int MAX_FILE_SIZE_IN_BYTES = (int) (Math.pow(2, 20) * 5); // 5MB
private static final String LOG_FILE = "addressbook.log";
Expand Down Expand Up @@ -102,5 +103,4 @@ private static void setBaseLogger() {
}
}


}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/core/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@ public int hashCode() {
}
return Integer.parseInt(hash);
}

}
11 changes: 10 additions & 1 deletion src/main/java/seedu/address/commons/core/index/Index.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.commons.core.index;

import java.util.Objects;

import seedu.address.commons.util.ToStringBuilder;

/**
Expand All @@ -11,7 +13,8 @@
* convert it back to an int if the index will not be passed to a different component again.
*/
public class Index {
private int zeroBasedIndex;

private final int zeroBasedIndex;

/**
* Index can only be created by calling {@link Index#fromZeroBased(int)} or
Expand Down Expand Up @@ -62,8 +65,14 @@ public boolean equals(Object other) {
return zeroBasedIndex == otherIndex.zeroBasedIndex;
}

@Override
public int hashCode() {
return Objects.hash(zeroBasedIndex);
}

@Override
public String toString() {
return new ToStringBuilder(this).add("zeroBasedIndex", zeroBasedIndex).toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* Represents an error during loading of data from a file.
*/
public class DataLoadingException extends Exception {
public DataLoadingException(Exception cause) {
super(cause);
}

public DataLoadingException(String message) {
super(message);
}

public DataLoadingException(Exception cause) {
super(cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
* Signals that some given data does not fulfill some constraints.
*/
public class IllegalValueException extends Exception {

/**
* @param message should contain relevant information on the failed constraint(s)
*/
public IllegalValueException(String message) {
super(message);
}

/**
* @param message should contain relevant information on the failed constraint(s)
* @param cause of the main exception
*/
public IllegalValueException(String message, Throwable cause) {
super(message, cause);
}
}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/util/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public static void checkArgument(Boolean condition, String errorMessage) {
throw new IllegalArgumentException(errorMessage);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public static void requireAllNonNull(Collection<?> items) {
public static boolean isAnyNonNull(Object... items) {
return items != null && Arrays.stream(items).anyMatch(Objects::nonNull);
}

}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ public static boolean isNonZeroUnsignedInteger(String s) {
return false;
}
}

}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/commons/util/ToStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Builds a string representation of an object that is suitable as the return value of {@link Object#toString()}.
*/
public class ToStringBuilder {

private static final String OBJECT_PREFIX = "{";
private static final String OBJECT_SUFFIX = "}";
private static final String FIELD_SEPARATOR = ", ";
Expand Down Expand Up @@ -50,4 +51,5 @@ public ToStringBuilder add(String fieldName, Object fieldValue) {
public String toString() {
return stringBuilder.toString() + OBJECT_SUFFIX;
}

}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* The main LogicManager of the app.
*/
public class LogicManager implements Logic {

private final Logger logger = LogsCenter.getLogger(LogicManager.class);

private final Model model;
Expand Down Expand Up @@ -62,4 +63,5 @@ public GuiSettings getGuiSettings() {
public void setGuiSettings(GuiSettings guiSettings) {
model.setGuiSettings(guiSettings);
}

}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ public String toString() {
.add("toAdd", toAdd)
.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class ClearCommand extends Command {
public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";


@Override
public String execute(Model model) {
requireNonNull(model);
model.setAddressBook(new AddressBook());
return MESSAGE_SUCCESS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ public String toString() {
.add("targetIndex", targetIndex)
.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,5 @@ public String toString() {
.toString();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class HelpCommand extends Command {
public String execute(Model model) {
return Messages.MESSAGE_SHOWING_HELP;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public String execute(Model model) {
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return MESSAGE_SUCCESS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public String execute(Model model) throws CommandException {
model.undo();
return MESSAGE_SUCCESS;
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package seedu.address.logic.commands.exceptions;

import seedu.address.logic.commands.Command;

/**
* Represents an error which occurs during execution of a {@link Command}.
*/
public class CommandException extends Exception {

public CommandException(String message) {
super(message);
}

/**
* Constructs a new {@code CommandException} with the specified detail {@code message} and {@code cause}.
*/
public CommandException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ public ParseException(String message) {
super(message);
}

public ParseException(String message, Throwable cause) {
super(message, cause);
}
}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Duplicates are not allowed (by .isSamePerson comparison).
*/
public class AddressBook implements ReadOnlyAddressBook {

@JsonIgnore
public static final String MESSAGE_UNDO_STACK_EMPTY = "There are no previous AddressBook states to return to.";
@JsonIgnore
Expand Down Expand Up @@ -211,4 +212,5 @@ public boolean equals(Object other) {
public int hashCode() {
return persons.hashCode();
}

}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* The API of the Model component.
*/
public interface Model {

/** {@code Predicate} that always evaluate to true */
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;

Expand Down Expand Up @@ -116,4 +117,5 @@ public interface Model {
* Changes the target asset into the editedAsset.
*/
void editAsset(Asset target, Asset editedAsset);

}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Represents the in-memory model of the address book data.
*/
public class ModelManager implements Model {

private static final Logger logger = LogsCenter.getLogger(ModelManager.class);

private final AddressBook addressBook;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class AddressBookException extends RuntimeException {
public AddressBookException(String message) {
super(message);
}

}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ public String toString() {
.add("assets", assets)
.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Iterator;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonValue;
Expand All @@ -26,7 +25,7 @@
* @see Person#isSamePerson(Person)
*/
@JsonDeserialize(using = UniquePersonListDeserializer.class)
public class UniquePersonList implements Iterable<Person> {
public class UniquePersonList {

private final ObservableList<Person> internalList = FXCollections.observableArrayList();

Expand Down Expand Up @@ -107,11 +106,6 @@ public ObservableList<Person> asUnmodifiableObservableList() {
return FXCollections.unmodifiableObservableList(internalList);
}

@Override
public Iterator<Person> iterator() {
return internalList.iterator();
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down Expand Up @@ -150,4 +144,5 @@ private boolean personsAreUnique(List<Person> persons) {
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* identity).
*/
public class DuplicatePersonException extends RuntimeException {

public DuplicatePersonException() {
super("Operation would result in duplicate persons");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
/**
* Signals that the operation is unable to find the specified person.
*/
public class PersonNotFoundException extends RuntimeException {}
public class PersonNotFoundException extends RuntimeException {

public PersonNotFoundException() {
super("Operation is unable to find the specified person");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ public boolean equals(Object other) {
public int hashCode() {
return assets.hashCode();
}

}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/person/fields/Prefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* E.g. 't/' in 'add James t/ friend'.
*/
public class Prefix {

private final String prefix;

public Prefix(String prefix) {
Expand Down Expand Up @@ -39,4 +40,5 @@ public boolean equals(Object other) {
Prefix otherPrefix = (Prefix) other;
return prefix.equals(otherPrefix.prefix);
}

}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Contains utility methods for populating {@code AddressBook} with sample data.
*/
public class SampleDataUtil {

public static Person[] getSamplePersons() {
return new Person[] {
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"),
Expand Down Expand Up @@ -55,4 +56,5 @@ public static Tags getTagSet(String... strings) {
public static Assets getAssetSet(String... strings) {
return new Assets(strings);
}

}
Loading

0 comments on commit b73766c

Please sign in to comment.