use of org.powermock.core.classloader.annotations.PrepareForTest in project mobile-center-sdk-android by Microsoft.
the class AppCenterFutureTest method isDoneWithInterruption.
@Test
@PrepareForTest(DefaultAppCenterFuture.class)
public void isDoneWithInterruption() throws Exception {
CountDownLatch latch = mock(CountDownLatch.class);
whenNew(CountDownLatch.class).withAnyArguments().thenReturn(latch);
when(latch.await(anyLong(), any(TimeUnit.class))).thenThrow(new InterruptedException()).thenReturn(true);
final DefaultAppCenterFuture<Boolean> future = new DefaultAppCenterFuture<>();
final AtomicReference<Boolean> result = new AtomicReference<>();
Thread thread = new Thread() {
@Override
public void run() {
result.set(future.isDone());
}
};
thread.start();
thread.join();
assertEquals(true, result.get());
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project leopard by tanhaichao.
the class LoepardMockRunnerDelegateImpl method autoMockStatic.
/**
* 自动mock静态类.
*/
protected void autoMockStatic() {
Description description = getDescription();
PrepareForTest prepareForTest = description.getAnnotation(PrepareForTest.class);
// System.out.println("prepareForTest:" + prepareForTest);
if (prepareForTest == null) {
return;
}
Class<?>[] classes = prepareForTest.value();
mockStatic(classes);
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project pentaho-kettle by pentaho.
the class StepWithMappingMetaTest method activateParamsTest.
@Test
@PrepareForTest(StepWithMappingMeta.class)
public void activateParamsTest() throws Exception {
String childParam = "childParam";
String childValue = "childValue";
String paramOverwrite = "paramOverwrite";
String parentValue = "parentValue";
VariableSpace parent = new Variables();
parent.setVariable(paramOverwrite, parentValue);
TransMeta childVariableSpace = new TransMeta();
childVariableSpace.setParameterValue(childParam, childValue);
String[] parameters = childVariableSpace.listParameters();
StepWithMappingMeta.activateParams(childVariableSpace, childVariableSpace, parent, parameters, new String[] { childParam, paramOverwrite }, new String[] { childValue, childValue });
Assert.assertEquals(childValue, childVariableSpace.getVariable(childParam));
Assert.assertEquals(parentValue, childVariableSpace.getVariable(paramOverwrite));
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project pentaho-kettle by pentaho.
the class AllocateServerSocketServletTest method testAllocateServerSocketServletEncodesParametersForHmtlResponse.
@Test
@PrepareForTest({ Encode.class })
public void testAllocateServerSocketServletEncodesParametersForHmtlResponse() throws ServletException, IOException {
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
HttpServletResponse mockResponse = mock(HttpServletResponse.class);
SocketPortAllocation mockSocketPortAllocation = mock(SocketPortAllocation.class);
PowerMockito.spy(Encode.class);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ServletOutputStream servletOutputStream = new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
byteArrayOutputStream.write(b);
}
};
when(mockRequest.getContextPath()).thenReturn(AllocateServerSocketServlet.CONTEXT_PATH);
when(mockRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
when(mockResponse.getOutputStream()).thenReturn(servletOutputStream);
when(mockTransformationMap.allocateServerSocketPort(anyInt(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(mockSocketPortAllocation);
allocateServerSocketServlet.doGet(mockRequest, mockResponse);
String response = byteArrayOutputStream.toString();
// Pull out dynamic part of body, remove hardcoded html
String dynamicBody = ServletTestUtils.getInsideOfTag("BODY", response).replaceAll("<p>", "").replaceAll("<br>", "").replaceAll("<H1>.+</H1>", "").replaceAll("--> port", "");
assertFalse(ServletTestUtils.hasBadText(dynamicBody));
PowerMockito.verifyStatic(atLeastOnce());
Encode.forHtml(anyString());
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project pentaho-kettle by pentaho.
the class CleanupTransServletTest method testCleanupTransServletEscapesHtmlWhenTransNotFound.
@Test
@PrepareForTest({ Encode.class })
public void testCleanupTransServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
PowerMockito.spy(Encode.class);
when(mockHttpServletRequest.getContextPath()).thenReturn(CleanupTransServlet.CONTEXT_PATH);
when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
cleanupTransServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
PowerMockito.verifyStatic(atLeastOnce());
Encode.forHtml(anyString());
}
Aggregations