/** * Get the value of a field using reflection based on the fields type. This * method will traverse the super class hierarchy until the first field of * type <tt>fieldType</tt> is found. The value of this field will be * returned. * * @param object * the object to modify * @param fieldType * the type of the field */ public static <T> T getInternalState(Object object, Class<T> fieldType) { return WhiteboxImpl.getInternalState(object, fieldType); }
/** * Get the value of a field using reflection. This method will iterate * through the entire class hierarchy and return the value of the first * field named <tt>fieldName</tt>. If you want to get a specific field value * at specific place in the class hierarchy please refer to * {@link #getInternalState(Object, String, Class)}. * * @param object * the object to modify * @param fieldName * the name of the field */ public static <T> T getInternalState(Object object, String fieldName) { return WhiteboxImpl.getInternalState(object, fieldName); }
/** * Get the value of a field using reflection based on the fields type. This * method will traverse the super class hierarchy until the first field of * type <tt>fieldType</tt> is found. The value of this field will be * returned. * * @param object * the object to modify * @param fieldType * the type of the field */ public static <T> T getInternalState(Object object, Class<T> fieldType) { return WhiteboxImpl.<T> getInternalState(object, fieldType); }
/** * Get the value of a field using reflection. This method will iterate * through the entire class hierarchy and return the value of the first * field named <tt>fieldName</tt>. If you want to get a specific field value * at specific place in the class hierarchy please refer to * {@link #getInternalState(Object, String, Class)}. * * @param object * the object to modify * @param fieldName * the name of the field */ public static <T> T getInternalState(Object object, String fieldName) { return WhiteboxImpl.<T> getInternalState(object, fieldName); }
/** * Get the value of a field using reflection. Use this method when you need * to specify in which class the field is declared. This might be useful * when you have mocked the instance you are trying to access. * * @param object * the object to modify * @param fieldName * the name of the field * @param where * which class the field is defined */ public static <T> T getInternalState(Object object, String fieldName, Class<?> where) { return WhiteboxImpl.getInternalState(object, fieldName, where); }
/** * Get the value of a field using reflection. Use this method when you need * to specify in which class the field is declared. This might be useful * when you have mocked the instance you are trying to access. * * @param object * the object to modify * @param fieldName * the name of the field * @param where * which class the field is defined */ public static <T> T getInternalState(Object object, String fieldName, Class<?> where) { return WhiteboxImpl.<T> getInternalState(object, fieldName, where); }
/** * Get the value of a field using reflection based on the field type. Use * this method when you need to specify in which class the field is * declared. The first field matching the <tt>fieldType</tt> in * <tt>where</tt> is the field whose value will be returned. * * @param <T> * the expected type of the field * @param object * the object to modify * @param fieldType * the type of the field * @param where * which class the field is defined */ public static <T> T getInternalState(Object object, Class<T> fieldType, Class<?> where) { return WhiteboxImpl.getInternalState(object, fieldType, where); }
/** * Get the value of a field using reflection based on the field type. Use * this method when you need to specify in which class the field is * declared. The first field matching the <tt>fieldType</tt> in * <tt>where</tt> is the field whose value will be returned. * * @param <T> * the expected type of the field * @param object * the object to modify * @param fieldType * the type of the field * @param where * which class the field is defined */ public static <T> T getInternalState(Object object, Class<T> fieldType, Class<?> where) { return WhiteboxImpl.<T> getInternalState(object, fieldType, where); }
public MockType getMockType() { return WhiteboxImpl.getInternalState(invocationHandler.getControl(), MockType.class); }
@Test public void testDestroy() { // given assertNotNull("layout field must not be null before destroy method call", getInternalState(removeView, "layout")); assertNotNull("mWindowManager field must not be null before destroy method call", getInternalState(removeView, "windowManager")); // when removeView.destroy(); // then assertNull("layout field must be set to null after destroy method call", getInternalState(removeView, "layout")); assertNull("mWindowManager field must be set to null after destroy method call", getInternalState(removeView, "windowManager")); } }
@Test public void testIconSize() { // given magnet.show(); // when magnet.setIconSize(iconWidth, iconHeight); // then final LayoutParams layoutParams = getInternalState(magnet, "layoutParams"); final int width = getInternalState(magnet, "iconWidth"); final int height = getInternalState(magnet, "iconHeight"); assertEquals("setIconWidth method must set the iconWidth value of the magnet", iconWidth, width); assertEquals("setIconWidth method must set the iconHeight value of the magnet", iconHeight, height); assertEquals("setIconWidth method must set the width value of the layout params field", iconWidth, layoutParams.width); assertEquals("setIconWidth method must set the height value of the layout params field", iconHeight, layoutParams.height); } }
@Test public void testDestroy() { // given magnet.show(); // when magnet.destroy(); // then verify(windowManagerMock).removeView(iconViewMock); verify(removeViewMock).destroy(); verify(iconCallbackMock).onIconDestroyed(); Context context = getInternalState(magnet, "context"); assertNull("mContext field must be set to null after destroy method call", context); }
View layout = getInternalState(removeView, "layout"); View button = getInternalState(removeView, "button"); View shadow = getInternalState(removeView, "shadow"); View buttonImage = getInternalState(removeView, "buttonImage"); WindowManager windowManager = getInternalState(removeView, "windowManager"); int buttonBottomPadding = getInternalState(removeView, "buttonBottomPadding");