ProtoUtils { public static Message.Builder getBuilder(Class<? extends Message> clazz) { final Message.Builder protoBuilder; try { Method newBuilderMethod = clazz.getMethod("newBuilder"); protoBuilder = (Message.Builder)newBuilderMethod.invoke(null); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new MappingException("Failed to create Message.Builder for " + clazz.getCanonicalName(), e); } return protoBuilder; } private  ProtoUtils(); static Message.Builder getBuilder(Class<? extends Message> clazz); static List<Descriptors.FieldDescriptor> getFieldDescriptors(Class<? extends Message> clazz); static Descriptors.FieldDescriptor getFieldDescriptor(Class<? extends Message> clazz, String fieldName); static Object getFieldValue(Object message, String fieldName); static Class<?> getJavaClass(final Descriptors.FieldDescriptor descriptor, BeanContainer beanContainer); static Class<?> getJavaGenericClassForCollection(final Descriptors.FieldDescriptor descriptor, BeanContainer beanContainer); @SuppressWarnings("unchecked") static Object wrapEnums(Object value); @SuppressWarnings("unchecked") static Object unwrapEnums(Object value, BeanContainer beanContainer); static String toCamelCase(String name);  }
@Test public void canGetBuilder() { Message.Builder result = ProtoUtils.getBuilder(ProtoTestObjects.ProtobufFieldNaming.class); assertNotNull(result); }
@Test public void handlesIncorrectMessage() { handlesIncorrectMessageExpectedException.expect(MappingException.class); handlesIncorrectMessageExpectedException.expectMessage("Failed to create Message.Builder for com.github.dozermapper.protobuf.vo.proto.FakeMessage"); handlesIncorrectMessageExpectedException.expectCause(IsInstanceOf.instanceOf(NoSuchMethodException.class)); ProtoUtils.getBuilder(FakeMessage.class); }