本文整理匯總了Java中org.powermock.api.easymock.PowerMock.mockStatic方法的典型用法代碼示例。如果您正苦於以下問題:Java PowerMock.mockStatic方法的具體用法?Java PowerMock.mockStatic怎麽用?Java PowerMock.mockStatic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.powermock.api.easymock.PowerMock
的用法示例。
在下文中一共展示了PowerMock.mockStatic方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
worker = PowerMock.createMock(Worker.class);
EasyMock.expect(worker.isSinkConnector(CONN1)).andStubReturn(Boolean.FALSE);
time = new MockTime();
herder = PowerMock.createPartialMock(DistributedHerder.class, new String[]{"backoff", "updateDeletedConnectorStatus"},
new DistributedConfig(HERDER_CONFIG), worker, WORKER_ID, statusBackingStore, configBackingStore, member, MEMBER_URL, time);
configUpdateListener = herder.new ConfigUpdateListener();
rebalanceListener = herder.new RebalanceListener();
plugins = PowerMock.createMock(Plugins.class);
pluginLoader = PowerMock.createMock(PluginClassLoader.class);
delegatingLoader = PowerMock.createMock(DelegatingClassLoader.class);
PowerMock.mockStatic(Plugins.class);
PowerMock.expectPrivate(herder, "updateDeletedConnectorStatus").andVoid().anyTimes();
}
示例2: whenLoadByUsernameCalledWithKnownUsernameThenExpectUserDetailsToBeReturned
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void whenLoadByUsernameCalledWithKnownUsernameThenExpectUserDetailsToBeReturned() throws Exception {
PowerMock.mockStatic(JwtUserFactory.class);
final User user = PowerMock.createMock(User.class);
final JwtUser jwtUser = EasyMock.createMock(JwtUser.class);
expect(userRepository.findByUsername(KNOWN_USERNAME)).andStubReturn(user);
expect(JwtUserFactory.create(eq(user))).andStubReturn(jwtUser);
PowerMock.replayAll();
final JwtUserDetailsService jwtUserDetailsService = new JwtUserDetailsService(userRepository);
final JwtUser userDetails = (JwtUser) jwtUserDetailsService.loadUserByUsername(KNOWN_USERNAME);
assertEquals(jwtUser, userDetails);
PowerMock.verifyAll();
}
示例3: setup
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setup() {
super.setup();
Map<String, String> workerProps = new HashMap<>();
workerProps.put("key.converter", "org.apache.kafka.connect.json.JsonConverter");
workerProps.put("value.converter", "org.apache.kafka.connect.json.JsonConverter");
workerProps.put("internal.key.converter", "org.apache.kafka.connect.json.JsonConverter");
workerProps.put("internal.value.converter", "org.apache.kafka.connect.json.JsonConverter");
workerProps.put("internal.key.converter.schemas.enable", "false");
workerProps.put("internal.value.converter.schemas.enable", "false");
workerProps.put("offset.storage.file.filename", "/tmp/connect.offsets");
config = new StandaloneConfig(workerProps);
PowerMock.mockStatic(Plugins.class);
}
示例4: setUp
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
helper.setUp();
localUserMock = PowerMock.createMock(LocalUser.class);
PowerMock.mockStatic(LocalUser.class);
expect(LocalUser.getInstance()).andReturn(localUserMock).anyTimes();
localUserMock.set(new User("1", "NonSuch", "NoName", null, 0, false, false, 0, null));
expectLastCall().times(1);
expect(localUserMock.getUserEmail()).andReturn("NonSuch").times(1);
localUserInfo = PowerMock.createMock(OdeAuthFilter.UserInfo.class);
expect(localUserInfo.buildCookie(false)).andReturn("NoCookie").anyTimes();
expect(localUserInfo.buildCookie(true)).andReturn("NoCookie").anyTimes();
mockFilterChain = PowerMock.createNiceMock(FilterChain.class);
mockServletRequest = PowerMock.createNiceMock(HttpServletRequest.class);
mockServletResponse = PowerMock.createNiceMock(HttpServletResponse.class);
}
示例5: testDoRegisterLspWS
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testDoRegisterLspWS() throws IOException, ServletException {
String regData = "/:aLang=/testWS/aLang";
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
PowerMock.mockStatic(WebSocketClient.class);
expect(WebSocketClient.getInstance()).andReturn(wsClient);
replayAll();
BufferedReader reader;
// Register
try (InputStream is = new ByteArrayInputStream(regData.getBytes())) {
reader = new BufferedReader(new InputStreamReader(is));
}
Mockito.when(request.getReader()).thenReturn(reader);
Mockito.when(request.getHeader("Register-lsp")).thenReturn("true");
cut.doPost(request, response);
Map<String, LSPDestination> reg = TestUtils.getInternalState(cut, "lspDestPath");
assertTrue("No listener registered", !reg.entrySet().isEmpty());
assertNotNull("Wrong registration key", reg.get("/:aLang"));
assertNotNull("Wrong registration url", reg.get("/:aLang").getWebSocketClient());
// Unregister
try (InputStream is = new ByteArrayInputStream(regData.getBytes())) {
reader = new BufferedReader(new InputStreamReader(is));
}
Mockito.when(request.getReader()).thenReturn(reader);
Mockito.when(request.getHeader("Register-lsp")).thenReturn("false");
cut.doPost(request, response);
reg = TestUtils.getInternalState(cut, "lspDestPath");
assertTrue("Listener unregistered", reg.entrySet().isEmpty());
}
示例6: testDoRegisterLspProj
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testDoRegisterLspProj() throws IOException, ServletException {
String regData = "/myProj/:aLang/=/testWS/aLang";
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
PowerMock.mockStatic(WebSocketClient.class);
expect(WebSocketClient.getInstance()).andReturn(wsClient);
replayAll();
BufferedReader reader;
// Register
try (InputStream is = new ByteArrayInputStream(regData.getBytes())) {
reader = new BufferedReader(new InputStreamReader(is));
}
Mockito.when(request.getReader()).thenReturn(reader);
Mockito.when(request.getHeader("Register-lsp")).thenReturn("true");
cut.doPost(request, response);
Map<String, LSPDestination> reg = TestUtils.getInternalState(cut, "lspDestPath");
assertTrue("No listener registered", !reg.entrySet().isEmpty());
assertNotNull("Wrong registration key", reg.get("/myProj/:aLang/"));
assertNotNull("Wrong registration url", reg.get("/myProj/:aLang/").getWebSocketClient());
// Unregister
try (InputStream is = new ByteArrayInputStream(regData.getBytes())) {
reader = new BufferedReader(new InputStreamReader(is));
}
Mockito.when(request.getReader()).thenReturn(reader);
Mockito.when(request.getHeader("Register-lsp")).thenReturn("false");
cut.doPost(request, response);
reg = TestUtils.getInternalState(cut, "lspDestPath");
assertTrue("Listener unregistered", reg.entrySet().isEmpty());
}
示例7: testDoRegisterLspModule
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testDoRegisterLspModule() throws IOException, ServletException {
String regData = "/myProj/myModule/:aLang/=/testWS/aLang";
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
PowerMock.mockStatic(WebSocketClient.class);
expect(WebSocketClient.getInstance()).andReturn(wsClient);
replayAll();
BufferedReader reader;
// Register
try (InputStream is = new ByteArrayInputStream(regData.getBytes())) {
reader = new BufferedReader(new InputStreamReader(is));
}
Mockito.when(request.getReader()).thenReturn(reader);
Mockito.when(request.getHeader("Register-lsp")).thenReturn("true");
cut.doPost(request, response);
Map<String, LSPDestination> reg = TestUtils.getInternalState(cut, "lspDestPath");
assertTrue("No listener registered", !reg.entrySet().isEmpty());
assertNotNull("Wrong registration key", reg.get("/myProj/myModule/:aLang/"));
assertNotNull("Wrong registration url", reg.get("/myProj/myModule/:aLang/").getWebSocketClient());
// Unregister
try (InputStream is = new ByteArrayInputStream(regData.getBytes())) {
reader = new BufferedReader(new InputStreamReader(is));
}
Mockito.when(request.getReader()).thenReturn(reader);
Mockito.when(request.getHeader("Register-lsp")).thenReturn("false");
cut.doPost(request, response);
reg = TestUtils.getInternalState(cut, "lspDestPath");
assertTrue("Listener unregistered", reg.entrySet().isEmpty());
}
示例8: setup
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setup() {
herder = new StandaloneHerder(worker, WORKER_ID, statusBackingStore, new MemoryConfigBackingStore());
plugins = PowerMock.createMock(Plugins.class);
pluginLoader = PowerMock.createMock(PluginClassLoader.class);
delegatingLoader = PowerMock.createMock(DelegatingClassLoader.class);
PowerMock.mockStatic(Plugins.class);
}
示例9: setUp
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
PowerMock.mockStatic(RestServer.class,
RestServer.class.getMethod("httpRequest", String.class, String.class, Object.class, TypeReference.class));
plugins = PowerMock.createMock(Plugins.class);
herder = PowerMock.createMock(AbstractHerder.class);
connectorPluginsResource = new ConnectorPluginsResource(herder);
}
示例10: setUp
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
PowerMock.mockStatic(LocalUser.class);
localUserMock = PowerMock.createNiceMock(LocalUser.class);
expect(LocalUser.getInstance()).andReturn(localUserMock).anyTimes();
expect(localUserMock.getUserId()).andReturn(USER_ID).anyTimes();
exporterMock = PowerMock.createNiceMock(FileExporterImpl.class);
PowerMock.expectNew(FileExporterImpl.class).andReturn(exporterMock).anyTimes();
dummyZip = new ProjectSourceZip(DUMMY_ZIP_FILENAME, new byte[] {}, 2);
dummyZipWithTitle = new ProjectSourceZip(DUMMY_ZIP_FILENAME_WITH_TITLE, new byte[] {}, 2);
dummyApk = new RawFile(DUMMY_APK_FILENAME, new byte[] {});
dummyFile = new RawFile(DUMMY_FILENAME, new byte[] {});
}
示例11: setUp
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
helper.setUp();
storageIo = StorageIoInstanceHolder.INSTANCE;
PowerMock.mockStatic(LocalUser.class);
localUserMock = PowerMock.createMock(LocalUser.class);
expect(localUserMock.getSessionId()).andReturn("test-session").anyTimes();
localUserMock.setSessionId("test-session");
expectLastCall().times(1);
expect(LocalUser.getInstance()).andReturn(localUserMock).anyTimes();
localUserMock.set(new User("1", "NonSuch", "NoName", null, 0, false, false, 0, null));
expectLastCall().anyTimes();
KeyczarEncryptor.rootPath.setForTest(KEYSTORE_ROOT_PATH);
}
示例12: setup
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {
PowerMock.mockStatic(ConfigurationManager.class);
}
示例13: setUp
import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setUp() throws NoSuchMethodException {
PowerMock.mockStatic(RestServer.class,
RestServer.class.getMethod("httpRequest", String.class, String.class, Object.class, TypeReference.class));
connectorsResource = new ConnectorsResource(herder);
}