mirror of https://github.com/jwtk/jjwt.git
Merge pull request #117 from matzon/master
implement hashCode and equals in JwtMap
This commit is contained in:
commit
0f63ec8012
|
@ -155,4 +155,14 @@ public class JwtMap implements Map<String,Object> {
|
|||
public String toString() {
|
||||
return map.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return map.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return map.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,4 +124,28 @@ class JwtMapTest {
|
|||
def s = ['b', 'd']
|
||||
assertTrue m.values().containsAll(s) && s.containsAll(m.values())
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() throws Exception {
|
||||
def m1 = new JwtMap();
|
||||
m1.put("a", "a");
|
||||
|
||||
def m2 = new JwtMap();
|
||||
m2.put("a", "a");
|
||||
|
||||
assertEquals(m1, m2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() throws Exception {
|
||||
def m = new JwtMap();
|
||||
def hashCodeEmpty = m.hashCode();
|
||||
|
||||
m.put("a", "b");
|
||||
def hashCodeNonEmpty = m.hashCode();
|
||||
assertTrue(hashCodeEmpty != hashCodeNonEmpty);
|
||||
|
||||
def identityHash = System.identityHashCode(m);
|
||||
assertTrue(hashCodeNonEmpty != identityHash);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue