Comments (1)
Getting pl.pojo.tester.internal.assertion.equals.NotEqualEqualsAssertionError
is caused by ObjectGenerator
's method generateDifferentObjects
It creates new object of field type class and sets to baseObjectCopy
without checking if values are equal so solution for this problem is to put tihs code int 72 line:
Object newFieldTypeInstance = createNewInstance(permutationFieldType);
try {
if (newFieldTypeInstance.equals(FieldUtils.getValue(baseObject, permutationField))) {
newFieldTypeInstance = abstractFieldValueChanger.increaseValue(newFieldTypeInstance);
}
} catch (final IllegalAccessException e) {
// TODO
throw new RuntimeException("Make FieldUtils.getValue(...,...) throw runtime exception");
}
but this makes another problem.
When creating proxy object (using java proxy or javaasist proxy) we need to pass InvocationHandler
or MethodInvocationHandler
.
This is implemented to return 0
:
return Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, (proxy, method, args) -> 0);
So when equals
method is invoked, we get CastClassException
. Naturally, we cant cast 0
to boolean
so at first glance we can replace return statement with
return Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, (proxy, method, args) -> method.invoke(proxy,args));
but this makes sweet Java
throw java.lang.reflect.UndeclaredThrowableException
.
.
.
Can you imagine life without exceptions?
Just imagine...
And finally great sollution for this is:
private Object proxyByJava() {
return Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, this::createInvocationHandler);
}
private Object createInvocationHandler(final Object proxy, final Method method, final Object[] args) {
try {
return method.invoke(proxy, args);
} catch (IllegalAccessException | InvocationTargetException e) {
final Class<?> returnType = method.getReturnType();
if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
return true;
} else {
return 0;
}
}
}
😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆 😆
from pojo-tester.
Related Issues (20)
- Timestamp break Equals HOT 3
- Unexpectedly getting NotEqualHashCodeAssertionError HOT 3
- Exclusion not working HOT 1
- support lowercase FirstName setter and getter function
- AbstractFieldValueChanger not working; POJOS with Set<> fail. HOT 2
- Intellj IDEA generated toString() methods are not well implemented HOT 1
- Support Builder-style setters HOT 1
- Getter and Setter not found HOT 1
- Recurrence stackoverflow exception
- Project Abandoned? HOT 5
- Object[] property causing: has bad 'toString' method implementation in Intellij
- Illegal reflective access warnings on JDK 11
- JDK 13. Bug when testing any pojo HOT 8
- How to test class with 'simple' inner class HOT 3
- Unexpected NotEqualEqualsAssertionError
- DefaultPackageFilter should only consider .class files
- Contribution required HOT 3
- Bug in equals tester
- Non-compliant with Java spec: "The hashCode method should return different hash codes for non equal objects." HOT 1
- Getting issue "pl.pojo.tester.internal.GetOrSetValueException: Unable to get or set value for field 'modifiers' in class 'class java.lang.reflect.Field'. Cause message: modifiers"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pojo-tester.