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


Java PowerMockito.field方法代码示例

本文整理汇总了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));
}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:22,代码来源:LiAuthServiceTest.java

示例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));
}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:23,代码来源:LiAuthServiceTest.java

示例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);

}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:13,代码来源:LiAuthStateTest.java

示例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);
}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:12,代码来源:LiTokenResponseTest.java

示例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));

    }
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:32,代码来源:LiAuthServiceTest.java


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