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


Java MemberModifier类代码示例

本文整理汇总了Java中org.powermock.api.support.membermodification.MemberModifier的典型用法代码示例。如果您正苦于以下问题:Java MemberModifier类的具体用法?Java MemberModifier怎么用?Java MemberModifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MemberModifier类属于org.powermock.api.support.membermodification包,在下文中一共展示了MemberModifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReplaceView

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
public void testReplaceView() throws Exception {
    ArrayList<ViewsInfo> mockedViewsInfos = mock(ArrayList.class);
    MemberModifier.field(UnderlabelValidator.class, "mContext").set(mSpiedUnderlabelValidator, mMockedContext);
    MemberModifier.field(UnderlabelValidator.class, "mViewsInfos").set(mSpiedUnderlabelValidator, mockedViewsInfos);
    int index = 128;
    EditText mockedEditText = mock(EditText.class);
    ViewGroup mockedParent = mock(ViewGroup.class);
    LinearLayout mockedContainer = mock(LinearLayout.class);
    ViewsInfo mockedViewsInfo = mock(ViewsInfo.class);
    when(mMockedValidationHolderRegexTypeFail.getEditText()).thenReturn(mockedEditText);
    when(mockedEditText.getParent()).thenReturn(mockedParent);
    when(mockedParent.indexOfChild(mockedEditText)).thenReturn(index);
    PowerMockito.whenNew(LinearLayout.class).withArguments(mMockedContext).thenReturn(mockedContainer);
    PowerMockito.whenNew(ViewsInfo.class).withArguments(index, mockedParent, mockedContainer, mockedEditText).thenReturn(mockedViewsInfo);
    Whitebox.invokeMethod(mSpiedUnderlabelValidator, "replaceView", mMockedValidationHolderRegexTypeFail);
    verify(mockedViewsInfos, times(1)).add(mockedViewsInfo);
    TextView mockedTextView = mock(TextView.class);
    PowerMockito.whenNew(TextView.class).withArguments(mMockedContext).thenReturn(mockedTextView);
    assertEquals(mockedTextView, Whitebox.invokeMethod(mSpiedUnderlabelValidator, "replaceView", mMockedValidationHolderRegexTypeFail));
}
 
开发者ID:PM-Martin,项目名称:Validation-android,代码行数:21,代码来源:UnderlabelValidatorTest.java

示例2: testHaltRestoreViewsForAllAnyway

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
public void testHaltRestoreViewsForAllAnyway() throws IllegalAccessException {
    ArrayList<ViewsInfo> spiedViewsInfos = spy(ArrayList.class);
    ViewsInfo mockedViewsInfo1 = mock(ViewsInfo.class);
    ViewsInfo mockedViewsInfo2 = mock(ViewsInfo.class);
    ViewsInfo mockedViewsInfo3 = mock(ViewsInfo.class);
    ViewsInfo mockedViewsInfo4 = mock(ViewsInfo.class);
    spiedViewsInfos.addAll(Arrays.asList(mockedViewsInfo1, mockedViewsInfo2, mockedViewsInfo3, mockedViewsInfo4));
    MemberModifier.field(UnderlabelValidator.class, "mViewsInfos").set(mSpiedUnderlabelValidator, spiedViewsInfos);
    mSpiedUnderlabelValidator.mValidationHolderList.addAll(Arrays.asList(mMockedValidationHolderRegexTypePass,
            mMockedValidationHolderRegexTypeFail,
            mMockedValidationHolderRangeTypePass,
            mMockedValidationHolderRangeTypeFail));
    mSpiedUnderlabelValidator.halt();
    for (ViewsInfo viewsInfo : spiedViewsInfos) {
        verify(viewsInfo, times(1)).restoreViews();
    }
}
 
开发者ID:PM-Martin,项目名称:Validation-android,代码行数:18,代码来源:UnderlabelValidatorTest.java

示例3: testCreateDataCarrier

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testCreateDataCarrier() throws IllegalAccessException {
    DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(5, 100);
    Assert.assertEquals(((Integer) (MemberModifier.field(DataCarrier.class, "bufferSize").get(carrier))).intValue(), 100);
    Assert.assertEquals(((Integer) (MemberModifier.field(DataCarrier.class, "channelSize").get(carrier))).intValue(), 5);

    Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels").get(carrier));
    Assert.assertEquals(channels.getChannelSize(), 5);

    Buffer<SampleData> buffer = channels.getBuffer(0);
    Assert.assertEquals(buffer.getBufferSize(), 100);

    Assert.assertEquals(MemberModifier.field(Buffer.class, "strategy").get(buffer), BufferStrategy.BLOCKING);
    carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE);
    Assert.assertEquals(MemberModifier.field(Buffer.class, "strategy").get(buffer), BufferStrategy.IF_POSSIBLE);

    Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner").get(channels).getClass(), SimpleRollingPartitioner.class);
    carrier.setPartitioner(new ProducerThreadPartitioner<SampleData>());
    Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner").get(channels).getClass(), ProducerThreadPartitioner.class);
}
 
开发者ID:wu-sheng,项目名称:DataCarrier,代码行数:21,代码来源:DataCarrierTest.java

示例4: testProduce

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testProduce() throws IllegalAccessException {
    DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100);
    Assert.assertTrue(carrier.produce(new SampleData().setName("a")));
    Assert.assertTrue(carrier.produce(new SampleData().setName("b")));
    Assert.assertTrue(carrier.produce(new SampleData().setName("c")));
    Assert.assertTrue(carrier.produce(new SampleData().setName("d")));

    Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels").get(carrier));
    Buffer<SampleData> buffer1 = channels.getBuffer(0);
    List result1 = buffer1.obtain(0, 100);

    Buffer<SampleData> buffer2 = channels.getBuffer(1);
    List result2 = buffer2.obtain(0, 100);

    Assert.assertEquals(2, result1.size());
    Assert.assertEquals(4, result1.size() + result2.size());


}
 
开发者ID:wu-sheng,项目名称:DataCarrier,代码行数:21,代码来源:DataCarrierTest.java

示例5: testOverrideProduce

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testOverrideProduce() throws IllegalAccessException {
    DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100);
    carrier.setBufferStrategy(BufferStrategy.OVERRIDE);

    for (int i = 0; i < 500; i++) {
        Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i)));
    }

    Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels").get(carrier));
    Buffer<SampleData> buffer1 = channels.getBuffer(0);
    List result1 = buffer1.obtain(0, 100);

    Buffer<SampleData> buffer2 = channels.getBuffer(1);
    List result2 = buffer2.obtain(0, 100);
    Assert.assertEquals(200, result1.size() + result2.size());
}
 
开发者ID:wu-sheng,项目名称:DataCarrier,代码行数:18,代码来源:DataCarrierTest.java

示例6: testIfPossibleProduce

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testIfPossibleProduce() throws IllegalAccessException {
    DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100);
    carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE);

    for (int i = 0; i < 200; i++) {
        Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i)));
    }

    for (int i = 0; i < 200; i++) {
        Assert.assertFalse(carrier.produce(new SampleData().setName("d" + i + "_2")));
    }

    Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels").get(carrier));
    Buffer<SampleData> buffer1 = channels.getBuffer(0);
    List result1 = buffer1.obtain(0, 100);

    Buffer<SampleData> buffer2 = channels.getBuffer(1);
    List result2 = buffer2.obtain(0, 100);
    Assert.assertEquals(200, result1.size() + result2.size());
}
 
开发者ID:wu-sheng,项目名称:DataCarrier,代码行数:22,代码来源:DataCarrierTest.java

示例7: testDoGetBadTicket

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testDoGetBadTicket() throws Exception {
    //Mock some objects.
    HttpServletRequest request = createDoGetHttpServletRequest(CONVERSATION_TICKET, TICKET, "false");
    HttpServletResponse response = createMockHttpServletResponse();
    Cas20ServiceTicketValidator ticketValidator = PowerMockito.mock(Cas20ServiceTicketValidator.class);
    PowerMockito.when(ticketValidator.validate(TICKET, URL_WITH_CONVERSATION)).thenThrow(new TicketValidationException("Invalid Ticket"));

    PowerMockito.mockStatic(ExternalAuthentication.class);
    BDDMockito.given(ExternalAuthentication.startExternalAuthentication(request)).willThrow(new ExternalAuthenticationException());

    //Prep our object
    ShibcasAuthServlet shibcasAuthServlet = createShibcasAuthServlet();

    //Override the internal Cas20TicketValidator because we don't want it to call a real server
    MemberModifier.field(ShibcasAuthServlet.class, "ticketValidator").set(shibcasAuthServlet, ticketValidator);

    //Standard request/response - bad ticket
    BDDMockito.given(request.getAttribute(ExternalAuthentication.FORCE_AUTHN_PARAM)).willReturn("false");
    BDDMockito.given(request.getAttribute(ExternalAuthentication.PASSIVE_AUTHN_PARAM)).willReturn("false");
    shibcasAuthServlet.doGet(request, response);

    //Verify
    verify(request).getRequestDispatcher("/no-conversation-state.jsp");
    verify(response).setStatus(404);
}
 
开发者ID:Unicon,项目名称:shib-cas-authn3,代码行数:27,代码来源:ShibcasAuthServletTest.java

示例8: buildWorkflowModel

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
public static void buildWorkflowModel(String bundleDirectory, AbstractWorkflowDataModel w) throws IllegalAccessException {

        //Need to mock basedir as it is retrieved from the WS
        MemberModifier.field(AbstractWorkflowDataModel.class, "basedir").set(w, bundleDirectory);

        //Get the data from metadata.xml
        Map<String, String> metaInfo = WorkflowV2Utility.parseMetaInfo(FileUtils.getFile(bundleDirectory));

        //Build the workflow model
        AbstractWorkflowDataModel.prepare(w);
        w.setMetadata_output_file_prefix(w.getConfigs().get("output_prefix"));
        w.setMetadata_output_dir(w.getConfigs().get("output_dir"));
        w.setName(metaInfo.get("name"));
        w.setVersion(metaInfo.get("workflow_version"));
        w.setRandom("" + new Random(System.currentTimeMillis()).nextInt(100000000)); //seqware's random int method
        w.setupDirectory();
        w.setupFiles();
        w.setupWorkflow();
        w.setupEnvironment();
        w.buildWorkflow();
        w.wrapup();
    }
 
开发者ID:oicr-gsi,项目名称:gatk3,代码行数:23,代码来源:MockWorkflowDataModelFactory.java

示例9: testCreateDataCarrier

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testCreateDataCarrier() throws IllegalAccessException {
    DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(5, 100);
    Assert.assertEquals(((Integer)(MemberModifier.field(DataCarrier.class, "bufferSize").get(carrier))).intValue(), 100);
    Assert.assertEquals(((Integer)(MemberModifier.field(DataCarrier.class, "channelSize").get(carrier))).intValue(), 5);

    Channels<SampleData> channels = (Channels<SampleData>)(MemberModifier.field(DataCarrier.class, "channels").get(carrier));
    Assert.assertEquals(channels.getChannelSize(), 5);

    Buffer<SampleData> buffer = channels.getBuffer(0);
    Assert.assertEquals(buffer.getBufferSize(), 100);

    Assert.assertEquals(MemberModifier.field(Buffer.class, "strategy").get(buffer), BufferStrategy.BLOCKING);
    carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE);
    Assert.assertEquals(MemberModifier.field(Buffer.class, "strategy").get(buffer), BufferStrategy.IF_POSSIBLE);

    Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner").get(channels).getClass(), SimpleRollingPartitioner.class);
    carrier.setPartitioner(new ProducerThreadPartitioner<SampleData>());
    Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner").get(channels).getClass(), ProducerThreadPartitioner.class);
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:21,代码来源:DataCarrierTest.java

示例10: testProduce

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testProduce() throws IllegalAccessException {
    DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100);
    Assert.assertTrue(carrier.produce(new SampleData().setName("a")));
    Assert.assertTrue(carrier.produce(new SampleData().setName("b")));
    Assert.assertTrue(carrier.produce(new SampleData().setName("c")));
    Assert.assertTrue(carrier.produce(new SampleData().setName("d")));

    Channels<SampleData> channels = (Channels<SampleData>)(MemberModifier.field(DataCarrier.class, "channels").get(carrier));
    Buffer<SampleData> buffer1 = channels.getBuffer(0);
    List result1 = buffer1.obtain(0, 100);

    Buffer<SampleData> buffer2 = channels.getBuffer(1);
    List result2 = buffer2.obtain(0, 100);

    Assert.assertEquals(2, result1.size());
    Assert.assertEquals(4, result1.size() + result2.size());

}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:20,代码来源:DataCarrierTest.java

示例11: testOverrideProduce

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testOverrideProduce() throws IllegalAccessException {
    DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100);
    carrier.setBufferStrategy(BufferStrategy.OVERRIDE);

    for (int i = 0; i < 500; i++) {
        Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i)));
    }

    Channels<SampleData> channels = (Channels<SampleData>)(MemberModifier.field(DataCarrier.class, "channels").get(carrier));
    Buffer<SampleData> buffer1 = channels.getBuffer(0);
    List result1 = buffer1.obtain(0, 100);

    Buffer<SampleData> buffer2 = channels.getBuffer(1);
    List result2 = buffer2.obtain(0, 100);
    Assert.assertEquals(200, result1.size() + result2.size());
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:18,代码来源:DataCarrierTest.java

示例12: testIfPossibleProduce

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testIfPossibleProduce() throws IllegalAccessException {
    DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100);
    carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE);

    for (int i = 0; i < 200; i++) {
        Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i)));
    }

    for (int i = 0; i < 200; i++) {
        Assert.assertFalse(carrier.produce(new SampleData().setName("d" + i + "_2")));
    }

    Channels<SampleData> channels = (Channels<SampleData>)(MemberModifier.field(DataCarrier.class, "channels").get(carrier));
    Buffer<SampleData> buffer1 = channels.getBuffer(0);
    List result1 = buffer1.obtain(0, 100);

    Buffer<SampleData> buffer2 = channels.getBuffer(1);
    List result2 = buffer2.obtain(0, 100);
    Assert.assertEquals(200, result1.size() + result2.size());
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:22,代码来源:DataCarrierTest.java

示例13: testPutAndGetConnectionInstance

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
public void testPutAndGetConnectionInstance() throws Exception {
    ConnectionInfo key = mock(ConnectionInfo.class);
    ConnectionInfo connectionInfo = mock(ConnectionInfo.class);
    PowerMockito.mockStatic(SouthboundMapper.class);
    when(SouthboundMapper.suppressLocalIpPort(key)).thenReturn(connectionInfo);

    clients = new ConcurrentHashMap<>();
    MemberModifier.field(OvsdbConnectionManager.class, "clients").set(ovsdbConnManager, clients);

    // Test putConnectionInstance()
    OvsdbConnectionInstance instance = mock(OvsdbConnectionInstance.class);
    Whitebox.invokeMethod(ovsdbConnManager, "putConnectionInstance", key, instance);
    Map<ConnectionInfo, OvsdbConnectionInstance> testClients = Whitebox.getInternalState(ovsdbConnManager,
            "clients");
    assertEquals("Error, size of the hashmap is incorrect", 1, testClients.size());

    // Test getConnectionInstance(ConnectionInfo key)
    assertEquals("Error, returned incorrect OvsdbConnectionInstance object", instance,
            ovsdbConnManager.getConnectionInstance(key));
}
 
开发者ID:opendaylight,项目名称:ovsdb,代码行数:22,代码来源:OvsdbConnectionManagerTest.java

示例14: testCreateTransactInvokers

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testCreateTransactInvokers() throws Exception {
    // transactInvokers not null case
    transactInvokers = new HashMap();
    field(OvsdbConnectionInstance.class, "transactInvokers").set(ovsdbConnectionInstance , transactInvokers);
    ovsdbConnectionInstance.createTransactInvokers();
    verify(ovsdbConnectionInstance, times(0)).getSchema(anyString());

    // transactInvokers null case
    MemberModifier.field(OvsdbConnectionInstance.class, "transactInvokers").set(ovsdbConnectionInstance , null);

    ListenableFuture<DatabaseSchema> listenableDbSchema = mock(ListenableFuture.class);
    DatabaseSchema dbSchema = mock(DatabaseSchema.class);
    doReturn(listenableDbSchema).when(ovsdbConnectionInstance).getSchema(anyString());
    when(listenableDbSchema.get()).thenReturn(dbSchema);

    ovsdbConnectionInstance.createTransactInvokers();
    verify(ovsdbConnectionInstance).getSchema(anyString());

    Map<DatabaseSchema, TransactInvoker> testTransactInvokers = Whitebox.getInternalState(ovsdbConnectionInstance,
            "transactInvokers");
    assertEquals("Error, size of the hashmap is incorrect", 1, testTransactInvokers.size());
}
 
开发者ID:opendaylight,项目名称:ovsdb,代码行数:25,代码来源:OvsdbConnectionInstanceTest.java

示例15: testSetOtherConfig

import org.powermock.api.support.membermodification.MemberModifier; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testSetOtherConfig() throws Exception {
    OpenVSwitch oldEntry = mock(OpenVSwitch.class);
    OpenVSwitch openVSwitch = mock(OpenVSwitch.class);

    Column<GenericTableSchema, Map<String, String>> column = mock(Column.class);
    when(openVSwitch.getOtherConfigColumn()).thenReturn(column);
    Map<String, String> map = new HashMap<>();
    when(column.getData()).thenReturn(map);
    when(oldEntry.getOtherConfigColumn()).thenReturn(column);
    MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "removeOldConfigs",
            ReadWriteTransaction.class, Map.class, OpenVSwitch.class));
    MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "setNewOtherConfigs",
            OvsdbNodeAugmentationBuilder.class, Map.class));

    ReadWriteTransaction transaction = mock(ReadWriteTransaction.class);
    OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = mock(OvsdbNodeAugmentationBuilder.class);
    Whitebox.invokeMethod(openVSwitchUpdateCommand, "setOtherConfig",
            transaction, ovsdbNodeBuilder, oldEntry, openVSwitch);
    verify(openVSwitch, times(2)).getOtherConfigColumn();
    verify(oldEntry, times(2)).getOtherConfigColumn();
    PowerMockito.verifyPrivate(openVSwitchUpdateCommand).invoke("removeOldConfigs",
            any(ReadWriteTransaction.class),
            any(Map.class), any(OpenVSwitch.class));
}
 
开发者ID:opendaylight,项目名称:ovsdb,代码行数:27,代码来源:OpenVSwitchUpdateCommandTest.java


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