本文整理了Java中org.powermock.api.mockito.PowerMockito.method()
方法的一些代码示例,展示了PowerMockito.method()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PowerMockito.method()
方法的具体详情如下:
包路径:org.powermock.api.mockito.PowerMockito
类名称:PowerMockito
方法名:method
暂无
代码示例来源:origin: apache/kylin
@Before
public void setup() throws SQLException {
connection = mock(Connection.class);
dbmd = mock(DatabaseMetaData.class);
jdbcMetadata = mock(DefaultJdbcMetadata.class);
PowerMockito.stub(PowerMockito.method(SqlUtil.class, "getConnection")).toReturn(connection);
PowerMockito.mockStatic(JdbcMetadataFactory.class);
when(JdbcMetadataFactory.getJdbcMetadata(anyString(), any(DBConnConf.class))).thenReturn(jdbcMetadata);
when(connection.getMetaData()).thenReturn(dbmd);
jdbcExplorer = spy(JdbcExplorer.class);
}
代码示例来源:origin: facebook/facebook-android-sdk
@Before
public void before() throws Exception {
stub(PowerMockito.method(Utility.class, "awaitGetGraphMeRequestWithCache")).toReturn(
new JSONObject().put("id", "1000"));
}
代码示例来源:origin: facebook/facebook-android-sdk
@Before
public void before() throws Exception {
stub(PowerMockito.method(Utility.class, "awaitGetGraphMeRequestWithCache")).toReturn(
new JSONObject().put("id", "1000"));
}
代码示例来源:origin: facebook/facebook-android-sdk
@Before
public void before() throws Exception {
mockStatic(FacebookSdk.class);
stub(method(AccessToken.class, "getCurrentAccessToken")).toReturn(null);
stub(method(AccessToken.class, "setCurrentAccessToken")).toReturn(null);
stub(method(Profile.class, "fetchProfileForCurrentAccessToken")).toReturn(null);
when(FacebookSdk.isInitialized()).thenReturn(true);
when(FacebookSdk.getApplicationId()).thenReturn(MOCK_APP_ID);
when(FacebookSdk.getApplicationContext()).thenReturn(mockApplicationContext);
when(FacebookSdk.getExecutor()).thenReturn(threadExecutor);
when(mockFragment.getActivity()).thenReturn(mockFragmentActivity);
when(mockActivity.getApplicationContext()).thenReturn(mockApplicationContext);
when(FacebookSdk.getApplicationContext()
.getSharedPreferences(anyString(), anyInt())).thenReturn(mockSharedPreferences);
when(mockSharedPreferences.edit()).thenReturn(mockEditor);
when(mockEditor.putBoolean(anyString(), anyBoolean())).thenReturn(mockEditor);
// We use mocks rather than RobolectricPackageManager because it's simpler to not
// have to specify Intents. Default to resolving all intents to something.
ResolveInfo resolveInfo = new ResolveInfo();
when(mockApplicationContext.getPackageManager()).thenReturn(mockPackageManager);
when(mockPackageManager.resolveActivity(any(Intent.class), anyInt()))
.thenReturn(resolveInfo);
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testLogInWithReadAndAccessTokenCreatesReauthRequest() {
AccessToken accessToken = createAccessToken();
stub(method(AccessToken.class, "getCurrentAccessToken")).toReturn(accessToken);
LoginManager loginManager = new LoginManager();
loginManager.logInWithReadPermissions(mockActivity,
Arrays.asList("public_profile", "user_friends"));
int loginRequestCode = CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
verify(mockActivity, times(1)).startActivityForResult(any(Intent.class),
eq(loginRequestCode));
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testLogInWithPublishAndAccessTokenCreatesReauthRequest() {
AccessToken accessToken = createAccessToken();
stub(method(AccessToken.class, "getCurrentAccessToken")).toReturn(accessToken);
LoginManager loginManager = new LoginManager();
loginManager.logInWithPublishPermissions(mockActivity,
Arrays.asList("publish_actions", "publish_stream"));
int loginRequestCode = CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
verify(mockActivity, times(1)).startActivityForResult(any(Intent.class),
eq(loginRequestCode));
}
代码示例来源:origin: facebook/facebook-android-sdk
@Before
public void before() throws Exception {
mockStatic(FacebookSdk.class);
sharedPreferences = RuntimeEnvironment.application.getSharedPreferences(
AccessTokenManager.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
sharedPreferences.edit().clear().commit();
cachingStrategyFactory = mock(
AccessTokenCache.SharedPreferencesTokenCachingStrategyFactory.class);
when(cachingStrategyFactory.create()).thenReturn(cachingStrategy);
stub(PowerMockito.method(Utility.class, "awaitGetGraphMeRequestWithCache")).toReturn(
new JSONObject().put("id", "1000"));
}
代码示例来源:origin: paypal/PayPal-Java-SDK
@BeforeMethod
public void setUp() throws Exception {
InputStream testClientCertStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("testClientCert.crt");
stub(PowerMockito.method(SSLUtil.class, "downloadCertificateFromPath", String.class, Map.class)).toReturn(testClientCertStream);
// Settings some default values before each methods
headers = new HashMap<String, String>();
configs = new HashMap<String, String>();
apiContext = new APIContext();
//configs.put(Constants.PAYPAL_TRUST_CERT_URL, "DigiCertSHA2ExtendedValidationServerCA.crt");
configs.put(Constants.PAYPAL_WEBHOOK_ID, "96605875FF6516633");
apiContext.setConfigurationMap(configs);
headers.put(Constants.PAYPAL_HEADER_CERT_URL, "https://api.sandbox.paypal.com/v1/notifications/test");
headers.put(Constants.PAYPAL_HEADER_TRANSMISSION_ID, "071f7d20-1584-11e7-abf0-6b62a8a99ac4");
headers.put(Constants.PAYPAL_HEADER_TRANSMISSION_TIME, "2017-03-30T20:04:05Z");
headers.put(Constants.PAYPAL_HEADER_AUTH_ALGO, "SHA256withRSA");
headers.put(Constants.PAYPAL_HEADER_TRANSMISSION_SIG, "aBjgm5/xljRYu3G64Q0axISrP2xcy7WbW1u4UTCKnQvyprOZ1a1BBmqn2Jdr6ce8E76I3Ti/AL9y4VYSHyGSEaoE6dVQcCDebLbOXLH0fjTAbTc1/rmfdWmsk0DPltW84Y8W8jOHe3CLWDOwg5zmozyt+AceG2x5eOiw7mLSycaEoj/5RG+dOIWXnmWcLEArbG3VFshy0wuhZrKuGa9C/bD4Ku+Y9gK7Bv5I5IuGRVnTGpcFnVG0KxOyJxccLGyBVCIUMY5IZS7LkmJszQ3HZZFDTNihvgJHECSLwLhzUaysIye5G6CbbLdtAmeeb6wiDciEAvr2dFf+SplOR4Lrng==");
requestBody = "{\"id\":\"WH-2MW4820926242972J-6SG447389E205703U\",\"event_version\":\"1.0\",\"create_time\":\"2017-03-30T20:04:05.613Z\",\"resource_type\":\"plan\",\"event_type\":\"BILLING.PLAN.CREATED\",\"summary\":\"A billing plan was created\",\"resource\":{\"merchant_preferences\":{\"setup_fee\":{\"currency\":\"USD\",\"value\":\"1\"},\"return_url\":\"https://www.mta.org/wp-content/plugins/AMS/api/Paypal/paypal/rest-api-sdk-php/sample/billing/ExecuteAgreement.php?success=true\",\"cancel_url\":\"https://www.mta.org/wp-content/plugins/AMS/api/Paypal/paypal/rest-api-sdk-php/sample/billing/ExecuteAgreement.php?success=false\",\"auto_bill_amount\":\"YES\",\"initial_fail_amount_action\":\"CONTINUE\",\"max_fail_attempts\":\"0\"},\"update_time\":\"2017-03-30T20:04:05.587Z\",\"create_time\":\"2017-03-30T20:04:05.587Z\",\"name\":\"T-Shirt of the Month Club Plan\",\"description\":\"Template creation.\",\"links\":[{\"href\":\"api.sandbox.paypal.com/v1/payments/billing-plans/P-2U911356NH683973BEDIWKUY\",\"rel\":\"self\",\"method\":\"GET\"}],\"payment_definitions\":[{\"name\":\"Regular Payments\",\"type\":\"REGULAR\",\"frequency\":\"Month\",\"frequency_interval\":\"2\",\"amount\":{\"currency\":\"USD\",\"value\":\"100\"},\"cycles\":\"12\",\"charge_models\":[{\"type\":\"SHIPPING\",\"amount\":{\"currency\":\"USD\",\"value\":\"10\"},\"id\":\"CHM-6H655806YS685182XEDIWKUY\"}],\"id\":\"PD-5N450756VM995270VEDIWKUY\"}],\"id\":\"P-2U911356NH683973BEDIWKUY\",\"state\":\"CREATED\",\"type\":\"FIXED\"},\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2MW4820926242972J-6SG447389E205703U\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2MW4820926242972J-6SG447389E205703U/resend\",\"rel\":\"resend\",\"method\":\"POST\"}]}";
}
代码示例来源:origin: NucleusPowered/Nucleus
@Override
protected void configure() {
Path test;
Path test2;
try {
test = Files.createTempDirectory("quick");
test2 = Files.createTempFile(test, "quick", "conf");
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
this.bind(Path.class).annotatedWith(DefaultConfig.class).toInstance(test2);
this.bind(Path.class).annotatedWith(ConfigDir.class).toInstance(test);
this.bind(Game.class).toInstance(Mockito.mock(Game.class));
this.bind(Logger.class).toInstance(Mockito.mock(Logger.class));
CoreConfigAdapter mock = Mockito.mock(CoreConfigAdapter.class);
PowerMockito.replace(PowerMockito.method(CoreConfigAdapter.class, "getNode")).with((obj, method, arguments) -> new CoreConfig());
this.bind(CoreConfigAdapter.class).toInstance(mock);
try {
NucleusPlugin plugin = getMockPlugin();
this.bind(NucleusPlugin.class).toInstance(plugin);
this.bind(UserDataManager.class).toInstance(plugin.getUserDataManager());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: ArturVasilov/AndroidSchool
@Before
public void setUp() throws Exception {
mPreferences = new SharedPreferencesMapImpl();
PowerMockito.stub(PowerMockito.method(Preferences.class, "getPrefs")).toReturn(mPreferences);
mTestRepository = new TestMoviesRepository();
RepositoryProvider.setRepository(mTestRepository);
mRouter = mock(MoviesRouter.class);
mViewModel = spy(new MoviesViewModel(Mockito.mock(Context.class), new MockLifecycleHandler(), mRouter));
}
代码示例来源:origin: apache/lens
CubeQueryRewriter mockWriter = getMockedRewriter();
CubeMetastoreClient mockClient = getMockedClient();
PowerMockito.stub(PowerMockito.method(RewriteUtil.class, "getCubeRewriter")).toReturn(mockWriter);
PowerMockito.stub(PowerMockito.method(RewriteUtil.class, "getClient")).toReturn(mockClient);
内容来源于网络,如有侵权,请联系作者删除!