Skip to content

Commit

Permalink
Added some bullet-proofing against students who do not provide a firs…
Browse files Browse the repository at this point in the history
…t or last name.
  • Loading branch information
DavidWhitlock committed Jul 2, 2016
1 parent 2f3e2a7 commit e3e8615
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
11 changes: 11 additions & 0 deletions grader/src/main/java/edu/pdx/cs410J/grader/poa/POASubmission.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,20 @@ public static class Builder {
private String content;

public POASubmission create() {
assertNotNull("subject", subject);
assertNotNull("submitter", submitter);
assertNotNull("submitTime", submitTime);
assertNotNull("content", content);

return new POASubmission(subject, submitter, submitTime, content);
}

private void assertNotNull(String description, Object object) {
if (object == null) {
throw new IllegalStateException(description + " cannot be null");
}
}

public Builder setSubject(String subject) {
this.subject = subject;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public void populateViewWithStudents(GradeBookLoaded event) {

private Comparator<Student> sortStudentsByLastNameFirstNameEmail() {
return (student1, student2) -> {
String lastName1 = student1.getLastName();
String lastName2 = student2.getLastName();
String lastName1 = getLastNameOfStudent(student1);
String lastName2 = getLastNameOfStudent(student2);
if (!lastName1.equals(lastName2)) {
return lastName1.compareTo(lastName2);

} else {
String firstName1 = student1.getFirstName();
String firstName2 = student2.getFirstName();
String firstName1 = getFirstNameOfStudent(student1);
String firstName2 = getFirstNameOfStudent(student2);
if (!firstName1.equals(firstName2)) {
return firstName1.compareTo(firstName2);

Expand All @@ -80,8 +80,16 @@ private Comparator<Student> sortStudentsByLastNameFirstNameEmail() {
};
}

private String getLastNameOfStudent(Student student) {
String lastName = student.getLastName();
if (lastName == null) {
throw new IllegalStateException("Student " + student.getId() + " doesn't have a last name");
}
return lastName;
}

private String getStudentDisplayText(Student student) {
return student.getFirstName() + " " + student.getLastName() + " <" + student.getEmail() + ">";
return getFirstNameOfStudent(student) + " " + getLastNameOfStudent(student) + " <" + student.getEmail() + ">";
}

@Subscribe
Expand Down Expand Up @@ -109,7 +117,15 @@ private boolean submitterContainsStudentEmail(Student student, String submitter)
}

private boolean submitterContainsStudentName(Student student, String submitter) {
return submitter.contains(student.getFirstName()) && submitter.contains(student.getLastName());
return submitter.contains(getFirstNameOfStudent(student)) && submitter.contains(getLastNameOfStudent(student));
}

private String getFirstNameOfStudent(Student student) {
String firstName = student.getFirstName();
if (firstName == null) {
throw new IllegalStateException("Student " + student.getId() + " doesn't have a first name");
}
return firstName;
}

}

0 comments on commit e3e8615

Please sign in to comment.