Right, XStream is probably not the best in the general case, but it worked in out case. Let me know if you need a more "formalized" JUnit like test case.
Code:
import java.util.*;
import java.lang.reflect.*;
import java.io.Serializable;
import org.springmodules.cache.key.*;
import org.aopalliance.intercept.MethodInvocation;
public class Test {
public static void main(String[] args) {
try {
new Test().test();
} catch (Exception e) {
e.printStackTrace();
}
}
public void test() throws Exception {
Long arg1 = (long) Math.pow(2.0, 32.0);
Long arg2 = 1L;
System.out.println("arg1.equals(arg2) -> " + arg1.equals(arg2));
Method methodToCache = Test.class.getDeclaredMethod("someMethodWeWantCached", Object.class);
CacheKeyGenerator g = new HashCodeCacheKeyGenerator(true);
Serializable key1 = g.generateKey(fakeMethodInvocation(methodToCache, arg1));
Serializable key2 = g.generateKey(fakeMethodInvocation(methodToCache, arg2));
System.out.println("key1.equals(key2) -> " + key1.equals(key2));
}
private MethodInvocation fakeMethodInvocation(final Method methodToCache, final Object arg) {
return new MethodInvocation() {
public Method getMethod() {
return methodToCache;
}
public Object[] getArguments() {
return new Object[] { arg };
}
public Object getThis() {
return Test.this;
}
public AccessibleObject getStaticPart() {
return null;
}
public Object proceed() throws Throwable {
return null;
}
};
}
public Object someMethodWeWantCached(Object o) {
return o;
}
}