@Test public void cancel() throws Exception { JobCoordinator coordinator = Mockito.mock(JobCoordinator.class); Map<Long, JobCoordinator> map = Maps.newHashMap(); long jobId = 1L; map.put(jobId, coordinator); Whitebox.setInternalState(mJobMaster, "mIdToJobCoordinator", map); mJobMaster.cancel(jobId); Mockito.verify(coordinator).cancel(); }
public SerializableMockitoMethodProxy(MethodProxy methodProxy) { Object info = Whitebox.getInternalState(methodProxy, "createInfo"); c1 = (Class<?>) Whitebox.getInternalState(info, "c1"); c2 = (Class<?>) Whitebox.getInternalState(info, "c2"); desc = methodProxy.getSignature().getDescriptor(); name = methodProxy.getSignature().getName(); superName = methodProxy.getSuperName(); this.methodProxy = methodProxy; }
private static Field getFieldFromHierarchy(Class<?> clazz, String field) { Field f = getField(clazz, field); while (f == null && clazz != Object.class) { clazz = clazz.getSuperclass(); f = getField(clazz, field); } if (f == null) { throw new RuntimeException( "You want me to set value to this field: '" + field + "' on this class: '" + clazz.getSimpleName() + "' but this field is not declared withing hierarchy of this class!"); } return f; }
public void appendWarnings(Failure failure, String warnings) { if (isEmpty(warnings)) { return; } //TODO: this has to protect the use in case jUnit changes and this internal state logic fails Throwable throwable = (Throwable) Whitebox.getInternalState(failure, "fThrownException"); String newMessage = "contains both: actual test failure *and* Mockito warnings.\n" + warnings + "\n *** The actual failure is because of: ***\n"; ExceptionIncludingMockitoWarnings e = new ExceptionIncludingMockitoWarnings(newMessage, throwable); e.setStackTrace(throwable.getStackTrace()); Whitebox.setInternalState(failure, "fThrownException", e); }
private void changeInternalStateForTesting(PhoenixResultSet rs) { // get and set the internal state for testing purposes. ReadMetricQueue testMetricsQueue = new TestReadMetricsQueue(LogLevel.OFF,true); StatementContext ctx = (StatementContext)Whitebox.getInternalState(rs, "context"); Whitebox.setInternalState(ctx, "readMetricsQueue", testMetricsQueue); Whitebox.setInternalState(rs, "readMetricsQueue", testMetricsQueue); }
public void testFailedPutUser() throws Exception { final ContentProviderStorage storage = new ContentProviderStorage(getProviderMockContext(), "testPut_Device", TrayStorage.Type.USER); TrayProviderHelper mockHelper = mock(TrayProviderHelper.class); when(mockHelper.persist(any(Uri.class), anyString(), anyString())).thenReturn(false); Whitebox.setInternalState(storage, "mProviderHelper", mockHelper); assertFalse(storage.put(TEST_KEY, TEST_STRING)); assertDeviceDatabaseSize(0); assertUserDatabaseSize(0); }
public SerializableMockitoMethodProxy(MethodProxy methodProxy) { assert methodProxy != null; Object info = Whitebox.getInternalState(methodProxy, "createInfo"); c1 = (Class<?>) Whitebox.getInternalState(info, "c1"); c2 = (Class<?>) Whitebox.getInternalState(info, "c2"); desc = methodProxy.getSignature().getDescriptor(); name = methodProxy.getSignature().getName(); superName = methodProxy.getSuperName(); this.methodProxy = methodProxy; }
public void appendWarnings(Failure failure, String warnings) { if (isEmpty(warnings)) { return; } //TODO: this has to protect the use in case jUnit changes and this internal state logic fails Throwable throwable = (Throwable) Whitebox.getInternalState(failure, "fThrownException"); String newMessage = "contains both: actual test failure *and* Mockito warnings.\n" + warnings + "\n *** The actual failure is because of: ***\n"; ExceptionIncludingMockitoWarnings e = new ExceptionIncludingMockitoWarnings(newMessage, throwable); e.setStackTrace(throwable.getStackTrace()); Whitebox.setInternalState(failure, "fThrownException", e); }
public void testFailedPutDevice() throws Exception { final ContentProviderStorage storage = new ContentProviderStorage(getProviderMockContext(), "testPut_Device", TrayStorage.Type.DEVICE); TrayProviderHelper mockHelper = mock(TrayProviderHelper.class); when(mockHelper.persist(any(Uri.class), anyString(), anyString())).thenReturn(false); Whitebox.setInternalState(storage, "mProviderHelper", mockHelper); assertFalse(storage.put(TEST_KEY, TEST_STRING)); assertDeviceDatabaseSize(0); assertUserDatabaseSize(0); }
public void testVersionChangeFailed() throws Exception { final TrayStorage storage = Mockito.mock(TrayStorage.class); Mockito.when(storage.getVersion()) .thenThrow(new TrayException("something very very bad happened :-(")); final MockSimplePreferences mockPreference = new MockSimplePreferences(storage, 1); assertFalse(mockPreference.isVersionChangeChecked()); assertFalse((Boolean) Whitebox.getInternalState(mockPreference, "mChangeVersionSucceeded")); }
@Test public void testRemoveSequenceDescriptorsShouldNotRemoveDescriptor() { //GIVEN Map<String, SequenceDescriptor> descriptors = new ConcurrentHashMap<>(); descriptors.put("TestTeam-fistDescriptor-TestHandler", sequenceDescriptor); Whitebox.setInternalState(underTest, "descriptors", descriptors); //WHEN underTest.removeSequenceDescriptors("something"); //THEN Map<String, SequenceDescriptor> actualDescriptors = (Map<String, SequenceDescriptor>) Whitebox.getInternalState(underTest, "descriptors"); Assert.assertEquals(actualDescriptors.size(), 1); }
doCallRealMethod().when( rest ).searchForHeaders( any() ); setInternalState( rest, "meta", meta ); setInternalState( rest, "data", data );
@Test public void testPartitionHeaderOutOfRange() throws Exception { Sink kafkaSink = new KafkaSink(); try { doPartitionErrors(PartitionOption.VALIDBUTOUTOFRANGE, kafkaSink); fail(); } catch (EventDeliveryException e) { // } SinkCounter sinkCounter = (SinkCounter) Whitebox.getInternalState(kafkaSink, "counter"); assertEquals(1, sinkCounter.getEventWriteFail()); }
@Test public void testAreAppNotificationsEnabled_callsPlatformMethod_whenOptOutProviderReturnsFalse() { mockAppLevelOptOutProvider(false); final NotificationClientBase notificationClient = Mockito.mock(NotificationClientBase.class, withSettings().defaultAnswer(CALLS_REAL_METHODS)); Whitebox.setInternalState(notificationClient, "pinpointContext", mockPinpointContext); notificationClient.areAppNotificationsEnabled(); verify(notificationClient).areAppNotificationsEnabledOnPlatform(); }
Set<Integer> unwrapped = (Set<Integer>)Whitebox.getInternalState( gridAffinityAssignment2.primaryPartitions(clusterNode1.id()), "c"
@Test public void testAreAppNotificationsEnabled_callsPlatformMethod_whenOptOutProviderReturnsFalse() { mockAppLevelOptOutProvider(false); final NotificationClientBase notificationClient = Mockito.mock(NotificationClientBase.class, withSettings().defaultAnswer(CALLS_REAL_METHODS)); Whitebox.setInternalState(notificationClient, "pinpointContext", mockPinpointContext); notificationClient.areAppNotificationsEnabled(); verify(notificationClient).areAppNotificationsEnabledOnPlatform(); }
@Test public void testEndpointMetric() { target.addMetric(null, 0.0); assertTrue(target.getAllMetrics().isEmpty()); assertNull(target.getMetric(null)); assertFalse(target.hasMetric(null)); assertEquals(((AtomicInteger) Whitebox.getInternalState(target, "currentNumOfAttributesAndMetrics")).get(), 0); target.addMetric("key1", 0.0); assertFalse(target.getAllMetrics().isEmpty()); assertNotNull(target.getMetric("key1")); assertTrue(target.hasMetric("key1")); assertEquals(((AtomicInteger) Whitebox.getInternalState(target, "currentNumOfAttributesAndMetrics")).get(), 1); target.addMetric("key1", null); assertTrue(target.getAllMetrics().isEmpty()); assertEquals(((AtomicInteger) Whitebox.getInternalState(target, "currentNumOfAttributesAndMetrics")).get(), 0); target.withMetric("key2", 0.0); assertTrue(target.hasMetric("key2")); assertEquals(((AtomicInteger) Whitebox.getInternalState(target, "currentNumOfAttributesAndMetrics")).get(), 1); }
@Test public void testAreAppNotificationsEnabled_callsPlatformMethod_whenOptOutProviderReturnsFalse() { mockAppLevelOptOutProvider(false); final NotificationClientBase notificationClient = Mockito.mock(NotificationClientBase.class, withSettings().defaultAnswer(CALLS_REAL_METHODS)); Whitebox.setInternalState(notificationClient, "pinpointContext", mockPinpointContext); notificationClient.areAppNotificationsEnabled(); verify(notificationClient).areAppNotificationsEnabledOnPlatform(); }
ConnectionQueryServices rebuildQueryServices = rebuildIndexConnection.getQueryServices(); Connection rebuildIndexHConnection = (Connection) Whitebox.getInternalState(rebuildQueryServices, "connection"); Connection regularHConnection = (Connection) Whitebox.getInternalState( regularConnection.getQueryServices(), "connection");
@Test public void testAreAppNotificationsEnabled_callsPlatformMethod_whenOptOutProviderReturnsFalse() { mockAppLevelOptOutProvider(false); final NotificationClientBase notificationClient = Mockito.mock(NotificationClientBase.class, withSettings().defaultAnswer(CALLS_REAL_METHODS)); Whitebox.setInternalState(notificationClient, "pinpointContext", mockPinpointContext); notificationClient.areAppNotificationsEnabled(); verify(notificationClient).areAppNotificationsEnabledOnPlatform(); }