当前位置: 首页>>代码示例>>Java>>正文


Java PowerMockito.mock方法代码示例

本文整理汇总了Java中org.powermock.api.mockito.PowerMockito.mock方法的典型用法代码示例。如果您正苦于以下问题:Java PowerMockito.mock方法的具体用法?Java PowerMockito.mock怎么用?Java PowerMockito.mock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.powermock.api.mockito.PowerMockito的用法示例。


在下文中一共展示了PowerMockito.mock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRemoveNotificationListener_ListenerDoesntExist

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testRemoveNotificationListener_ListenerDoesntExist() throws Exception {
    String auth = "xxxx";
    PlatformServiceImpl mockPlatformService = PowerMockito.mock(PlatformServiceImpl.class);
    PusherNotificationServiceImpl mockPusherNotificationService = PowerMockito.mock(PusherNotificationServiceImpl.class);

    PowerMockito.whenNew(PlatformServiceImpl.class).withParameterTypes(Config.class).withArguments(Mockito.isA(Config.class)).thenReturn(mockPlatformService);
    Mockito.when(mockPlatformService.getAuth(Mockito.isA(GetPlatformAuthRequestVO.class))).thenReturn(getPlatformAuthResponseVO);
    PowerMockito.whenNew(PusherNotificationServiceImpl.class).withParameterTypes(Notification.class).withArguments(Mockito.isA(Notification.class))
            .thenReturn(mockPusherNotificationService);
    Mockito.when(mockPusherNotificationService.initializeNotificationService(Mockito.isA(GetPlatformAuthDetailsResponseVO.class))).thenReturn(true);

    boolean result = notificationsAsyncService.initNotificationsServiceAsync(auth).get();
    assertThat(result).isTrue();

    notificationsAsyncService.removeNotificationListenerAsync(mockNotificationListener);

    PowerMockito.verifyNew(PlatformServiceImpl.class).withArguments(Mockito.isA(Config.class));
    Mockito.verify(mockPlatformService, Mockito.times(1)).getAuth(Mockito.isA(GetPlatformAuthRequestVO.class));
    PowerMockito.verifyNew(PusherNotificationServiceImpl.class).withArguments(Mockito.isA(Notification.class));
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:22,代码来源:NotificationsAsyncServiceTest.java

示例2: testInitNotificationsService_SuccessInitializedAlready

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testInitNotificationsService_SuccessInitializedAlready() throws Exception {
    String auth = "xxxx";
    PlatformServiceImpl mockPlatformService = PowerMockito.mock(PlatformServiceImpl.class);
    PusherNotificationServiceImpl mockPusherNotificationService = PowerMockito.mock(PusherNotificationServiceImpl.class);

    PowerMockito.whenNew(PlatformServiceImpl.class).withParameterTypes(Config.class).withArguments(Mockito.isA(Config.class)).thenReturn(mockPlatformService);
    Mockito.when(mockPlatformService.getAuth(Mockito.isA(GetPlatformAuthRequestVO.class))).thenReturn(getPlatformAuthResponseVO);
    PowerMockito.whenNew(PusherNotificationServiceImpl.class).withParameterTypes(Notification.class).withArguments(Mockito.isA(Notification.class))
            .thenReturn(mockPusherNotificationService);
    Mockito.when(mockPusherNotificationService.initializeNotificationService(Mockito.isA(GetPlatformAuthDetailsResponseVO.class))).thenReturn(true);

    boolean result = notificationsAsyncService.initNotificationsServiceAsync(auth).get();
    assertThat(result).isTrue();

    result = notificationsAsyncService.initNotificationsServiceAsync(auth).get();
    assertThat(result).isTrue();

    PowerMockito.verifyNew(PlatformServiceImpl.class).withArguments(Mockito.isA(Config.class));
    PowerMockito.verifyNew(PlatformServiceImpl.class).withArguments(Mockito.isA(Config.class));
    Mockito.verify(mockPlatformService, Mockito.times(2)).getAuth(Mockito.isA(GetPlatformAuthRequestVO.class));
    PowerMockito.verifyNew(PusherNotificationServiceImpl.class).withArguments(Mockito.isA(Notification.class));
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:24,代码来源:NotificationsAsyncServiceTest.java

示例3: getStopsForLineTest

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void getStopsForLineTest() throws Exception {
    /* Mock the HTTP call */
    URL mockURL = PowerMockito.mock(URL.class);
    PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(mockURL);
    PowerMockito.when(mockURL.openStream())
            .thenReturn(getClass().getResourceAsStream("instant_V2_stops_line.txt"));

    /* List stops and verify some values */
    List<Stop> stops = new UraClient("mocked").forLines("33").getStops();
    assertThat(stops, hasSize(47));
    assertThat(stops.get(0).getId(), is("100000"));
    assertThat(stops.get(1).getName(), is("Kuckelkorn"));
    assertThat(stops.get(2).getState(), is(0));;
    assertThat(stops.get(3).getLatitude(), is(50.7690688));
    assertThat(stops.get(4).getIndicator(), is("H.1"));
    assertThat(stops.get(5).getLongitude(), is(6.2314072));
}
 
开发者ID:stklcode,项目名称:juraclient,代码行数:19,代码来源:UraClientTest.java

示例4: testGetEvent_ResponseIsNull

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testGetEvent_ResponseIsNull() throws Exception {
    GetEventRequestVO getEventRequestVO = ImmutableGetEventRequestVO.builder()
            .setAppId("eventId")
            .setEventId("eventId")
            .build();

    GetEventResponseVO returnedGetEventResponseVO = null;

    JsonRpcUtils mockJsonRpcUtils = PowerMockito.mock(JsonRpcUtils.class);
    PowerMockito.whenNew(JsonRpcUtils.class).withNoArguments().thenReturn(mockJsonRpcUtils);
    Mockito.when(mockJsonRpcUtils.sendJsonRpcRequest(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.isA(Map.class))).thenReturn(returnedGetEventResponseVO);

    eventService = new EventsServiceImpl(enjinConfig);
    GetEventResponseVO[] getEventResponseVO = eventService.getEvent(getEventRequestVO);
    assertThat(getEventResponseVO).isNull();

    PowerMockito.verifyNew(JsonRpcUtils.class, Mockito.times(1)).withNoArguments();
    Mockito.verify(mockJsonRpcUtils, Mockito.times(1)).sendJsonRpcRequest(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.isA(Map.class));
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:22,代码来源:EventsServiceTest.java

示例5: testInitNotificationsService_FailedToInitialize

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testInitNotificationsService_FailedToInitialize() throws Exception {
    String auth = "xxxx";
    PlatformServiceImpl mockPlatformService = PowerMockito.mock(PlatformServiceImpl.class);
    PusherNotificationServiceImpl mockPusherNotificationService = PowerMockito.mock(PusherNotificationServiceImpl.class);

    PowerMockito.whenNew(PlatformServiceImpl.class).withParameterTypes(Config.class).withArguments(Mockito.isA(Config.class)).thenReturn(mockPlatformService);
    Mockito.when(mockPlatformService.getAuth(Mockito.isA(GetPlatformAuthRequestVO.class))).thenReturn(getPlatformAuthResponseVO);
    PowerMockito.whenNew(PusherNotificationServiceImpl.class).withArguments(Mockito.isA(Notification.class)).thenReturn(mockPusherNotificationService);
    Mockito.when(mockPusherNotificationService.initializeNotificationService(Mockito.isA(GetPlatformAuthDetailsResponseVO.class))).thenReturn(false);

    boolean result = notificationsService.initNotificationsService(auth);
    assertThat(result).isFalse();

    PowerMockito.verifyNew(PlatformServiceImpl.class).withArguments(Mockito.isA(Config.class));
    Mockito.verify(mockPlatformService, Mockito.times(1)).getAuth(Mockito.isA(GetPlatformAuthRequestVO.class));
    PowerMockito.verifyNew(PusherNotificationServiceImpl.class).withArguments(Mockito.isA(Notification.class));
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:19,代码来源:NotificationsServiceTest.java

示例6: testGetTransactionRequest_ResponseIsNull

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "serial" })
@Test
public void testGetTransactionRequest_ResponseIsNull() throws Exception {

    GetTransactionRequestRequestVO getTransactionRequestRequestVO = ImmutableGetTransactionRequestRequestVO.builder()
            .setAuth("xxxxxxxx")
            .setIdentityMap(new HashMap<String, Object>() {{
                put("identity_id", "12345");
            }})
            .setAppId("123")
            .setRecipientMap(new HashMap<String, Object>() {{
                put("identity_id", "12345");
            }})
            .setType("buy")
            .setAfterTxrId("1234567")
            .setLimit("50")
            .setCurrency("23456")
            .build();

    GetTransactionRequestResponseVO returnedGetTransactionRequestResponseVO = null;

    JsonRpcUtils mockJsonRpcUtils = PowerMockito.mock(JsonRpcUtils.class);
    PowerMockito.whenNew(JsonRpcUtils.class).withNoArguments().thenReturn(mockJsonRpcUtils);
    Mockito.when(mockJsonRpcUtils.sendJsonRpcRequest(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.isA(Map.class))).thenReturn(returnedGetTransactionRequestResponseVO);

    transactionRequestsService = new TransactionRequestsServiceImpl(enjinConfig);
    GetTransactionRequestResponseVO[] getTransactionRequestResponseVO = transactionRequestsService.getTransactionRequest(getTransactionRequestRequestVO);
    assertThat(getTransactionRequestResponseVO).isNull();

    PowerMockito.verifyNew(JsonRpcUtils.class, Mockito.times(1)).withNoArguments();
    Mockito.verify(mockJsonRpcUtils, Mockito.times(1)).sendJsonRpcRequest(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.isA(Map.class));
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:33,代码来源:TransactionRequestsServiceTest.java

示例7: testConvertObjectToJson_JsonObjectIsNull

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testConvertObjectToJson_JsonObjectIsNull() {
    Object jsonObject = null;
    Gson mockGson = PowerMockito.mock(Gson.class);

    String jsonResponse = JsonUtils.convertObjectToJson(mockGson, jsonObject);
    assertThat(jsonResponse).isNull();
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:9,代码来源:JsonUtilsTest.java

示例8: init

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void init() throws InterruptedException, IOException {
    PowerMockito.mockStatic(Runtime.class);
    this.runtimeMock = PowerMockito.mock(Runtime.class);
    this.processMock = PowerMockito.mock(Process.class);
    PowerMockito.when(this.processMock.waitFor()).thenReturn(0);
    Mockito.when(Runtime.getRuntime()).thenReturn(this.runtimeMock);

    this.homeDirectory = this.testFolder.newFolder("fakeHomeDir");

    if (!this.homeDirectory.exists()) {
        Assert.fail("Failed to create new folder for tests");
    }

    this.regularFile = new File(this.homeDirectory, this.PID_FILE);
    if (this.regularFile.exists()) {
        boolean isDeleted = this.regularFile.delete();
        Assert.assertTrue(isDeleted);
    }

    this.regularFile = new File(this.homeDirectory, this.PID_FILE);

    if (!this.regularFile.createNewFile() || !this.regularFile.exists()) {
        Assert.fail("Failed to create new file for test");
    }

    this.cmdOutput = new ArrayList<>();
    this.cmdOutput.add(" PID TTY STAT TIME COMMAND");
    this.cmdOutput.add(" 10 ? Ss 0:07 /test/test");
    this.cmdOutput.add(" 9990 ? Ss 0:07 /test/java");
    this.cmdOutput.add(" " + this.oldProcessId + " ? Ss 0:07 /osc/java");
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:33,代码来源:ServerUtilTest.java

示例9: setup

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void setup() {
    mockStatic(RealmLog.class);
    mockStatic(Realm.class);

    Realm mockRealm = PowerMockito.mock(Realm.class);

    when(Realm.getDefaultInstance()).thenReturn(mockRealm);
    this.mockRealm = mockRealm;
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:11,代码来源:SimpleRealmTest.java

示例10: testInitNotificationsService_GetPlatformAuthResponseVOIsNull

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testInitNotificationsService_GetPlatformAuthResponseVOIsNull() throws Exception {
    GetPlatformAuthResponseVO tempGetPlatformAuthResponseVO = null;
    String auth = "xxxx";
    PlatformServiceImpl mockPlatformService = PowerMockito.mock(PlatformServiceImpl.class);

    PowerMockito.whenNew(PlatformServiceImpl.class).withParameterTypes(Config.class).withArguments(Mockito.isA(Config.class)).thenReturn(mockPlatformService);
    Mockito.when(mockPlatformService.getAuth(Mockito.isA(GetPlatformAuthRequestVO.class))).thenReturn(tempGetPlatformAuthResponseVO);

    boolean result = notificationsAsyncService.initNotificationsServiceAsync(auth).get();
    assertThat(result).isFalse();

    PowerMockito.verifyNew(PlatformServiceImpl.class).withArguments(Mockito.isA(Config.class));
    Mockito.verify(mockPlatformService, Mockito.times(1)).getAuth(Mockito.isA(GetPlatformAuthRequestVO.class));
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:16,代码来源:NotificationsAsyncServiceTest.java

示例11: testConvertJsonToObject_JsonStringIsEmpty

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testConvertJsonToObject_JsonStringIsEmpty() {
    String jsonString = "";
    Class<?> responseClass = GetEventResponseVO.class;
    Gson mockGson = PowerMockito.mock(Gson.class);
    Object responseObject = JsonUtils.convertJsonToObject(mockGson, jsonString, responseClass);
    assertThat(responseObject).isNull();
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:9,代码来源:JsonUtilsTest.java

示例12: testCreateTransactionRequest_Success

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testCreateTransactionRequest_Success() throws Exception {
    Map<String, Object> listIdentityMap = new HashMap<>();
    listIdentityMap.put("player_name", "Joe");
    Map<String, Object> listRecipientMap = new HashMap<>();
    listRecipientMap.put("player_name", "Alice");
    Map<String, Object> createValueMap = new HashMap<>();
    createValueMap.put("ENJ", "3000000000000000000");

    CreateTransactionRequestRequestVO createTransactionRequestRequestVO = ImmutableCreateTransactionRequestRequestVO.builder()
            .setAuth("xxxxxxxx")
            .setIdentityMap(listIdentityMap)
            .setRecipientMap(listRecipientMap)
            .setType("send")
            .setIcon("https://enjincoin.io/images/bubble.png")
            .setTitle("Mineplex: /transfer alice 3 ENJ")
            .setValueMap(createValueMap)
            .build();

    CreateTransactionRequestResponseVO returnedCreateTransactionRequestResponseVO = ImmutableCreateTransactionRequestResponseVO.builder().build();

    JsonRpcUtils mockJsonRpcUtils = PowerMockito.mock(JsonRpcUtils.class);
    PowerMockito.whenNew(JsonRpcUtils.class).withNoArguments().thenReturn(mockJsonRpcUtils);
    Mockito.when(mockJsonRpcUtils.sendJsonRpcRequest(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.isA(Map.class))).thenReturn(returnedCreateTransactionRequestResponseVO);

    transactionRequestsAsyncService = new TransactionRequestsAsyncServiceImpl(enjinConfig);
    CompletableFuture<CreateTransactionRequestResponseVO> createTransactionRequestResponseCompletableFutureVO = transactionRequestsAsyncService.createTransactionRequestAsync(createTransactionRequestRequestVO);
    assertThat(createTransactionRequestResponseCompletableFutureVO).isNotNull();
    CreateTransactionRequestResponseVO createTransactionRequestResponseVO = createTransactionRequestResponseCompletableFutureVO.get();
    assertThat(createTransactionRequestResponseVO).isNotNull();

    PowerMockito.verifyNew(JsonRpcUtils.class, Mockito.times(1)).withNoArguments();
    Mockito.verify(mockJsonRpcUtils, Mockito.times(1)).sendJsonRpcRequest(Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.isA(Map.class));
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:36,代码来源:TransactionRequestsAsyncServiceTest.java

示例13: testIgnorePublicationFalseWrongGroup

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testIgnorePublicationFalseWrongGroup() throws Exception {
  // setup mock for participant data
  ParticipantBuiltinTopicData participantBuiltinTopicData = mock(ParticipantBuiltinTopicData.class);
  PowerMockito.whenNew(ParticipantBuiltinTopicData.class).withAnyArguments().thenReturn(participantBuiltinTopicData);

  PowerMockito.mockStatic(PropertyQosPolicyHelper.class);
  when(PropertyQosPolicyHelper.lookup_property(
      any(), anyString())//eq("rti.routing_service.group_name"))
  ).thenReturn(new Property_t("rti.routing_service.group_name", "", false));

  // setup mock for topic helper
  PowerMockito.mockStatic(BuiltinTopicHelper.class);
  when(BuiltinTopicHelper.getParticipantBuiltinTopicData(
      any(DomainParticipant.class), any(BuiltinTopicKey_t.class))
  ).thenReturn(participantBuiltinTopicData);

  // setup mock for publication topic data
  PublicationBuiltinTopicData data = mock(PublicationBuiltinTopicData.class);
  BuiltinTopicKey_t key = PowerMockito.mock(BuiltinTopicKey_t.class);
  Whitebox.setInternalState(data, "participant_key", key);

  // setup mock for instance handle
  InstanceHandle_t instanceHandle = mock(InstanceHandle_t.class);

  // call ignore publication
  assertFalse(filter.ignorePublication(domainParticipant, instanceHandle, data));
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:29,代码来源:RoutingServiceGroupEntitiesFilterTest.java

示例14: testLoadWithSupplier_FileDoesntExistSuccess

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testLoadWithSupplier_FileDoesntExistSuccess() throws Exception {
    Class configClass = JsonConfig.class;
    Supplier supplier  = ()-> new JsonConfig();

    File mockFile = PowerMockito.mock(File.class);
    FileWriter mockFileWriter = PowerMockito.mock(FileWriter.class);
    FileWriter spyFileWriter = Mockito.spy(mockFileWriter);

    Mockito.when(mockFile.exists()).thenReturn(false);
    PowerMockito.whenNew(FileWriter.class).withParameterTypes(File.class).withArguments(mockFile).thenReturn(mockFileWriter);
    Mockito.when(mockFile.getParentFile()).thenReturn(null);
    Mockito.when(mockFile.exists()).thenReturn(false);
    Mockito.when(mockFile.createNewFile()).thenReturn(true);
    Mockito.doNothing().when(spyFileWriter).write(Mockito.anyString());
    Mockito.doNothing().when(spyFileWriter).close();

    JsonConfig response = JsonConfig.load(mockFile, configClass, supplier);
    assertThat(response).isNotNull();

    Mockito.verify(mockFile, Mockito.times(2)).exists();
    PowerMockito.verifyNew(FileWriter.class, Mockito.times(1)).withArguments(Mockito.isA(File.class));
    Mockito.verify(mockFile, Mockito.times(1)).getParentFile();
    Mockito.verify(mockFile, Mockito.times(1)).createNewFile();
    Mockito.verify(mockFileWriter, Mockito.times(1)).write(Mockito.anyString());
    Mockito.verify(mockFileWriter, Mockito.times(2)).close();
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:29,代码来源:JsonConfigTest.java

示例15: setup

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void setup() {
    mockStatic(RealmLog.class);
    mockStatic(Realm.class);

    Realm mockRealm = PowerMockito.mock(Realm.class);

    when(Realm.getDefaultInstance()).thenReturn(mockRealm);

    this.mockRealm = mockRealm;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:ExampleRealmTest.java


注:本文中的org.powermock.api.mockito.PowerMockito.mock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。