/** Access the default layout thread looper for testing purposes only. */ public static Looper getDefaultLayoutThreadLooper() throws Exception { return (Looper) Whitebox.invokeMethod(ComponentTree.class, "getDefaultLayoutThreadLooper"); }
/** * Unbinds a component tree from a component view. * * @param lithoView The view to unbind. */ public static void unbindComponent(LithoView lithoView) { try { Whitebox.invokeMethod(lithoView, "onDetach"); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Expect calls to private methods without having to specify the method * name. The method will be looked up using the parameter types (if * possible). * * @see {@link Mockito#when(Object)} * @throws Exception * If something unexpected goes wrong. */ public static <T> OngoingStubbing<T> when(Object instance, Object... arguments) throws Exception { return Mockito.when(Whitebox.<T> invokeMethod(instance, arguments)); }
private void performChecks(String minSpringVersion) throws Exception { Whitebox.invokeMethod(SpringSecurityCoreVersion.class, "performVersionChecks", minSpringVersion); } }
private void performChecks() throws Exception { Whitebox.invokeMethod(SpringSecurityCoreVersion.class, "performVersionChecks"); }
private VerificationMode getVerificationMode() { try { MockingProgress progress = Whitebox.invokeMethod(ThreadSafeMockingProgress.class, "threadSafely"); return getVerificationModeFromMockProgress(progress); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void close() throws Exception { for (String threadName : mThreads) { Whitebox.invokeMethod(HeartbeatContext.class, "setTimerClass", threadName, mPrevious.get(threadName)); } } }
private static boolean componentTreeHasSizeSpec(ComponentTree componentTree) { try { boolean hasCssSpec; // Need to hold the lock on componentTree here otherwise the invocation of hasCssSpec // will fail. synchronized (componentTree) { hasCssSpec = Whitebox.invokeMethod(componentTree, ComponentTree.class, "hasSizeSpec"); } return hasCssSpec; } catch (Exception e) { throw new IllegalArgumentException("Failed to invoke hasSizeSpec on ComponentTree for: "+e); } }
@Override public <T> void when(Class<T> classMock, Object... arguments) throws Exception { assertNotNull(classMock, "classMock"); when(classMock); Whitebox.invokeMethod(classMock, arguments); }
private int getDrawableItemsSize() throws Exception { SparseArrayCompat drawableItems = Whitebox.getInternalState(mHost, "mDrawableMountItems"); return Whitebox.invokeMethod(drawableItems, "size"); }
@Override public void run() { try { mLayoutThreadShadowLooper = Shadows.shadowOf( (Looper) Whitebox.invokeMethod(ComponentTree.class, "getDefaultLayoutThreadLooper")); } catch (Exception e) { e.printStackTrace(); } } }.run();
public Resource(List<String> threads) { mThreads = threads; mPrevious = new HashMap<>(); for (String threadName : mThreads) { try { mPrevious.put(threadName, HeartbeatContext.getTimerClass(threadName)); Whitebox.invokeMethod(HeartbeatContext.class, "setTimerClass", threadName, HeartbeatContext.SCHEDULED_TIMER_CLASS); } catch (Exception e) { throw new RuntimeException(e); } } }
private MountItem getDrawableMountItemAt(int index) throws Exception { SparseArrayCompat drawableItems = Whitebox.getInternalState(mHost, "mDrawableMountItems"); return Whitebox.invokeMethod(drawableItems, "valueAt", index); }
@Test public void testParsePropertyString() throws Exception { final List<String> propertyRefs = new ArrayList<>(); final List<String> fragments = new ArrayList<>(); Whitebox.invokeMethod(ConfigurationLoader.class, "parsePropertyString", "$", fragments, propertyRefs); assertEquals("Fragments list has unexpected amount of items", 1, fragments.size()); }
@Before public void setup() throws Exception { mComponentContext = new ComponentContext(RuntimeEnvironment.application); mRecyclerView = mock(RecyclerView.class); mLayoutThreadShadowLooper = Shadows.shadowOf( (Looper) Whitebox.invokeMethod(ComponentTree.class, "getDefaultLayoutThreadLooper")); }
@Before public void setup() throws Exception { mSectionContext = new SectionContext(RuntimeEnvironment.application); mChangeSetThreadShadowLooper = Shadows.shadowOf( (Looper) Whitebox.invokeMethod( SectionTree.class, "getDefaultChangeSetThreadLooper")); }
@Test public void testLoadHeaderFileTwice() throws Exception { final HeaderCheck check = new HeaderCheck(); check.setHeader("Header"); try { Whitebox.invokeMethod(check, "loadHeaderFile"); fail("ConversionException is expected"); } catch (IllegalArgumentException ex) { assertEquals("Invalid exception message", "header has already been set - " + "set either header or headerFile, not both", ex.getMessage()); } }
@Test public void testRegisterIntegralTypes() throws Exception { final ConvertUtilsBeanStub convertUtilsBean = new ConvertUtilsBeanStub(); Whitebox.invokeMethod(AutomaticBean.class, "registerIntegralTypes", convertUtilsBean); assertEquals("Number of converters registered differs from expected", 81, convertUtilsBean.getRegisterCount()); }
@Before public void setup() throws Exception { mContext = new ComponentContext(new ContextWrapper(RuntimeEnvironment.application)); mLayoutThreadShadowLooper = Shadows.shadowOf( (Looper) Whitebox.invokeMethod(ComponentTree.class, "getDefaultLayoutThreadLooper")); }
@Before public void setup() throws Exception { mContext = new ComponentContext(RuntimeEnvironment.application); mComponent = TestDrawableComponent.create(mContext).build(); mComponentTree = create(mContext, mComponent).build(); mLayoutThreadShadowLooper = Shadows.shadowOf( (Looper) Whitebox.invokeMethod(ComponentTree.class, "getDefaultLayoutThreadLooper")); mWidthSpec = makeSizeSpec(39, EXACTLY); mWidthSpec2 = makeSizeSpec(40, EXACTLY); mHeightSpec = makeSizeSpec(41, EXACTLY); mHeightSpec2 = makeSizeSpec(42, EXACTLY); }