use of org.simpleflatmapper.datastax.test.utils.RecorderInvocationHandler in project SimpleFlatMapper by arnaudroger.
the class DataTypeTest method testNumberSetter.
private <N> void testNumberSetter(Class<N> numberClass, Class<?> primitiveSetter) throws Exception {
Method[] methods = DataType.class.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getReturnType().equals(DataType.class) && Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length == 0) {
DataType dataType = (DataType) method.invoke(null);
if (DataTypeHelper.isNumber(dataType)) {
Class<?> dataTypeClass = DataTypeHelper.asJavaClass(dataType);
Setter<? super SettableByIndexData, N> setter = getSetter(numberClass, dataType);
assertNotNull("No setter for " + numberClass + ", " + dataType, setter);
if (numberClass.isPrimitive() && dataTypeClass.equals(numberClass) && primitiveSetter != null) {
primitiveSetter.isInstance(setter);
}
RecorderInvocationHandler recorder = new RecorderInvocationHandler();
SettableByIndexData settableByDataInstance = (SettableByIndexData) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { SettableByIndexData.class }, recorder);
N value = getValue(numberClass);
setter.set(settableByDataInstance, value);
recorder.invokedOnce(setterMethodFor(dataType), 1, getValue(dataTypeClass));
recorder.reset();
setter.set(settableByDataInstance, null);
recorder.invokedOnce("setToNull", 1);
}
}
}
}
use of org.simpleflatmapper.datastax.test.utils.RecorderInvocationHandler in project SimpleFlatMapper by arnaudroger.
the class DataTypeTest method testNumberGetter.
private <N> void testNumberGetter(Class<N> numberClass, Class<?> primitiveGetter) throws Exception {
Method[] methods = DataType.class.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getReturnType().equals(DataType.class) && Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length == 0) {
DataType dataType = (DataType) method.invoke(null);
if (DataTypeHelper.isNumber(dataType)) {
Class dataTypeClass = DataTypeHelper.asJavaClass(dataType);
Getter<? super GettableByIndexData, N> getter = getGetter(numberClass, dataType);
assertNotNull("No getter for " + numberClass + ", " + dataType, getter);
if (numberClass.isPrimitive() && dataTypeClass.equals(numberClass) && primitiveGetter != null) {
primitiveGetter.isInstance(getter);
}
RecorderInvocationHandler recorder = new RecorderInvocationHandler();
GettableByIndexData gettableByDataInstance = (GettableByIndexData) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { GettableByIndexData.class }, recorder);
getter.get(gettableByDataInstance);
recorder.invokedOnce(getterMethodFor(dataType), 1);
if (!(dataTypeClass.equals(numberClass) && (BigInteger.class.equals(numberClass)) || BigDecimal.class.equals(numberClass))) {
recorder.when("isNull", 1, true);
assertNull(" fail isNull check " + numberClass + " - " + dataTypeClass, getter.get(gettableByDataInstance));
recorder.reset();
}
}
}
}
}
use of org.simpleflatmapper.datastax.test.utils.RecorderInvocationHandler in project SimpleFlatMapper by arnaudroger.
the class Datastax3 method testLocalDateGetter.
@Test
public void testLocalDateGetter() throws Exception {
Getter<GettableByIndexData, ?> getter = DataTypeTest.getGetter(localDateClass, (DataType) DataType.class.getMethod("date").invoke(null));
RecorderInvocationHandler recorder = new RecorderInvocationHandler();
GettableByIndexData gettableByDataInstance = (GettableByIndexData) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { GettableByIndexData.class }, recorder);
getter.get(gettableByDataInstance);
recorder.invokedOnce("getDate", 1);
}
use of org.simpleflatmapper.datastax.test.utils.RecorderInvocationHandler in project SimpleFlatMapper by arnaudroger.
the class Datastax3 method testLocalDateSetter.
@SuppressWarnings("unchecked")
@Test
public void testLocalDateSetter() throws Exception {
Setter<SettableByIndexData, Object> setter = DataTypeTest.getSetter((Class<Object>) localDateClass, (DataType) DataType.class.getMethod("date").invoke(null));
RecorderInvocationHandler recorder = new RecorderInvocationHandler();
SettableByIndexData settableByDataInstance = (SettableByIndexData) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { SettableByIndexData.class }, recorder);
Object localDateInstance = localDateClass.getDeclaredMethod("fromMillisSinceEpoch", long.class).invoke(null, System.currentTimeMillis());
setter.set(settableByDataInstance, localDateInstance);
recorder.invokedOnce("setDate", 1, localDateInstance);
recorder.reset();
setter.set(settableByDataInstance, null);
recorder.invokedOnce("setToNull", 1);
}
Aggregations