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


Java Action类代码示例

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


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

示例1: will

import org.jmock.api.Action; //导入依赖的package包/类
void will(final Closure cl) {
    will(new Action() {
        public void describeTo(Description description) {
            description.appendText("execute closure");
        }

        public Object invoke(Invocation invocation) throws Throwable {
            List<Object> params = Arrays.asList(invocation.getParametersAsArray());
            Object result;
            try {
                List<Object> subParams = params.subList(0, Math.min(invocation.getParametersAsArray().length,
                        cl.getMaximumNumberOfParameters()));
                result = cl.call(subParams.toArray(new Object[0]));
            } catch (InvokerInvocationException e) {
                throw e.getCause();
            }
            if (invocation.getInvokedMethod().getReturnType().isInstance(result)) {
                return result;
            }
            return null;
        }
    });
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:24,代码来源:JUnit4GroovyMockery.java

示例2: will

import org.jmock.api.Action; //导入依赖的package包/类
void will(final Closure cl) {
    will(new Action() {
        public void describeTo(Description description) {
            description.appendText("execute closure");
        }

        public Object invoke(Invocation invocation) throws Throwable {
            List<Object> params = Arrays.asList(invocation.getParametersAsArray());
            Object result;
            try {
                List<Object> subParams = params.subList(0, Math.min(invocation.getParametersAsArray().length,
                        cl.getMaximumNumberOfParameters()));
                result = cl.call(subParams.toArray(new Object[subParams.size()]));
            } catch (InvokerInvocationException e) {
                throw e.getCause();
            }
            if (invocation.getInvokedMethod().getReturnType().isInstance(result)) {
                return result;
            }
            return null;
        }
    });
}
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:24,代码来源:JUnit4GroovyMockery.java

示例3: returnInstantiatedAndInitializedViewModel

import org.jmock.api.Action; //导入依赖的package包/类
private Action returnInstantiatedAndInitializedViewModel() {
    return new Action() {
        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            final Class<?> cls = (Class<?>) invocation.getParameter(0);
            final String memento = (String) invocation.getParameter(1);
            final ViewModel viewModelInstance = (ViewModel) cls.newInstance();
            viewModelInstance.viewModelInit(memento);
            if(viewModelInstance instanceof UserPermissionViewModel) {
                ((UserPermissionViewModel) viewModelInstance).applicationPermissionRepository = mockApplicationPermissionRepository;
            }
            return viewModelInstance;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("return instantiated and initialized view model ");
        }
    };
}
 
开发者ID:isisaddons-legacy,项目名称:isis-module-security,代码行数:21,代码来源:UserPermissionViewModelTest.java

示例4: addToInMemoryDB

import org.jmock.api.Action; //导入依赖的package包/类
private Action addToInMemoryDB() {
    return new Action() {
        
        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            final InMemoryDB inMemoryDB = getVar("isis", "in-memory-db", InMemoryDB.class);
            final String name = (String)invocation.getParameter(0);
            final SimpleObject obj = new SimpleObject();
            obj.setName(name);
            inMemoryDB.put(SimpleObject.class, name, obj);
            return obj;
        }
        
        @Override
        public void describeTo(Description description) {
            description.appendText("add to database");
        }
    };
}
 
开发者ID:danhaywood,项目名称:rrraddd-isis-131,代码行数:20,代码来源:SimpleObjectGlue.java

示例5: testFailsIfInvokedMoreTimesThanThereAreActionsInTheSequence

import org.jmock.api.Action; //导入依赖的package包/类
@SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!
public void testFailsIfInvokedMoreTimesThanThereAreActionsInTheSequence() throws Throwable {
    MockAction[] actions = new MockAction[]{new MockAction(), new MockAction()};
    ActionSequence sequence = new ActionSequence((Action[])actions);
    
    for (int i = 0; i < actions.length; i++) sequence.invoke(invocation);
    
    try {
        sequence.invoke(invocation);
        fail("should have thrown IllegalStateException");
    }
    catch (ExpectationError ex) {
        AssertThat.stringIncludes("should describe error",
            "no more actions", ex.getMessage());
        return;
    }
}
 
开发者ID:Shared-Business-Service,项目名称:jMock-Demo,代码行数:18,代码来源:ActionSequenceTests.java

示例6: testDescribesItselfAsSequenceOfActions

import org.jmock.api.Action; //导入依赖的package包/类
@SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!
public void testDescribesItselfAsSequenceOfActions() throws Throwable {
    MockAction[] actions = new MockAction[]{new MockAction(), new MockAction()};
    ActionSequence sequence = new ActionSequence((Action[])actions);
    
    String sequenceDescription = StringDescription.toString(sequence);

    for (int i = 0; i < actions.length; i++) {
        AssertThat.stringIncludes("should include action " + i,
            actions[i].descriptionText, sequenceDescription);

        if (i > 0) {
            int h = i - 1;
            
            assertTrue("description of action " + h + " should be before that of action " + i,
                       sequenceDescription.indexOf(actions[h].descriptionText) <
                       sequenceDescription.indexOf(actions[i].descriptionText));
        }
    }
}
 
开发者ID:Shared-Business-Service,项目名称:jMock-Demo,代码行数:21,代码来源:ActionSequenceTests.java

示例7: testSaveLoad

import org.jmock.api.Action; //导入依赖的package包/类
@Test(dataProvider = "editionProvider")
public void testSaveLoad(@NotNull final PowerShellEdition edition) throws IOException {
  PowerShellInfo info = new PowerShellInfo(PowerShellBitness.x64, createTempDir(), "1.0", edition, "powershell.exe");

  final Mockery m = new Mockery();
  final BuildAgentConfiguration conf = m.mock(BuildAgentConfiguration.class);

  final Map<String, String> confParams = new HashMap<String, String>();
  m.checking(new Expectations(){{
    allowing(conf).getConfigurationParameters(); will(returnValue(Collections.unmodifiableMap(confParams)));
    allowing(conf).addConfigurationParameter(with(any(String.class)), with(any(String.class)));
    will(new Action() {
      public Object invoke(final Invocation invocation) throws Throwable {
        final String key = (String) invocation.getParameter(0);
        final String value = (String) invocation.getParameter(1);
        Assert.assertNotNull(key);
        Assert.assertNotNull(value);
        confParams.put(key, value);
        return null;
      }

      public void describeTo(final Description description) {
        description.appendText("add Parameters");
      }
    });
  }});

  info.saveInfo(conf);

  PowerShellInfo i = PowerShellInfo.loadInfo(conf, PowerShellBitness.x64);

  Assert.assertNotNull(i);
  Assert.assertEquals(i.getBitness(), info.getBitness());
  Assert.assertEquals(i.getHome(), info.getHome());
  Assert.assertEquals(i.getExecutablePath(), info.getExecutablePath());
  Assert.assertEquals(i.getVersion(), info.getVersion());
  Assert.assertEquals(i.getEdition(), info.getEdition());
  Assert.assertEquals(i.getExecutable(), info.getExecutable());
}
 
开发者ID:JetBrains,项目名称:teamcity-powershell,代码行数:40,代码来源:PowerShellInfoTest.java

示例8: countDown

import org.jmock.api.Action; //导入依赖的package包/类
public static Action countDown(final CountDownLatch latch)
{
    return new CustomAction("Count Down Latch")
    {
        public Object invoke(Invocation invocation) throws Throwable
        {
            latch.countDown();
            return null;
        }
    };
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:12,代码来源:Actions.java

示例9: setupApplication

import org.jmock.api.Action; //导入依赖的package包/类
@Before
public final void setupApplication() throws Exception {
  context = new JUnit4Mockery();
  context.setImposteriser(ClassImposteriser.INSTANCE);
  myApplication = context.mock(ApplicationEx.class, "application");

  context.checking(new Expectations() {
    {
      allowing(myApplication).isUnitTestMode(); will(returnValue(false));
      allowing(myApplication).getName(); will(returnValue("IDEA"));

      // some tests leave invokeLater()'s after them
      allowing(myApplication).invokeLater(with(any(Runnable.class)), with(any(ModalityState.class)));

      allowing(myApplication).runReadAction(with(any(Runnable.class)));
      will(new Action() {
        @Override
        public void describeTo(final Description description) {
          description.appendText("runs runnable");
        }

        @Override
        @Nullable
        public Object invoke(final Invocation invocation) throws Throwable {
          ((Runnable)invocation.getParameter(0)).run();
          return null;
        }
      });
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:32,代码来源:PathMacroManagerTest.java

示例10: executeCallableAndReturn

import org.jmock.api.Action; //导入依赖的package包/类
private static Action executeCallableAndReturn() {
    return new Action() {
        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            Callable<Object> callable = (Callable<Object>) invocation.getParameter(0);
            return callable.call();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("execute arg 0 as callable and return");
        }
    };
}
 
开发者ID:estatio,项目名称:estatio,代码行数:15,代码来源:IndexValueRepository_Test.java

示例11: returnLeaseTerm

import org.jmock.api.Action; //导入依赖的package包/类
private Action returnLeaseTerm() {
    return new Action() {
        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            LeaseItem leaseItem = (LeaseItem) invocation.getParameter(0);
            LeaseTerm leaseTerm = (LeaseTerm) invocation.getParameter(1);
            LocalDate startDate = (LocalDate) invocation.getParameter(2);
            LocalDate endDate = (LocalDate) invocation.getParameter(3);
            LeaseTermForTesting ltt = new LeaseTermForTesting();
            // relationships
            ltt.setLeaseItem(leaseItem);
            leaseItem.getTerms().add(ltt);
            ltt.setPrevious(leaseTerm);
            leaseTerm.setNext(ltt);
            // set values
            ltt.modifyStartDate(startDate);
            ltt.modifyEndDate(endDate);
            ltt.clockService = mockClockService;
            return ltt;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("new Lease Term under item and with previous term");
        }
    };
}
 
开发者ID:estatio,项目名称:estatio,代码行数:28,代码来源:LeaseTerm_Test.java

示例12: setupApplication

import org.jmock.api.Action; //导入依赖的package包/类
@Before
public final void setupApplication() throws Exception {
  // in fact the test accesses extension points so it rather should be converted to a platform one
  assumeNotNull(ApplicationManager.getApplication());

  context = new JUnit4Mockery();
  context.setImposteriser(ClassImposteriser.INSTANCE);
  myApplication = context.mock(ApplicationEx.class, "application");

  context.checking(new Expectations() {
    {
      allowing(myApplication).isUnitTestMode(); will(returnValue(false));

      // some tests leave invokeLater()'s after them
      allowing(myApplication).invokeLater(with(any(Runnable.class)), with(any(ModalityState.class)));

      allowing(myApplication).runReadAction(with(any(Runnable.class)));
      will(new Action() {
        @Override
        public void describeTo(final Description description) {
          description.appendText("runs runnable");
        }

        @Override
        @javax.annotation.Nullable
        public Object invoke(final Invocation invocation) throws Throwable {
          ((Runnable)invocation.getParameter(0)).run();
          return null;
        }
      });
    }
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:34,代码来源:PathMacroManagerTest.java

示例13: buildExpectations

import org.jmock.api.Action; //导入依赖的package包/类
public void buildExpectations(Action defaultAction, ExpectationCollector collector) {
    checkLastExpectationWasFullySpecified();
    
    for (InvocationExpectationBuilder builder : builders) {
        collector.add(builder.toExpectation(defaultAction));
    }
}
 
开发者ID:Shared-Business-Service,项目名称:jMock-Demo,代码行数:8,代码来源:Expectations.java

示例14: toExpectation

import org.jmock.api.Action; //导入依赖的package包/类
public Expectation toExpectation(Action defaultAction) {
    if (needsDefaultAction) {
        expectation.setDefaultAction(defaultAction);
    }
    
    return expectation;
}
 
开发者ID:Shared-Business-Service,项目名称:jMock-Demo,代码行数:8,代码来源:InvocationExpectationBuilder.java

示例15: doSomethingDescribedAs

import org.jmock.api.Action; //导入依赖的package包/类
public Action doSomethingDescribedAs(String name) {
    return new CustomAction(name) {
        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            return null;
        }
    };
}
 
开发者ID:Shared-Business-Service,项目名称:jMock-Demo,代码行数:9,代码来源:ErrorMessagesAcceptanceTests.java


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