Skip to content

Commit

Permalink
Fix and test for usnistgov/jsip#25
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirralev authored and jaimecasero committed Aug 24, 2017
1 parent bcc319e commit 590b28b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/gov/nist/javax/sdp/fields/AttributeField.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,15 @@ public Object clone() {
public boolean equals(Object that ) {
if ( ! (that instanceof AttributeField)) return false;
AttributeField other = (AttributeField) that;
return other.getAttribute().getName().equalsIgnoreCase(this.getAttribute().getName()) &&
this.getAttribute().getValueAsObject().equals(other.getAttribute().getValueAsObject());
boolean equalNames = other.getAttribute().getName().equalsIgnoreCase(this.getAttribute().getName());
boolean equalValues;
if(this.getAttribute().getValueAsObject() != null) {
equalValues = this.getAttribute().getValueAsObject().equals(other.getAttribute().getValueAsObject());
} else {
equalValues = (other.getAttribute().getValueAsObject() == null);
}

return equalNames && equalValues;
}

@Override
Expand Down
11 changes: 10 additions & 1 deletion src/test/gov/nist/javax/sdp/parser/SdpParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ public void testWebRtcSdpParser() throws Exception {
public void testAttribEquals() throws Exception {
AttributeField f1 = new AttributeFieldParser("a=sendrecv").attributeField();
AttributeField f2 = new AttributeFieldParser("a=sendrecv").attributeField();
f1.equals(f2);
AttributeField f3 = new AttributeFieldParser("a=sendonly").attributeField();
AttributeField f4 = new AttributeFieldParser("a=f:sendonly").attributeField();
AttributeField f5 = new AttributeFieldParser("a=f:sendonly").attributeField();
AttributeField f6 = new AttributeFieldParser("a=ff:sendonly").attributeField();
f1.equals(f2); // NPE here Issue 25
assertEquals(f1, f2);
assertFalse(f2.equals(f3));
assertFalse(f4.equals(f3));
assertEquals(f5, f4);
assertFalse(f5.equals(f6));
}

public void testSdpParser() throws Exception {
Expand Down

0 comments on commit 590b28b

Please sign in to comment.