### Question:
ClassUtils { public Method getBuildMethod(final Class<?> parentClass, final Class<?> builderClass) { final String cacheKey = "BuildMethod-" + builderClass.getName(); return CACHE_MANAGER.getFromCache(cacheKey, Method.class).orElseGet(() -> { try { Method method = builderClass.getDeclaredMethod(BUILD_METHOD_NAME); if (!method.getReturnType().equals(parentClass)) { throw new MissingMethodException("Invalid " + BUILD_METHOD_NAME + " method definition. It must returns a: " + parentClass.getCanonicalName()); } method.setAccessible(true); CACHE_MANAGER.cacheObject(cacheKey, method); return method; } catch (NoSuchMethodException e) { throw new MissingMethodException("No Builder " + BUILD_METHOD_NAME + " method defined for class: " + builderClass.getName() + "."); } }); } ClassUtils(); boolean isPrimitiveOrSpecialType(final Class<?> clazz); boolean isPrimitiveType(final Class<?> clazz); boolean isPrimitiveTypeArray(final Class<?> clazz); boolean isSpecialType(final Class<?> clazz); static boolean isDouble(final Class<?> type); static boolean isFloat(final Class<?> type); static boolean isLong(final Class<?> type); static boolean isShort(final Class<?> type); static boolean isInt(final Class<?> type); static boolean isByte(final Class<?> type); static boolean isChar(final Class<?> type); static boolean isBoolean(final Class<?> type); static boolean isString(final Class<?> type); static boolean isBigInteger(final Class<?> type); static boolean isBigDecimal(final Class<?> type); static boolean isByteArray(final Class<?> type); @SuppressWarnings("unchecked") List<Field> getPrivateFinalFields(final Class<?> clazz); int getTotalFields(final Class<?> clazz, final Predicate<? super Field> predicate); List<Field> getPrivateFields(final Class<?> clazz); @SuppressWarnings("unchecked") List<Field> getPrivateFields(final Class<?> clazz, final boolean skipFinal); @SuppressWarnings("unchecked") List<Field> getDeclaredFields(final Class<?> clazz, final boolean skipStatic); Class<?> getFieldClass(final Field field, final T objectInstance); Class<?> getConcreteClass(final Field field, final Object fieldValue); boolean hasAccessibleConstructors(final Class<K> targetClass); Class[] getDeclaredClasses(final Class<?> clazz); @SuppressWarnings("unchecked") Optional<Class<?>> getBuilderClass(final Class<?> targetClass); Method getBuildMethod(final Class<?> parentClass, final Class<?> builderClass); @SuppressWarnings("unchecked") T getInstance(final Constructor constructor, final Object... constructorArgs); @SuppressWarnings("unchecked") Supplier<K> getNoArgsConstructor(final Class<K> clazz); @SuppressWarnings("unchecked") Constructor<K> getAllArgsConstructor(final Class<K> clazz); Parameter[] getConstructorParameters(final Constructor constructor); boolean hasField(final Object target, final String fieldName); boolean hasSetterMethods(final Class<?> clazz); boolean hasFinalFields(final Class<?> clazz); boolean allParameterAnnotatedWith(final Constructor constructor, final Class<? extends Annotation> annotationClass); boolean areParameterNamesAvailable(final Constructor constructor); ClassType getClassType(final Class<?> clazz); List<Method> getSetterMethods(final Class<?> clazz); List<Method> getGetterMethods(final Class<?> clazz); Object getDefaultTypeValue(final Class<?> objectType); @SuppressWarnings("unchecked") List<Field> getNotFinalFields(final Class<?> clazz, final Boolean skipStatic); static final String BUILD_METHOD_NAME; }### Answer:
@Test(dataProvider = "dataGetBuilderMethodExceptionTesting", expectedExceptions = MissingMethodException.class) public void testGetBuildMethodThrowsExceptionIfMethodIsMissing(final String testCaseDescription, final Class<?> containerTestClass, final Class<?> builderClass) { underTest.getBuildMethod(containerTestClass, builderClass); }
@Test public void testGetBuildMethodReturnsTheBuildMethod() { Method actual = underTest.getBuildMethod(MutableToFooWithBuilder.class, MutableToFooWithBuilder.Builder.class); assertThat(actual).isNotNull(); assertThat(actual.getName()).isEqualTo(BUILD_METHOD_NAME); assertThat(actual).hasFieldOrPropertyWithValue(NAME_FIELD_NAME, BUILD_METHOD_NAME); }