本文整理汇总了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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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();
}
示例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");
}
示例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;
}
示例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));
}
示例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();
}
示例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));
}
示例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));
}
示例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();
}
示例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;
}