本文整理汇总了Java中org.powermock.api.mockito.PowerMockito.field方法的典型用法代码示例。如果您正苦于以下问题:Java PowerMockito.field方法的具体用法?Java PowerMockito.field怎么用?Java PowerMockito.field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.powermock.api.mockito.PowerMockito
的用法示例。
在下文中一共展示了PowerMockito.field方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startLoginFlowTest
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void startLoginFlowTest() throws MalformedURLException, LiRestResponseException, URISyntaxException, IllegalAccessException {
LiSSOAuthorizationRequest authorizationRequest;
authorizationRequest = new LiSSOAuthorizationRequest();
authorizationRequest.setClientId(liAppCredentials.getClientKey());
authorizationRequest.setRedirectUri(liAppCredentials.getRedirectUri());
authorizationRequest.setState(RANDOM_STATE);
authorizationRequest.setUri(String.valueOf(liAppCredentials.getAuthorizeUri()));
Field field = PowerMockito.field(LiSystemClock.class, "INSTANCE");
LiSystemClock mock = mock(LiSystemClock.class);
field.set(LiSystemClock.class, mock);
when(mock.getCurrentTimeMillis()).thenReturn(1L);
//
LiAuthService liAuthService = new LiAuthServiceImpl(mContext);
liAuthService=spy(liAuthService);
doNothing().when(liAuthService).dispose();
doNothing().when(liAuthService).performAuthorizationRequest(authorizationRequest);
liAuthService.startLoginFlow();
verify(liAuthService,times(1)).performAuthorizationRequest(isA(LiSSOAuthorizationRequest.class));
verify(liAuthService,times(0)).performSSOAuthorizationRequest(isA(LiSSOAuthorizationRequest.class));
}
示例2: startLoginFlowSSOTest
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void startLoginFlowSSOTest() throws MalformedURLException, LiRestResponseException, URISyntaxException, IllegalAccessException {
LiSSOAuthorizationRequest authorizationRequest;
authorizationRequest = new LiSSOAuthorizationRequest();
authorizationRequest.setClientId(liAppCredentials.getClientKey());
authorizationRequest.setRedirectUri(liAppCredentials.getRedirectUri());
authorizationRequest.setState(RANDOM_STATE);
authorizationRequest.setUri(String.valueOf(liAppCredentials.getAuthorizeUri()));
Field field = PowerMockito.field(LiSystemClock.class, "INSTANCE");
LiSystemClock mock = mock(LiSystemClock.class);
field.set(LiSystemClock.class, mock);
when(mock.getCurrentTimeMillis()).thenReturn(1L);
//
LiAuthService liAuthService = new LiAuthServiceImpl(mContext);
liAuthService=spy(liAuthService);
doNothing().when(liAuthService).dispose();
doNothing().when(liAuthService).performSSOAuthorizationRequest(isA(LiSSOAuthorizationRequest.class));
liAuthService.startLoginFlow(SSO_TOKEN1);
verify(liAuthService,times(0)).performAuthorizationRequest(isA(LiSSOAuthorizationRequest.class));
verify(liAuthService,times(1)).performSSOAuthorizationRequest(isA(LiSSOAuthorizationRequest.class));
}
示例3: setUp
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void setUp() throws IllegalAccessException {
// Mockito has a very convenient way to inject mocks by using the @Mock annotation. To
// inject the mocks in the test the initMocks method needs to be called.
MockitoAnnotations.initMocks(this);
//systemClock= Mockito.mock(LiSystemClock.class);
Field field = PowerMockito.field(LiSystemClock.class, "INSTANCE");
mock = mock(LiSystemClock.class);
field.set(LiSystemClock.class, mock);
when(mock.getCurrentTimeMillis()).thenReturn(1L);
}
示例4: setupRequest
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void setupRequest() throws Exception {
// Mockito has a very convenient way to inject mocks by using the @Mock annotation. To
// inject the mocks in the test the initMocks method needs to be called.
MockitoAnnotations.initMocks(this);
//systemClock= Mockito.mock(LiSystemClock.class);
Field field = PowerMockito.field(LiSystemClock.class, "INSTANCE");
mock = mock(LiSystemClock.class);
field.set(LiSystemClock.class, mock);
when(mock.getCurrentTimeMillis()).thenReturn(1L);
}
示例5: performAuthorizationRequestTest
import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void performAuthorizationRequestTest() throws Exception {
LiSSOAuthorizationRequest authorizationRequest;
authorizationRequest = new LiSSOAuthorizationRequest();
authorizationRequest.setClientId(liAppCredentials.getClientKey());
authorizationRequest.setRedirectUri(liAppCredentials.getRedirectUri());
authorizationRequest.setState(RANDOM_STATE);
authorizationRequest.setUri(String.valueOf(liAppCredentials.getAuthorizeUri()));
Field field = PowerMockito.field(LiSystemClock.class, "INSTANCE");
LiSystemClock mock = mock(LiSystemClock.class);
field.set(LiSystemClock.class, mock);
when(mock.getCurrentTimeMillis()).thenReturn(1L);
//
LiAuthService liAuthService = new LiAuthServiceImpl(mContext);
//liAuthService=spy(liAuthService);
liAuthService = spy(liAuthService);
doNothing().when(liAuthService).dispose();
when(resource.getBoolean(anyInt())).thenReturn(true);
// CustomTabsIntent customTabsIntent=new CustomTabsIntent.Builder(null).build();
// PowerMockito.doReturn(customTabsIntent).when(liAuthService,
// "createCustomTabsIntent");
doNothing().when(liAuthService,
"checkIfDisposed");
liAuthService.startLoginFlow(SSO_TOKEN);
doNothing().when(mContext).startActivity(isA(Intent.class));
verify(mContext, Mockito.atLeastOnce()).startActivity(isA(Intent.class));
verify(liAuthService,times(1)).performAuthorizationRequest(isA(LiSSOAuthorizationRequest.class));
verify(liAuthService,times(0)).performSSOAuthorizationRequest(isA(LiSSOAuthorizationRequest.class));
}