### Question:
UtilReflection { @SuppressWarnings("unchecked") public static <T> T createReduce(Class<T> type, Object... params) throws NoSuchMethodException { Check.notNull(type); Check.notNull(params); final Class<?>[] paramTypes = getParamTypes(params); final Queue<Class<?>> typesQueue = new ArrayDeque<>(Arrays.asList(paramTypes)); final Queue<Object> paramsQueue = new ArrayDeque<>(Arrays.asList(params)); boolean stop = false; while (!stop) { final int typesLength = typesQueue.size(); final Class<?>[] typesArray = typesQueue.toArray(new Class<?>[typesLength]); for (final Constructor<?> constructor : type.getDeclaredConstructors()) { final Class<?>[] constructorTypes = constructor.getParameterTypes(); if (constructorTypes.length == typesLength && (typesLength == 0 || hasCompatibleConstructor(typesArray, constructorTypes))) { return create(type, (Constructor<T>) constructor, paramsQueue.toArray()); } } stop = paramsQueue.isEmpty(); typesQueue.poll(); paramsQueue.poll(); } throw new NoSuchMethodException(ERROR_NO_CONSTRUCTOR_COMPATIBLE + type.getName() + ERROR_WITH + Arrays.asList(paramTypes)); } private  UtilReflection(); static T create(Class<T> type, Class<?>[] paramTypes, Object... params); @SuppressWarnings("unchecked") static T createReduce(Class<T> type, Object... params); static Class<?>[] getParamTypes(Object... arguments); @SuppressWarnings("unchecked") static Constructor<T> getCompatibleConstructor(Class<T> type, Class<?>... paramTypes); @SuppressWarnings("unchecked") static Constructor<T> getCompatibleConstructorParent(Class<T> type, Class<?>[] paramTypes); static T getMethod(Object object, String name, Object... params); static T getField(Object object, String name); static void setAccessible(AccessibleObject object, boolean accessible); static Collection<Class<?>> getInterfaces(Class<?> object, Class<?> base);  }### Answer:
@Test void testCreateReduce() throws NoSuchMethodException { assertEquals(ViewerMock.class, UtilReflection.createReduce(ViewerMock.class, Integer.valueOf(1), "void").getClass()); }
@Test void testCreateReduceNoConstructor() { final String expected = UtilReflection.ERROR_NO_CONSTRUCTOR_COMPATIBLE + Config.class.getName() + UtilReflection.ERROR_WITH + Arrays.asList(Integer.class, String.class); assertThrows(NoSuchMethodException.class, () -> UtilReflection.createReduce(Config.class, Integer.valueOf(1), "void"), expected); }
@Test void testCreateReduceMoreParameters() throws NoSuchMethodException { UtilReflection.createReduce(Reduce.class, Integer.valueOf(1), "test", Integer.valueOf(3)); }