Skip to content

Commit

Permalink
Merge pull request #136 from duongphammmm/v1.3-tests
Browse files Browse the repository at this point in the history
Add tests for item field
  • Loading branch information
chrisjwelly authored Mar 26, 2020
2 parents 90fe78c + bacfcaf commit 8c93795
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 176 deletions.
17 changes: 14 additions & 3 deletions src/main/java/seedu/address/model/item/Internship.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
public class Internship extends Item {

// Data fields
// TODO: convert from and to back to Time
private String role;
private Time from;
private Time to;
Expand All @@ -34,7 +33,6 @@ public Internship(Name name, String role, Time from, Time to, String description
this.from = from;
this.to = to;
this.description = description;

}

public String getRole() {
Expand Down Expand Up @@ -62,6 +60,18 @@ public String getSummary() {
return builder.toString();
}

/**
* Returns true if both internships have the same name, role, from and to.
* This defines a weaker notion of equality between two items.
*/
@Override
public boolean isSame(Item otherInternship) {
return super.isSame(otherInternship)
&& ((Internship) otherInternship).getRole().equals(getRole())
&& ((Internship) otherInternship).getFrom().equals(getFrom())
&& ((Internship) otherInternship).getTo().equals(getTo());
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
Expand All @@ -79,6 +89,7 @@ && getName().equals(((Internship) other).getName())
&& role.equals(((Internship) other).role) // state check
&& from.equals(((Internship) other).from)
&& to.equals(((Internship) other).to)
&& description.equals(((Internship) other).description));
&& description.equals(((Internship) other).description))
&& getTags().equals(((Internship) other).getTags());
}
}
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/model/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public abstract class Item {
// Identity fields
protected Type type;
protected final int id;
private final Name name;
protected final Name name;

// Data fields
private final Set<Tag> tags = new HashSet<>();
protected final Set<Tag> tags = new HashSet<>();

public Item(Name name, int id, Set<Tag> tags) {
requireAllNonNull(name, tags);
Expand Down Expand Up @@ -67,7 +67,7 @@ public Set<Tag> getTags() {
}

/**
* Returns true if both items have the same name.
* Returns true if both items have the same name and are of the same type.
* This defines a weaker notion of equality between two items.
*/
public boolean isSame(Item otherItem) {
Expand All @@ -76,7 +76,8 @@ public boolean isSame(Item otherItem) {
}

return otherItem != null
&& otherItem.getName().equals(getName());
&& otherItem.getName().equals(getName())
&& otherItem.getType().equals(getType());
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/item/Resume.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Resume(Name name, Set<Tag> tags) {
public Resume(Name name, int id, Set<Tag> tags) {
super(name, id, tags);
this.type = Type.generate("res");
// TODO: change Resume constructor to take in existing lists of internships, projects or skills
}

public void addInternship(int value) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/item/Skill.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public Level getLevel() {
return this.level;
}

public void setLevel(String level) {
this.level = Level.valueOf(level);
}

@Override
public String getSummary() {
final StringBuilder builder = new StringBuilder();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/item/field/Description.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
public class Description {

// TODO: Utilise this class in main codes

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

/*
Expand Down
39 changes: 0 additions & 39 deletions src/test/java/seedu/address/model/item/AddressTest.java

This file was deleted.

6 changes: 2 additions & 4 deletions src/test/java/seedu/address/model/item/EmailTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package seedu.address.model.item;

/*import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.jupiter.api.Test;

import seedu.address.model.item.field.Email;*/
import seedu.address.model.item.field.Email;

public class EmailTest {
/*
@Test
public void constructor_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new Email(null));
Expand Down Expand Up @@ -61,5 +60,4 @@ public void isValidEmail() {
assertTrue(Email.isValidEmail("[email protected]")); // long local part
}

*/
}
83 changes: 83 additions & 0 deletions src/test/java/seedu/address/model/item/InternshipTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package seedu.address.model.item;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.VALID_INTERNSHIP_DESCRIPTION;
import static seedu.address.logic.commands.CommandTestUtil.VALID_INTERNSHIP_NAME_GOOGLE;
import static seedu.address.logic.commands.CommandTestUtil.VALID_INTERNSHIP_ROLE_FRONTEND;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_JAVA;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalInternship.GOOGLE;
import static seedu.address.testutil.TypicalInternship.NINJA_VAN;
import static seedu.address.testutil.TypicalInternship.PAYPAL;

import org.junit.jupiter.api.Test;

import seedu.address.testutil.InternshipBuilder;

public class InternshipTest {

@Test
public void asObservableList_modifyList_throwsUnsupportedOperationException() {
Internship internship = new InternshipBuilder().build();
assertThrows(UnsupportedOperationException.class, () -> internship.getTags().remove(0));
}

@Test
public void isSameInternship() {
// same object -> returns true
assertTrue(PAYPAL.isSame(PAYPAL));

// null -> returns false
assertFalse(PAYPAL.isSame(null));

// different role and description -> returns false
Internship editedPaypal = new InternshipBuilder(PAYPAL).withRole(VALID_INTERNSHIP_ROLE_FRONTEND)
.withDescription(VALID_INTERNSHIP_DESCRIPTION).build();
assertFalse(PAYPAL.isSame(editedPaypal));

// different name -> returns false
editedPaypal = new InternshipBuilder(PAYPAL).withName(VALID_INTERNSHIP_NAME_GOOGLE).build();
assertFalse(PAYPAL.isSame(editedPaypal));
}

@Test
public void equals() {
// same values -> returns true
Internship ninjaCopy = new InternshipBuilder(NINJA_VAN).build();
assertTrue(NINJA_VAN.equals(ninjaCopy));

// same object -> returns true
assertTrue(NINJA_VAN.equals(NINJA_VAN));

// null -> returns false
assertFalse(NINJA_VAN.equals(null));

// different type -> returns false
assertFalse(NINJA_VAN.equals(5));

// different internship -> returns false
assertFalse(NINJA_VAN.equals(GOOGLE));

// different name -> returns false
Internship editedNinja = new InternshipBuilder(NINJA_VAN).withName(VALID_INTERNSHIP_NAME_GOOGLE).build();
assertFalse(NINJA_VAN.equals(editedNinja));

// different role -> returns false
editedNinja = new InternshipBuilder(NINJA_VAN).withRole(VALID_INTERNSHIP_ROLE_FRONTEND).build();
assertFalse(NINJA_VAN.equals(editedNinja));

// different from -> returns false
editedNinja = new InternshipBuilder(NINJA_VAN).withFrom("05-2019").build();
assertFalse(NINJA_VAN.equals(editedNinja));

// different to -> returns false
editedNinja = new InternshipBuilder(NINJA_VAN).withTo("02-2018").build();
assertFalse(NINJA_VAN.equals(editedNinja));

// different tags -> returns false
editedNinja = new InternshipBuilder(NINJA_VAN).withTags(VALID_TAG_JAVA).build();
assertFalse(NINJA_VAN.equals(editedNinja));
}

}
99 changes: 0 additions & 99 deletions src/test/java/seedu/address/model/item/ItemTest.java

This file was deleted.

Loading

0 comments on commit 8c93795

Please sign in to comment.