@SuppressWarnings("unchecked") private static ActionReturnValue deserializeReturnValue(String payload, String className) { if (className == null) { return null; } Class<Serializable> retValueClass = (Class<Serializable>) ReflectionUtils.getClassFor(className); return (ActionReturnValue) SerializationFactory.getDeserializer().deserialize(payload, retValueClass); }
if (isCompatible(expectedParams, constructor.getParameterTypes())) { return constructor;
/** * Find the constructor with the given parameters and check that it was found and has the correct number and type of * parameters. * * @param parameters * The parameters to check with. */ private void findConstructorAndAssertItWasFound(Class<?> typeToTest, Class<?>[] parameters) { Constructor<?> constructor = ReflectionUtils.findConstructor(typeToTest, parameters); assertNotNull(constructor, createAssertMessage(typeToTest, "ctor not found")); assertEquals(parameters.length, constructor.getParameterTypes().length, createAssertMessage(typeToTest, "found ctor with wrong parameter length")); Class<?>[] ctorParameters = constructor.getParameterTypes(); for (int i = 0; i < parameters.length; i++) { assertTrue(ctorParameters[i].isAssignableFrom(parameters[i]), createAssertMessage(typeToTest, "parameter not compatible, expected {1} or a subclass, but was {2}", parameters[i].getSimpleName(), ctorParameters[i].getSimpleName())); } }
/** * Test that {@link ReflectionUtils#findConstructor(Class, Class...)} doesn't find a constructor when the supertype * is used for lookup. */ @ParameterizedTest @MethodSource public void negativeTestFindConstructorForSupertype(Class<?> typeToTest, Class<?>[] ctorParams) { assertNull(ReflectionUtils.findConstructor(typeToTest, ctorParams), createAssertMessage(typeToTest, "ctor was found anyway")); }
/** * Test that {@link ReflectionUtils#findConstructor(Class, Class...)} doesn't find a constructor when the number of * arguments doesn't match anything. */ @ParameterizedTest @MethodSource("positiveTestFindConstructorForExactParam") public void negativeTestFindConstructorForMismatchingArgumentsNumber(Class<?> typeToTest, Class<?>[] ctorParams) { assertNull(ReflectionUtils.findConstructor (typeToTest, (Class<?>[]) ArrayUtils.add(ctorParams, Object.class)), createAssertMessage(typeToTest, "ctor was found anyway")); }
@SuppressWarnings("unchecked") private static ActionParametersBase deserializeParameters(String payload, String className) { if (className == null) { return null; } Class<Serializable> actionParamsClass = (Class<Serializable>) ReflectionUtils.getClassFor(className); return (ActionParametersBase) SerializationFactory.getDeserializer().deserialize(payload, actionParamsClass); }