本文整理汇总了Java中org.powermock.api.mockito.PowerMockito.mockStatic方法的典型用法代码示例。如果您正苦于以下问题:Java PowerMockito.mockStatic方法的具体用法?Java PowerMockito.mockStatic怎么用?Java PowerMockito.mockStatic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.powermock.api.mockito.PowerMockito
的用法示例。
在下文中一共展示了PowerMockito.mockStatic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDataTypeShouldReturnPDXRegistryClosedForEnumTypeWhenCacheIsClosed
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void getDataTypeShouldReturnPDXRegistryClosedForEnumTypeWhenCacheIsClosed()
throws IOException {
int someArrayLength = 1;
PowerMockito.mockStatic(GemFireCacheImpl.class);
when(GemFireCacheImpl
.getForPdx("PDX registry is unavailable because the Cache has been closed."))
.thenThrow(CacheClosedException.class);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
out.writeByte(DSCODE.PDX_ENUM);
out.writeInt(someArrayLength);
byte[] bytes = baos.toByteArray();
String type = DataType.getDataType(bytes);
assertThat(type).isEqualTo("PdxRegistry/java.lang.Enum:PdxRegistryClosed");
}
示例2: mockUriParse
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
private void mockUriParse() {
PowerMockito.mockStatic(Uri.class);
PowerMockito.when(Uri.parse(anyString())).then(new Answer<Uri>() {
@Override
public Uri answer(InvocationOnMock invocation) throws Throwable {
return mockUri((String) invocation.getArguments()[0]);
}
});
}
示例3: testreadAll
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
public void testreadAll() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(ENTITY_NAME , entityName);
innerMap.put(INDEXED , true);
/*Map<String , Object> payLoad = new HashMap<>();
payLoad.put(JsonKey.USER_ID , "usergt78y4ry8");
payLoad.put(JsonKey.ID , "ggudy8d8ydyy8ddy9");
innerMap.put(PAYLOAD , payLoad);*/
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/object/read/list").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例4: P2SHScript
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@PrepareForTest({ ScriptBuilder.class })
@Test
public void P2SHScript() {
final List<Integer> calls = new ArrayList<>();
PowerMockito.mockStatic(ScriptBuilder.class);
PowerMockito.when(ScriptBuilder.createP2SHOutputScript(any(int.class), any(List.class))).thenAnswer((invocationOnMock) -> {
calls.add(0);
int numberOfSignaturesRequired = invocationOnMock.getArgumentAt(0, int.class);
List<BtcECKey> publicKeys = invocationOnMock.getArgumentAt(1, List.class);
Assert.assertEquals(4, numberOfSignaturesRequired);
Assert.assertEquals(6, publicKeys.size());
for (int i = 0; i < sortedPublicKeys.size();i ++) {
Assert.assertTrue(Arrays.equals(sortedPublicKeys.get(i).getPubKey(), publicKeys.get(i).getPubKey()));
}
return new Script(new byte[]{(byte)0xaa});
});
Assert.assertTrue(Arrays.equals(federation.getP2SHScript().getProgram(), new byte[]{(byte) 0xaa}));
Assert.assertTrue(Arrays.equals(federation.getP2SHScript().getProgram(), new byte[]{(byte) 0xaa}));
// Make sure the script creation happens only once
Assert.assertEquals(1, calls.size());
}
示例5: testchangePassword
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testchangePassword() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.PASSWORD , "password");
innerMap.put(JsonKey.NEW_PASSWORD , "newpssword");
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/user/changepassword").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例6: setup
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void setup() throws IOException, InterruptedException {
// Prepare site.
when(envVarsMock.get("JIRA_SITE")).thenReturn("LOCAL");
when(envVarsMock.get("BUILD_URL")).thenReturn("http://localhost:8080/jira-testing/job/01");
PowerMockito.mockStatic(Site.class);
Mockito.when(Site.get(any())).thenReturn(siteMock);
when(siteMock.getService()).thenReturn(jiraServiceMock);
when(runMock.getCauses()).thenReturn(null);
when(taskListenerMock.getLogger()).thenReturn(printStreamMock);
doNothing().when(printStreamMock).println();
final ResponseDataBuilder<Object> builder = ResponseData.builder();
when(jiraServiceMock.addComment(anyString(), anyString()))
.thenReturn(builder.successful(true).code(200).message("Success").build());
when(contextMock.get(Run.class)).thenReturn(runMock);
when(contextMock.get(TaskListener.class)).thenReturn(taskListenerMock);
when(contextMock.get(EnvVars.class)).thenReturn(envVarsMock);
}
示例7: testcompositeSearch
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testcompositeSearch() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.ORG_NAME , "org123");
innerMap.put(JsonKey.OBJECT_TYPE, JsonKey.ORGANISATION);
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/search/compositesearch").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例8: setup
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void setup() {
// Prepare site.
when(envVarsMock.get("JIRA_SITE")).thenReturn("LOCAL");
when(envVarsMock.get("BUILD_URL")).thenReturn("http://localhost:8080/jira-testing/job/01");
PowerMockito.mockStatic(Site.class);
Mockito.when(Site.get(any())).thenReturn(siteMock);
when(siteMock.getService()).thenReturn(jiraServiceMock);
stepExecution = spy(new GetCommentsStep.Execution());
when(runMock.getCauses()).thenReturn(null);
when(taskListenerMock.getLogger()).thenReturn(printStreamMock);
doNothing().when(printStreamMock).println();
final ResponseDataBuilder<Comments> builder = ResponseData.builder();
when(jiraServiceMock.getComments(anyString())).thenReturn(builder.successful(true).code(200).message("Success").build());
stepExecution.listener = taskListenerMock;
stepExecution.envVars = envVarsMock;
stepExecution.run = runMock;
doReturn(jiraServiceMock).when(stepExecution).getJiraService(any());
}
示例9: setUp
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void setUp() {
mClock = mock(SystemClock.class);
PowerMockito.mockStatic(SystemClock.class);
PowerMockito.when(SystemClock.get()).thenReturn(mClock);
mBackgroundExecutor = new TestExecutorService(new FakeClock());
mDiskTrimmableRegistry = mock(DiskTrimmableRegistry.class);
mCacheEventListener = mock(CacheEventListener.class);
mCacheEventListenerInOrder = inOrder(mCacheEventListener);
// we know the directory will be this
mCacheDirectory = new File(RuntimeEnvironment.application.getCacheDir(), CACHE_TYPE);
mCacheDirectory.mkdirs();
if (!mCacheDirectory.exists()) {
throw new RuntimeException(
String.format(
(Locale) null,
"Cannot create cache dir: %s: directory %s",
mCacheDirectory.getAbsolutePath(),
mCacheDirectory.exists() ? "already exists" : "does not exist"));
}
mStorage = createDiskStorage(TESTCACHE_VERSION_START_OF_VERSIONING);
mCache = createDiskCache(mStorage, false);
mCache.clearAll();
reset(mCacheEventListener);
verify(mDiskTrimmableRegistry).registerDiskTrimmable(mCache);
}
示例10: setUp
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
//Tool Stubbs
doReturn(0).when(tool).getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
doReturn(Material.DIAMOND_PICKAXE).when(tool).getType();
doReturn((short) 0).when(tool).getDurability();
doReturn(true).when(tool).hasItemMeta();
doReturn(itemMeta).when(tool).getItemMeta();
//inventory Stubs
doReturn(tool).when(inventory).getItemInMainHand();
//playter stubs
doReturn(inventory).when(player).getInventory();
doReturn(world).when(player).getWorld();
//block stubs
doReturn(new Location(world, 2, 2, 2)).when(block).getLocation();
doReturn(Material.EMERALD_ORE).when(block).getType();
//world stubbs
doReturn(block).when(world).getBlockAt(any());
//itemmeta stubbs
doReturn(true).when(itemMeta).hasLore();
//bukkit Stub
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
}
示例11: fileSystemGetFailureThrowsException
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test(expected = CircusTrainException.class)
public void fileSystemGetFailureThrowsException() throws Exception {
PowerMockito.mockStatic(FileSystem.class);
Configuration conf = null;
when(FileSystem.get(conf)).thenThrow(IOException.class);
String credentialProvider = "test.json";
temporaryFolder.newFile(credentialProvider);
credentialProvider = temporaryFolder.getRoot() + "/" + credentialProvider;
GCPSecurity security = new GCPSecurity();
security.setCredentialProvider(credentialProvider);
GCPCredentialConfigurer configurer = new GCPCredentialConfigurer(conf, security);
configurer.configureCredentials();
}
示例12: testunBlockUser
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testunBlockUser() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/user/unblock").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例13: testLoadNativeLIbrariesEnvNotSupported
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testLoadNativeLIbrariesEnvNotSupported() {
PowerMockito.mockStatic(NativesLoader.class);
PowerMockito.when(NativesLoader.isSupportedEnvironment()).thenReturn(false);
assertFalse(TinyBFactory.loadNativeLibraries());
PowerMockito.verifyStatic(times(1));
}
示例14: mainPrintUsageWithoutUserTest
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void mainPrintUsageWithoutUserTest() throws Exception {
PowerMockito.mockStatic(System.class);
Main.main(new String[]{"-nifi","http://localhost:8080/nifi-api","-branch","\"root>N2\"","-conf","adr","-m","undeploy","-password","pass"});
PowerMockito.verifyStatic();
System.exit(1);
}
示例15: init
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void init() {
PowerMockito.mockStatic(CoachmarkView_.class);
PowerMockito.when(CoachmarkView_.build(null)).thenReturn(mCoachmarkViewMock);
mBuilderToTest = new CoachmarkViewBuilder(null);
}