/** * Creates a mock from the specified class and sets it as the value in the field with the * specified name in the specified object. Supports inheritance. * * @param object The object to set the value in. * @param fieldName The name of the field. * @param classToMock The class to create a mock from, as the value to set in the field. */ public static <T> T setFieldValueWithMock( final Object object, final String fieldName, final Class<T> classToMock) { Validate.notNull(classToMock, "The class to mock can not be null"); final T mock = mock(classToMock); setFieldValue(object, fieldName, mock); return mock; }
@Before public void setUp() { final Settings settings = mock(Settings.class); when(settings.getMe()).thenReturn(new User("Test", 1234)); messageParser = new MessageParser(mock(MessageResponder.class), settings); TestUtils.setFieldValue(messageParser, "loggedOn", true); log = TestUtils.setFieldValueWithMock(messageParser, "LOG", Logger.class); }