當前位置: 首頁>>代碼示例>>Java>>正文


Java PowerMock.mockStatic方法代碼示例

本文整理匯總了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();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:18,代碼來源:DistributedHerderTest.java

示例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();
}
 
開發者ID:gazbert,項目名稱:bxbot-ui-server,代碼行數:18,代碼來源:TestJwtUserDetailsService.java

示例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);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:17,代碼來源:WorkerTest.java

示例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);
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:17,代碼來源:OdeAuthFilterTest.java

示例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());
}
 
開發者ID:SAP,項目名稱:cloud-language-servers-container,代碼行數:36,代碼來源:WSSynchronizationTest.java

示例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());
}
 
開發者ID:SAP,項目名稱:cloud-language-servers-container,代碼行數:35,代碼來源:WSSynchronizationTest.java

示例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());

}
 
開發者ID:SAP,項目名稱:cloud-language-servers-container,代碼行數:36,代碼來源:WSSynchronizationTest.java

示例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);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:9,代碼來源:StandaloneHerderTest.java

示例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);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:10,代碼來源:ConnectorPluginsResourceTest.java

示例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[] {});
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:15,代碼來源:DownloadServletTest.java

示例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);
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:16,代碼來源:ProjectServiceTest.java

示例12: setup

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {
    PowerMock.mockStatic(ConfigurationManager.class);
}
 
開發者ID:gazbert,項目名稱:bxbot-ui-server,代碼行數:5,代碼來源:TestBotConfigRepository.java

示例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);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:7,代碼來源:ConnectorsResourceTest.java


注:本文中的org.powermock.api.easymock.PowerMock.mockStatic方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。