implement hashCode and equals in JwtMap

This commit is contained in:
Brian Matzon 2016-04-27 12:15:36 +02:00
parent 29f980c5c9
commit 39ee58a511
2 changed files with 51 additions and 0 deletions

View File

@ -155,4 +155,16 @@ public class JwtMap implements Map<String,Object> {
public String toString() { public String toString() {
return map.toString(); return map.toString();
} }
@Override
public int hashCode()
{
return map.hashCode();
}
@Override
public boolean equals(Object obj)
{
return map.equals(obj);
}
} }

View File

@ -0,0 +1,39 @@
package io.jsonwebtoken.impl;
import org.junit.Test;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
/**
* Java specific test to ensure we don't hit Groovy's DefaultGroovyMethods
*/
public class JavaJwtMapTest
{
@Test
public void testEquals() throws Exception
{
JwtMap jwtMap1 = new JwtMap();
jwtMap1.put("a", "a");
JwtMap jwtMap2 = new JwtMap();
jwtMap2.put("a", "a");
assertEquals(jwtMap1, jwtMap2);
}
@Test
public void testHashCode() throws Exception
{
JwtMap jwtMap = new JwtMap();
int hashCodeEmpty = jwtMap.hashCode();
jwtMap.put("a", "b");
int hashCodeNonEmpty = jwtMap.hashCode();
assertTrue(hashCodeEmpty != hashCodeNonEmpty);
int identityHash = System.identityHashCode(jwtMap);
assertTrue(hashCodeNonEmpty != identityHash);
}
}