/** * Resets the cache for GroupMappingService. */ public static void resetCache() { Whitebox.setInternalState(GroupMappingService.Factory.class, "sCachedGroupMapping", (CachedGroupMapping) null); } }
/** * Resets the singleton {@link LoginUser} to null. */ public static void resetLoginUser() { synchronized (LoginUser.class) { Whitebox.setInternalState(LoginUser.class, "sLoginUser", (String) null); } }
/** * Creates a mock {@link DataOutputStream} for {@link UfsJournalLogWriter#mJournalOutputStream}. * * @param writer the {@link UfsJournalLogWriter} instance for which the mock is created * @return the created mock {@link DataOutputStream} instance */ private DataOutputStream createMockDataOutputStream(UfsJournalLogWriter writer) { DataOutputStream badOut = Mockito.mock(DataOutputStream.class); Object journalOutputStream = writer.getJournalOutputStream(); Whitebox.setInternalState(journalOutputStream, "mOutputStream", badOut); return badOut; }
/** * Resets the {@link LoginUser} and re-login with new user. * * @param user the new user */ public static void resetLoginUser(String user) { synchronized (LoginUser.class) { Whitebox.setInternalState(LoginUser.class, "sLoginUser", new User(user)); } } }
@Override public void evaluate() throws Throwable { long previousValue = TtlBucket.getTtlIntervalMs(); Whitebox.setInternalState(TtlBucket.class, "sTtlIntervalMs", mIntervalMs); try { statement.evaluate(); } finally { Whitebox.setInternalState(TtlBucket.class, "sTtlIntervalMs", previousValue); } } };
@Before public void setup() { Whitebox.setInternalState(SpringSecurityCoreVersion.class, logger); }
@Before public void setup() { mContext = new ComponentContext(RuntimeEnvironment.application); mComponent = TestLayoutComponent.create(mContext) .build(); Whitebox.setInternalState(mComponent, "mId", COMPONENT_ID); mLayoutState = new LayoutState(); Whitebox.setInternalState(mLayoutState, "mWidth", WIDTH); Whitebox.setInternalState(mLayoutState, "mHeight", HEIGHT); Whitebox.setInternalState(mLayoutState, "mComponent", mComponent); }
@Test public void emptyAndNullsAreDifferent() throws Exception { System.setProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "Y" ); Whitebox.setInternalState( ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", true ); List<Object[]> expected = Arrays.asList( new Object[] { "", "", null }, new Object[] { "", "", null }, new Object[] { "", "", null } ); executeAndAssertResults( expected ); }
@Test public void emptyAndNullsAreNotDifferent() throws Exception { System.setProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "N" ); Whitebox.setInternalState( ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", false ); List<Object[]> expected = Arrays.asList( new Object[] { "a", "", "a" }, new Object[] { "b", null, "b" }, new Object[] { null } ); executeAndAssertResults( expected ); }
@Test public void emptyAndNullsAreDifferent() throws Exception { System.setProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "Y" ); Whitebox.setInternalState( ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", true ); List<Object[]> expected = Arrays.asList( new Object[] { false, "" }, new Object[] { false, "" }, new Object[] { false, null } ); executeAndAssertResults( expected ); }
@Test public void emptyAndNullsAreNotDifferent() throws Exception { System.setProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "N" ); Whitebox.setInternalState( ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", false ); List<Object[]> expected = Arrays.asList( new Object[] { "", "", null }, new Object[] { null, "", null }, new Object[] { null, "", null } ); executeAndAssertResults( expected ); }
@Test public void emptyAndNullsAreDifferent() throws Exception { System.setProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "Y" ); Whitebox.setInternalState( ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", true ); List<Object[]> expected = Arrays.asList( new Object[] { "a", "", "a" }, new Object[] { "b", "", "b" }, new Object[] { "", "", "" } ); executeAndAssertResults( expected ); }
@Before public void setup() { mContext = new ComponentContext(RuntimeEnvironment.application); mWidthSpec = SizeSpec.makeSizeSpec(39, SizeSpec.EXACTLY); mHeightSpec = SizeSpec.makeSizeSpec(41, SizeSpec.EXACTLY); mComponent = TestLayoutComponent.create(mContext) .build(); Whitebox.setInternalState(mComponent, "mId", COMPONENT_ID); mLayoutState = new LayoutState(); Whitebox.setInternalState(mLayoutState, "mComponent", mComponent); Whitebox.setInternalState(mLayoutState, "mWidthSpec", mWidthSpec); Whitebox.setInternalState(mLayoutState, "mHeightSpec", mHeightSpec); }
private static void clearFlag(InternalNode internalNode, String flagName) { long flagPosition = Whitebox.getInternalState(InternalNode.class, flagName); long flags = Whitebox.getInternalState(internalNode, "mPrivateFlags"); flags &= ~flagPosition; Whitebox.setInternalState(internalNode, "mPrivateFlags", flags); }
private static void clearFlag(NodeInfo nodeInfo, String flagName) { int flagPosition = Whitebox.getInternalState(NodeInfo.class, flagName); int flags = Whitebox.getInternalState(nodeInfo, "mPrivateFlags"); flags &= ~flagPosition; Whitebox.setInternalState(nodeInfo, "mPrivateFlags", flags); }
@Test public void testGetJavadocBefore() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" "))); final Map<Integer, TextBlock> javadoc = new HashMap<>(); javadoc.put(0, new Comment(new String[] {"// "}, 2, 1, 2)); Whitebox.setInternalState(fileContents, "javadocComments", javadoc); final TextBlock javadocBefore = fileContents.getJavadocBefore(2); assertEquals("Invalid before javadoc", new Comment(new String[] {"// "}, 2, 1, 2).toString(), javadocBefore.toString()); }
@Before public void before() { Whitebox.setInternalState(FacebookSdk.class, "callbackRequestCodeOffset", 0xface); Whitebox.setInternalState(FacebookSdk.class, "sdkInitialized", false); stub(method(FetchedAppSettingsManager.class, "loadAppSettingsAsync")).toReturn(null); FacebookSdk.setAutoLogAppEventsEnabled(false); }
@Before public void before() { mTaskExecutorManager = PowerMockito.mock(TaskExecutorManager.class); mRegistry = PowerMockito.mock(JobDefinitionRegistry.class); Whitebox.setInternalState(JobDefinitionRegistry.class, "INSTANCE", mRegistry); }
@Before public void before() { FacebookSdk.setApplicationId("123456789"); FacebookSdk.setAutoLogAppEventsEnabled(false); FacebookSdk.sdkInitialize(RuntimeEnvironment.application); // Reset the static state every time so tests don't interfere with each other. Whitebox.setInternalState( CallbackManagerImpl.class, "staticCallbacks", new HashMap<Integer, CallbackManagerImpl.Callback>()); }
@Test public void testRetainAnimationStateAfterExitingRange() { ComponentTreeHolder holder = createComponentTreeHolder(mComponentRenderInfo); holder.computeLayoutSync(mContext, mWidthSpec, mHeightSpec, new Size()); assertThat(holder.getComponentTree().hasMounted()).isFalse(); Whitebox.setInternalState(holder.getComponentTree(), "mHasMounted", true); // component goes out of range holder.acquireStateAndReleaseTree(); assertThat(holder.getComponentTree()).isNull(); // component comes back within range holder.computeLayoutSync(mContext, mWidthSpec, mHeightSpec, new Size()); assertThat(holder.getComponentTree().hasMounted()).isTrue(); }