Java Examples for org.powermock.api.mockito.PowerMockito.verifyStatic
The following java examples will help you to understand the usage of org.powermock.api.mockito.PowerMockito.verifyStatic. These source code samples are taken from different open source projects.
Example 1
| Project: cucumber-jvm-master File: DebuggerWaiterTest.java View source code |
@Test
public void waits_for_debugger_when_flag_is_set() {
// given
final Arguments arguments = mock(Arguments.class);
when(arguments.isDebugEnabled()).thenReturn(true);
mockStatic(Debug.class);
final DebuggerWaiter waiter = new DebuggerWaiter(arguments);
// when
waiter.requestWaitForDebugger();
// then
verifyStatic();
Debug.waitForDebugger();
}Example 2
| Project: AnyMaps-master File: ProjectionAdapterTest.java View source code |
@Test
public void testGetVisibleRegion() throws Exception {
// Given
Projection projection = mock(Projection.class);
VisibleRegion visibleRegion = mock(VisibleRegion.class);
doReturn(visibleRegion).when(projection).getVisibleRegion();
ProjectionAdapter adapter = new ProjectionAdapter(projection);
// When
adapter.getVisibleRegion();
// Then
verify(projection).getVisibleRegion();
verifyStatic();
AnyMapAdapter.adapt(refEq(visibleRegion));
}Example 3
| Project: jenkins-master File: CoreEnvironmentContributorTest.java View source code |
@Issue("JENKINS-19307")
@Test
@PrepareForTest(fullyQualifiedNames = { "hudson.model.Computer", "jenkins.model.Jenkins" })
public void buildEnvironmentForJobShouldntUseCurrentComputer() throws IOException, InterruptedException {
PowerMockito.mockStatic(Computer.class);
PowerMockito.mockStatic(Jenkins.class);
PowerMockito.when(Jenkins.getInstance()).thenReturn(jenkins);
when(jenkins.getRootDir()).thenReturn(new File("."));
EnvVars env = new EnvVars();
instance.buildEnvironmentFor(job, env, listener);
// currentComputer shouldn't be called since it relates to a running build,
// which is not the case for calls of this method (e.g. polling)
verifyStatic(times(0));
Computer.currentComputer();
}Example 4
| Project: iris-master File: TestErrorProvider.java View source code |
@Test
public void testWrite() throws Exception {
EntityResource<GenericError> mr = new EntityResource<GenericError>(mock(GenericError.class));
ErrorProvider provider = new ErrorProvider();
// make sure write does nothing
mockStatic(ErrorWriter.class);
MultivaluedMap<String, Object> httpHeaders = new MultivaluedMapImpl<Object>();
provider.writeTo(mr, EntityResource.class, GenericError.class, null, MediaType.APPLICATION_XML_TYPE, httpHeaders, new ByteArrayOutputStream());
// turn on static verification
verifyStatic();
// verify our method called correctly
ErrorWriter.write(any(GenericError.class), any(Writer.class));
//check the response headers
assertEquals(MediaType.APPLICATION_XML, httpHeaders.getFirst(HttpHeaders.CONTENT_TYPE));
}Example 5
| Project: powermock-master File: Mockito2MockStaticTest.java View source code |
@Test
public void testMockStatic() throws Exception {
System.out.println("Skip test while Mockito doesn't deliver fix");
mockStatic(StaticService.class);
String expected = "Hello altered World";
when(StaticService.say("hello")).thenReturn("Hello altered World");
String actual = StaticService.say("hello");
verifyStatic();
StaticService.say("hello");
Assert.assertEquals(expected, actual);
}Example 6
| Project: jrs-rest-java-client-master File: BatchJobsOperationsAdapterTest.java View source code |
@Test
public void should_return_all_jobs() {
// Given
mockStatic(JerseyRequest.class);
when(JerseyRequest.buildRequest(eq(sessionStorageMock), eq(JobSummaryListWrapper.class), eq(new String[] { "jobs" }))).thenReturn(jobSummaryListWrapperJerseyRequest);
when(jobSummaryListWrapperJerseyRequest.get()).thenReturn(jobSummaryListWrapperOperationResult);
when(sessionStorageMock.getConfiguration()).thenReturn(configurationMock);
// When
BatchJobsOperationsAdapter adapter = spy(new BatchJobsOperationsAdapter(sessionStorageMock));
OperationResult<JobSummaryListWrapper> retrieved = adapter.search();
// Then
verifyStatic(times(1));
JerseyRequest.buildRequest(eq(sessionStorageMock), eq(JobSummaryListWrapper.class), eq(new String[] { "jobs" }));
verify(jobSummaryListWrapperJerseyRequest, times(1)).get();
assertNotNull(retrieved);
assertSame(retrieved, jobSummaryListWrapperOperationResult);
}Example 7
| Project: Jasmine-master File: HtmlGeneratorConfigurationTest.java View source code |
@Test
public void shouldReadCustomTemplateWhenOneIsProvided() throws IOException {
mockStatic(FileUtils.class);
File expected = mock(File.class);
IOUtilsWrapper ioUtilsWrapper = mock(IOUtilsWrapper.class);
this.generatorConfiguration = this.initGenerator(ioUtilsWrapper, null, expected);
this.generatorConfiguration.getRunnerTemplate();
verifyStatic(times(1));
FileUtils.readFileToString(expected);
}Example 8
| Project: spring-security-master File: SessionManagementConfigServlet31Tests.java View source code |
@Test
public void changeSessionIdDefaultsInServlet31Plus() throws Exception {
spy(ReflectionUtils.class);
Method method = mock(Method.class);
MockHttpServletRequest request = new MockHttpServletRequest();
request.getSession();
request.setServletPath("/login");
request.setMethod("POST");
request.setParameter("username", "user");
request.setParameter("password", "password");
when(ReflectionUtils.findMethod(HttpServletRequest.class, "changeSessionId")).thenReturn(method);
loadContext("<http>\n" + " <form-login/>\n" + " <session-management/>\n" + " <csrf disabled='true'/>\n" + " </http>" + XML_AUTHENTICATION_MANAGER);
springSecurityFilterChain.doFilter(request, response, chain);
verifyStatic();
ReflectionUtils.invokeMethod(same(method), any(HttpServletRequest.class));
}Example 9
| Project: sqoop-on-spark-master File: TestKiteToDestroyer.java View source code |
@Test
public void testDestroyForFailedJob() {
// setup
DestroyerContext context = new DestroyerContext(null, false, null);
when(KiteDatasetExecutor.listTemporaryDatasetUris(toJobConfig.toJobConfig.uri)).thenReturn(expectedUris);
for (String uri : expectedUris) {
when(Datasets.delete(uri)).thenReturn(true);
}
// exercise
destroyer.destroy(context, linkConfig, toJobConfig);
// verify
for (String uri : expectedUris) {
verifyStatic(times(1));
Datasets.delete(uri);
}
}Example 10
| Project: fcrepo-master File: BasicServerTest.java View source code |
@Test
public void testFirstRunNonemptyDatabase() throws Exception {
long now = System.currentTimeMillis();
when(SQLUtility.getMostRecentRebuild(mockRWConnection)).thenReturn(now);
when(SQLUtility.getRebuildStatus(mockRWConnection, now)).thenReturn(true);
test.checkRebuildHasRun(true);
verifyStatic();
SQLUtility.getRebuildStatus(mockRWConnection, now);
}Example 11
| Project: workberch-tolopogy-master File: WorkberchCartesianBoltTest.java View source code |
@Test
public void testReceivedFieldsFromTwoDifferentSources() {
final List<String> recivedFields = new ArrayList<String>();
recivedFields.add("dummyField1");
recivedFields.add("dummyField2");
final WorkberchCartesianBolt cartesianBolt = spy(new WorkberchCartesianBolt("mockGuid", recivedFields));
final Tuple stormTuple1 = mock(Tuple.class);
final Tuple stormTuple2 = mock(Tuple.class);
given(stormTuple1.getFields()).willReturn(new Fields("dummyField1", INDEX_FIELD));
given(stormTuple2.getFields()).willReturn(new Fields("dummyField2", INDEX_FIELD));
given(stormTuple1.getValueByField(INDEX_FIELD)).willReturn(0L);
given(stormTuple2.getValueByField(INDEX_FIELD)).willReturn(0L);
given(stormTuple1.getValueByField("dummyField1")).willReturn("dummyValue1");
given(stormTuple2.getValueByField("dummyField2")).willReturn("dummyValue2");
given(stormTuple1.getSourceComponent()).willReturn("dummySource1");
given(stormTuple2.getSourceComponent()).willReturn("dummySource2");
final CartesianIndex leaf1 = new CartesianLeaf(0L);
final CartesianIndex leaf2 = new CartesianLeaf(0L);
final List<CartesianIndex> leafs = new ArrayList<CartesianIndex>();
leafs.add(leaf1);
leafs.add(leaf2);
final CartesianIndex index = new CartesianNode(leafs);
final GlobalStreamId stream1 = mock(GlobalStreamId.class);
given(stream1.get_componentId()).willReturn("dummySource1");
final GlobalStreamId stream2 = mock(GlobalStreamId.class);
given(stream2.get_componentId()).willReturn("dummySource2");
final Set<GlobalStreamId> keyStreams = new HashSet<GlobalStreamId>();
keyStreams.add(stream1);
keyStreams.add(stream2);
@SuppressWarnings("unchecked") final Map<GlobalStreamId, Grouping> contextMap = mock(Map.class);
given(contextMap.keySet()).willReturn(keyStreams);
final TopologyContext context = mock(TopologyContext.class);
given(context.getThisComponentId()).willReturn("dummyComponent");
given(context.getThisSources()).willReturn(contextMap);
cartesianBolt.prepare(mock(Map.class), context);
given(RedisHandeler.getEmitedState("dummySource1")).willReturn(1L);
given(RedisHandeler.getEmitedState("dummySource2")).willReturn(0L);
cartesianBolt.execute(stormTuple1, mock(BasicOutputCollector.class));
verify(cartesianBolt, never()).emitTuple(anyListOf(Object.class), any(BasicOutputCollector.class), anyBoolean(), anyString());
verifyStatic();
RedisHandeler.increseRecivedState(anyString());
given(RedisHandeler.getEmitedState("dummySource2")).willReturn(1L);
cartesianBolt.execute(stormTuple2, mock(BasicOutputCollector.class));
verifyStatic(times(2));
RedisHandeler.increseRecivedState(anyString());
verify(cartesianBolt).emitTuple(argThat(new IndexMatcher(index)), any(BasicOutputCollector.class), anyBoolean(), anyString());
}