Skip to content

Commit

Permalink
Unit 2 Java: Graded Assignment LaunchCodeEducation#2: Tech Jobs OO - …
Browse files Browse the repository at this point in the history
…Task 5
  • Loading branch information
sungheechon committed Jan 19, 2024
1 parent 3b0c2e3 commit 39a1f49
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 21 deletions.
51 changes: 30 additions & 21 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/main/java/org/launchcode/techjobs/oo/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ public void setCoreCompetency(CoreCompetency coreCompetency) {
// TODO: Add custom equals and hashCode methods. Consider two Job objects "equal" when their id fields
// match.

@Override
public String toString() {
String newline = System.lineSeparator();
String msgEmptyField = "Data not available";
String emptyField = "";
String emptyData = "OOPS! This job does not seem to exist.";

return newline +

"ID: " + id + newline +
"Name: " + (name != emptyField ? name : msgEmptyField) + newline +
"Employer: " + (employer.getValue() != emptyField ? employer : msgEmptyField) + newline +
"Location: " + (location.getValue() != emptyField ? location : msgEmptyField) + newline +
"Position Type: " + (positionType.getValue() != emptyField ? positionType : msgEmptyField) + newline +
"Core Competency: " + (coreCompetency.getValue() != emptyField ? coreCompetency : msgEmptyField)

+ newline;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
63 changes: 63 additions & 0 deletions src/test/java/org/launchcode/techjobs/oo/JobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void testSettingJobId() {

assertNotEquals(msg, job1.getId(), job2.getId());
}

@Test
public void testJobConstructorSetsAllFields() {
// String msg = "Each Job object should contain six fields—id, name, employer, location, positionType, and coreCompetency";
Expand Down Expand Up @@ -67,7 +68,69 @@ public void testJobsForEquality() {
Job job5 = new Job("Product tester", new Employer("ACME"), new Location("Desert"), new PositionType("Quality control"), new CoreCompetency("Persistence"));
boolean isIdEqual = job4.equals(job5);
assertFalse("Two Job objects IDs are not equal", isIdEqual);
}

@Test
public void testToStringStartsAndEndsWithNewLine() {
String newline = System.lineSeparator();

Job job5 = new Job("Product tester", new Employer("ACME"), new Location("Desert"), new PositionType("Quality control"), new CoreCompetency("Persistence"));

String msgBlankLine = "Job object contains a blank line before and after the job information";

String firstChar = String.valueOf(job5.toString().charAt(0));
String lastChar = String.valueOf(job5.toString().charAt(job5.toString().length() - 1));

assertEquals(msgBlankLine, firstChar, newline);
assertEquals(msgBlankLine, lastChar, newline);

}

@Test
public void testToStringContainsCorrectLabelsAndData() {
String newline = System.lineSeparator();

Job job6 = new Job("Product tester", new Employer("ACME"), new Location("Desert"), new PositionType("Quality control"), new CoreCompetency("Persistence"));
String msgString = "The string should contain a label for each field, followed by the data stored in that field. Each field should be on its own line.";
String expectedString = newline +
"ID: " + job6.getId() + newline +
"Name: Product tester" + newline +
"Employer: ACME" + newline +
"Location: Desert" + newline +
"Position Type: Quality control" + newline +
"Core Competency: Persistence" + newline;
String actualString = job6.toString();
assertEquals(msgString, expectedString, actualString);

}

@Test
public void testToStringHandlesEmptyField() {
String newline = System.lineSeparator();

Job job7 = new Job("Product tester", new Employer("ACME"), new Location(""), new PositionType("Quality control"), new CoreCompetency("Persistence"));
String msgNoData = "If a job object's field is empty, display 'Data not available'";
String expectedNoData = newline +
"ID: " + job7.getId() + newline +
"Name: Product tester" + newline +
"Employer: ACME" + newline +
"Location: Data not available" + newline +
"Position Type: Quality control" + newline +
"Core Competency: Persistence" + newline;
String actualNoData = job7.toString();
assertEquals(msgNoData, expectedNoData, actualNoData);
}

// @Test
// public void testToStringHandlesNoData() {
//
// Job job8 = new Job();
// String msgIdOnly = "If a Job object ONLY contains data for the id field, the method should return, 'OOPS! This job does not seem to exist.'";
// String expectedIdOnly = "OOPS! This job does not seem to exist.";
//
// String actualIdOnly = job8.toString();
// assertEquals(msgIdOnly, expectedIdOnly, actualIdOnly);
// }


}

0 comments on commit 39a1f49

Please sign in to comment.