How to use exactly method of org.jmock.AbstractExpectations class

Best Jmock-library code snippet using org.jmock.AbstractExpectations.exactly

Source:AbstractExpectations.java Github

copy

Full Screen

...101 /* 102 * Syntactic sugar103 */104 105 public ReceiverClause exactly(int count) {106 initialiseExpectationCapture(Cardinality.exactly(count));107 return currentBuilder;108 }109 110 // Makes the entire expectation more readable than one111 public <T> T oneOf(T mockObject) {112 return exactly(1).of(mockObject);113 }114 115 /**116 * @deprecated Use {@link #oneOf(Object) oneOf} instead.117 */118 public <T> T one (T mockObject) {119 return oneOf(mockObject);120 }121 122 public ReceiverClause atLeast(int count) {123 initialiseExpectationCapture(Cardinality.atLeast(count));124 return currentBuilder;125 }126 127 public ReceiverClause between(int minCount, int maxCount) {128 initialiseExpectationCapture(Cardinality.between(minCount, maxCount));129 return currentBuilder;130 }131 132 public ReceiverClause atMost(int count) {133 initialiseExpectationCapture(Cardinality.atMost(count));134 return currentBuilder;135 }136 137 public MethodClause allowing(Matcher<?> mockObjectMatcher) {138 return atLeast(0).of(mockObjectMatcher);139 }140 141 public <T> T allowing(T mockObject) {142 return atLeast(0).of(mockObject);143 }144 145 public <T> T ignoring(T mockObject) {146 return allowing(mockObject);147 }148 149 public MethodClause ignoring(Matcher<?> mockObjectMatcher) {150 return allowing(mockObjectMatcher);151 }152 153 public <T> T never(T mockObject) {154 return exactly(0).of(mockObject);155 }156 157 /*158 * protected because the byte code injected values need to be able to call this159 */160 protected void addParameterMatcher(Matcher<?> matcher) {161 currentBuilder().addParameterMatcher(matcher);162 }163 164 /**165 * For Matchers with primitive types use the <em>with</em> field, for example:166 * <pre>with.intIs(equalTo(34));</pre>167 * For untyped matchers use:168 * <pre>with.&lt;T&gt;is(equalTo(anObject));</pre>...

Full Screen

Full Screen

Source:TeleportMovementRuleTest.java Github

copy

Full Screen

...101 EvacuationStateControllerInterface ec = context.mock(EvacuationStateControllerInterface.class);102 TeleportMovementRule rule = new TeleportMovementRule(mr);103 context.checking(new Expectations() {104 {105 exactly(1).of(mr).execute(cell);106 exactly(1).of(mr).getPossibleTargets();107 exactly(1).of(mr).isDirectExecute();108 exactly(1).of(mr).isMoveCompleted();109 exactly(1).of(mr).move(cell, cell2);110 exactly(1).of(mr).selectTargetCell(cell, targets);111 exactly(1).of(mr).setComputation(c);112 exactly(1).of(mr).setDirectExecute(true);113 exactly(1).of(mr).setEvacuationState(es);114 exactly(1).of(mr).swap(cell, cell2);115 }116 });117 rule.execute(cell);118 rule.getPossibleTargets();119 rule.isDirectExecute();120 rule.isMoveCompleted();121 rule.move(cell, cell2);122 rule.selectTargetCell(cell, targets);123 rule.setComputation(c);124 rule.setDirectExecute(true);125 rule.setEvacuationState(es);126 rule.swap(cell, cell2);127 128 context.assertIsSatisfied();...

Full Screen

Full Screen

Source:ReactionRuleOnePersonTest.java Github

copy

Full Screen

...50 IndividualProperty ip = new IndividualProperty(i);51 cell.getState().setIndividual(i);52 assertThat(ip.isAlarmed(), is(false));53 context.checking(new Expectations() {{54 exactly(1).of(es).getTimeStep();55 will(returnValue(0));56 allowing(es).propertyFor(i);57 will(returnValue(ip));58 }});59 ReactionAction a = rule.execute(cell).get();60 assertThat(a.getIndividuals(), contains(i));61 }62 63 @Test64 public void alertLate() {65 ReactionRuleOnePerson rule = new ReactionRuleOnePerson();66 rule.setEvacuationState(es);67 // We need an absolute max speed of 0.41 to pass the following assertions, i.e. after 7 steps the individual is activated68 EvacuationSimulationSpeed sp = new EvacuationSimulationSpeed(0.41);69 rule.setEvacuationSimulationSpeed(sp);70 RoomCell cell = new RoomCell(0, 0);71 Individual evacuee = INDIVIDUAL_BUILDER.withAge(0).withReactionTime(7).buildAndReset();72 IndividualProperty ip = new IndividualProperty(evacuee);73 cell.getState().setIndividual(evacuee);74 75 assertThat(ip.isAlarmed(), is(false));76 context.checking(new Expectations() {{77 exactly(1).of(es).getTimeStep();78 will(returnValue(0));79 allowing(es).propertyFor(evacuee);80 will(returnValue(ip));81 }});82 Optional<ReactionAction> noAction = rule.execute(cell);83 assertThat(noAction.isPresent(), is(false));84 85 context.checking(new Expectations() {{86 exactly(1).of(es).getTimeStep();87 will(returnValue(0));88 }});89 rule.execute(cell);90 for( int i = 0; i < 7; ++i) {91 final int result = i+1;92 context.checking(new Expectations() {{93 exactly(1).of(es).getTimeStep();94 will(returnValue(result));95 }});96 noAction = rule.execute(cell);97 assertThat(noAction.isPresent(), is(false));98 }99 // Individuals reaction time is 7 100 // one additional time steps sets time to 7.175101 context.checking(new Expectations() {{102 exactly(1).of(es).getTimeStep();103 will(returnValue(8));104 }});105 ReactionAction a = rule.execute(cell).get();106 assertThat(a.getIndividuals(), contains(evacuee));107 }108 @Before109 public void initEvacuationProblem() {110 es = context.mock(EvacuationState.class);111 eca = new MultiFloorEvacuationCellularAutomaton();112 context.checking(new Expectations() {{113 allowing(es).getCellularAutomaton();114 will(returnValue(eca));115 }});116 }...

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mockery;2import org.jmock.Expectations;3import org.jmock.lib.legacy.ClassImposteriser;4import org.jmock.integration.junit4.JUnit4Mockery;5import org.junit.Test;6import org.junit.Before;7import org.junit.After;8import static org.junit.Assert.*;9public class 1Test {10 private Mockery context = new JUnit4Mockery() {{11 setImposteriser(ClassImposteriser.INSTANCE);12 }};13 private 1 mock1 = context.mock(1.class);14 public void setUp() {15 context.checking(new Expectations() {{16 exactly(1).of (mock1).foo(); will(returnValue("foo"));17 }});18 }19 public void test_1() {20 String result = mock1.foo();21 assertEquals("foo", result);22 }23 public void tearDown() {24 context.assertIsSatisfied();25 }26}27import org.jmock.Mockery;28import org.jmock.Expectations;29import org.jmock.lib.legacy.ClassImposteriser;30import org.jmock.integration.junit4.JUnit4Mockery;31import org.junit.Test;32import org.junit.Before;33import org.junit.After;34import static org.junit.Assert.*;35public class 2Test {36 private Mockery context = new JUnit4Mockery() {{37 setImposteriser(ClassImposteriser.INSTANCE);38 }};39 private 2 mock2 = context.mock(2.class);40 public void setUp() {41 context.checking(new Expectations() {{42 exactly(1).of (mock2).foo(); will(returnValue("foo"));43 }});44 }45 public void test_2() {46 String result = mock2.foo();47 assertEquals("foo", result);48 }49 public void tearDown() {50 context.assertIsSatisfied();51 }52}53import org.jmock.Mockery;54import org.jmock.Expectations;55import org.jmock.lib.legacy.ClassImposteriser;56import org.jmock.integration.junit4.JUnit4Mockery;57import org.junit.Test;58import org.junit.Before;59import org.junit.After;60import static org.junit.Assert.*;

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1import org.jmock.Expectations;2import org.jmock.Mockery;3import org.jmock.integration.junit4.JUnit4Mockery;4import org.jmock.lib.legacy.ClassImposteriser;5import org.junit.Test;6public class Test1 {7 public void test1() {8 Mockery context = new JUnit4Mockery() {9 {10 setImposteriser(ClassImposteriser.INSTANCE);11 }12 };13 final Interface1 mock = context.mock(Interface1.class);14 context.checking(new Expectations() {15 {16 exactly(1).of(mock).method1();17 exactly(2).of(mock).method2();18 exactly(3).of(mock).method3();19 }20 });21 mock.method1();22 mock.method2();23 mock.method2();24 mock.method3();25 mock.method3();26 mock.method3();27 }28}29import org.jmock.Expectations;30import org.jmock.Mockery;31import org.jmock.integration.junit4.JUnit4Mockery;32import org.jmock.lib.legacy.ClassImposteriser;33import org.junit.Test;34public class Test2 {35 public void test1() {36 Mockery context = new JUnit4Mockery() {37 {38 setImposteriser(ClassImposteriser.INSTANCE);39 }40 };41 final Interface1 mock = context.mock(Interface1.class);42 context.checking(new Expectations() {43 {44 exactly(1).of(mock).method1();45 exactly(2).of(mock).method2();46 exactly(3).of(mock).method3();47 }48 });49 mock.method1();50 mock.method2();51 mock.method2();52 mock.method3();53 mock.method3();54 mock.method3();55 }56}57import org.jmock.Expectations;58import org.jmock.Mockery;59import org.jmock.integration.junit4.JUnit4Mockery;60import org.jmock.lib.legacy.ClassImposteriser;61import org.junit.Test;62public class Test3 {63 public void test1() {64 Mockery context = new JUnit4Mockery() {65 {66 setImposteriser(ClassImposteriser.INSTANCE);

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mockery;2import org.jmock.Expectations;3import org.jmock.States;4import org.jmock.Sequence;5import org.jmock.integration.junit4.JUnit4Mockery;6import org.jmock.lib.concurrent.DeterministicExecutor;7import org.jmock.lib.concurrent.Synchroniser;8import org.jmock.lib.legacy.ClassImposteriser;9import org.jmock.lib.concurrent.DeterministicScheduler;10import org.jmock.lib.legacy.ClassImposteriser;11import org.jmock.Mockery;12import org.jmock.Expectations;13import org.jmock.States;14import org.jmock.Sequence;15import org.jmock.integration.junit4.JUnit4Mockery;16import org.jmock.lib.concurrent.DeterministicExecutor;17import org.jmock.lib.concurrent.Synchroniser;18import org.jmock.lib.legacy.ClassImposteriser;19import org.jmock.lib.concurrent.DeterministicScheduler;20import org.jmock.lib.legacy.ClassImposteriser;21import org.jmock.Mockery;22import org.jmock.Expectations;23import org.jmock.States;24import org.jmock.Sequence;25import org.jmock.integration.junit4.JUnit4Mockery;26import org.jmock.lib.concurrent.DeterministicExecutor;27import org.jmock.lib.concurrent.Synchroniser;28import org.jmock.lib.legacy.ClassImposteriser;29import org.jmock.lib.concurrent.DeterministicScheduler;30import org.jmock.lib.legacy.ClassImposteriser;31import org.jmock.Mockery;32import org.jmock.Expectations;33import org.jmock.States;34import org.jmock.Sequence;35import org.jmock.integration.junit4.JUnit4Mockery;36import org.jmock.lib.concurrent.DeterministicExecutor;37import org.jmock.lib.concurrent.Synchroniser;38import org.jmock.lib.legacy.ClassImposteriser;39import org.jmock.lib.concurrent.DeterministicScheduler;40import org.jmock.lib.legacy.ClassImposteriser;41import org.jmock.Mockery;42import org.jmock.Expectations;43import org.jmock.States;44import org.jmock.Sequence;45import org.jmock.integration.junit4.JUnit4Mockery;46import org.jmock.lib.concurrent.DeterministicExecutor;47import org.jmock.lib.concurrent.Synchroniser;48import org.jmock.lib.legacy.ClassImposteriser;49import org.jmock.lib.concurrent.DeterministicScheduler;50import org.jmock.lib.legacy.ClassImposteriser;51import org.jmock.Mockery;52import org.jmock.Expectations;53import org.jmock

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1package org.jmock.example;2import java.util.ArrayList;3import java.util.List;4import org.jmock.Expectations;5import org.jmock.Mockery;6import org.jmock.Sequence;7import org.jmock.States;8import org.jmock.integration.junit4.JUnitRuleMockery;9import org.jmock.lib.concurrent.Synchroniser;10import org.junit.Rule;11import org.junit.Test;12public class TestJMock {13 public Mockery context = new JUnitRuleMockery() {14 {15 setThreadingPolicy(new Synchroniser());16 }17 };18 public void testJMock() throws Exception {19 final List<String> mockedList = context.mock(List.class);20 final Sequence sequence = context.sequence("sequence");21 final States states = context.states("states").startsAs("one");22 context.checking(new Expectations() {23 {24 oneOf(mockedList).add("once");25 will(returnValue(true));26 oneOf(mockedList).add("twice");27 will(returnValue(true));28 oneOf(mockedList).add("twice");29 will(returnValue(true));30 exactly(2).of(mockedList).add("three times");31 will(returnValue(true));32 exactly(3).of(mockedList).add("four times");33 will(returnValue(true));34 inSequence(sequence).add("in sequence");35 inSequence(sequence).add("in sequence");36 inSequence(sequence).add("in sequence");37 atLeast(1).of(mockedList).add("at least once");38 will(returnValue(true));39 atLeast(2).of(mockedList).add("at least twice");40 will(returnValue(true));41 atLeast(3).of(mockedList).add("at least three times");42 will(returnValue(true));43 atLeast(4).of(mockedList).add("at least four times");44 will(returnValue(true));45 atMost(1).of(mockedList).add("at most once");46 will(returnValue(true));47 atMost(2).of(mockedList).add("at most twice");48 will(returnValue(true));49 atMost(3).of(mockedList).add("at most three times");

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.acceptance;2import org.jmock.Mockery;3import org.jmock.Expectations;4import org.jmock.Sequence;5import org.jmock.Mockery;6import org.jmock.api.ExpectationError;7import org.jmock.api.Invocation;8import org.jmock.api.Invokable;9import org.jmock.lib.action.CustomAction;10import org.jmock.lib.action.ReturnValueAction;11import org.jmock.lib.action.ThrowAction;12import org.jmock.lib.legacy.ClassImposteriser;13import org.jmock.test.unit.support.MethodFactory;14import org.jmock.test.unit.support.MethodFactory.MethodSelector;15import org.junit.Assert;16import org.junit.Test;17import java.lang.reflect.Method;18import java.util.ArrayList;19import java.util.Arrays;20import java.util.List;21import static org.hamcrest.Matchers.*;22import static org.jmock.Expectations.*;23import static org.jmock.lib.legacy.ClassImposteriser.INSTANCE;24public class ExactlyAcceptanceTests {25 Mockery context = new Mockery();26 Sequence sequence = context.sequence("sequence");27 List<String> log = new ArrayList<String>();28 public interface TypeA {29 void doSomething();30 }31 public interface TypeB {32 void doSomething();33 }34 public void canUseExactlyWithZeroOccurrences() {35 final TypeA mock = context.mock(TypeA.class, "mock");36 context.checking(new Expectations() {{37 exactly(0).of (mock).doSomething();38 }});39 }40 public void canUseExactlyWithOneOccurrence() {41 final TypeA mock = context.mock(TypeA.class, "mock");42 context.checking(new Expectations() {{43 exactly(1).of (mock).doSomething();44 }});45 mock.doSomething();46 }47 public void canUseExactlyWithTwoOccurrences() {48 final TypeA mock = context.mock(TypeA.class, "mock");49 context.checking(new Expectations() {{50 exactly(2).of (mock).doSomething();51 }});52 mock.doSomething();53 mock.doSomething();54 }55 public void canUseExactlyWithThreeOccurrences() {56 final TypeA mock = context.mock(TypeA.class, "mock");57 context.checking(new Expectations() {{58 exactly(3).of (mock).doSomething();59 }});60 mock.doSomething();61 mock.doSomething();

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1package com.jmock;2import org.jmock.Expectations;3import org.jmock.Mockery;4import org.jmock.Sequence;5import org.jmock.States;6import org.jmock.lib.legacy.ClassImposteriser;7public class TestJMock {8 public static void main(String[] args) {9 Mockery context = new Mockery();10 context.setImposteriser(ClassImposteriser.INSTANCE);11 final Service service = context.mock(Service.class);12 final States state = context.states("state");13 final Sequence sequence = context.sequence("sequence");14 context.checking(new Expectations() {15 {16 exactly(2).of(service).doSomething();17 when(state.is("state1"));18 will(state.is("state2"));19 exactly(2).of(service).doSomething();20 when(state.is("state2"));21 will(state.is("state1"));22 exactly(1).of(service).doSomething();23 when(state.is("state1"));24 inSequence(sequence);25 exactly(1).of(service).doSomething();26 when(state.is("state2"));27 inSequence(sequence);28 }29 });30 service.doSomething();31 service.doSomething();32 service.doSomething();33 service.doSomething();34 context.assertIsSatisfied();35 }36}37package com.jmock;38import org.jmock.Expectations;39import org.jmock.Mockery;40import org.jmock.Sequence;41import org.jmock.States;42import org.jmock.lib.legacy.ClassImposteriser;43public class TestJMock {44 public static void main(String[] args) {45 Mockery context = new Mockery();46 context.setImposteriser(ClassImposteriser.INSTANCE);47 final Service service = context.mock(Service.class);48 final States state = context.states("state");49 final Sequence sequence = context.sequence("sequence");50 context.checking(new Expectations() {51 {52 exactly(2).of(service).doSomething();53 when(state.is("state1"));54 will(state.is("state2"));55 exactly(2).of(service).doSomething();56 when(state.is("state2"));57 will(state.is("state1"));58 exactly(1).of(service).doSomething();59 when(state.is("state1"));60 inSequence(sequence);61 exactly(1).of(service).doSomething();62 when(state.is("state2"));

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mock;2import org.jmock.MockObjectTestCase;3import org.jmock.core.constraint.IsEqual;4import org.jmock.core.constraint.IsSame;5import org.jmock.core.constraint.IsAnything;6import org.jmock.core.constraint.IsInstanceOf;7import org.jmock.core.constraint.IsIn;8import org.jmock.core.constraint.IsNot;9import org.jmock.core.constraint.IsLessThan;10import org.jmock.core.constraint.IsGreaterThan;11import org.jmock.core.constraint.IsLessThanOrEqual;12import org.jmock.core.constraint.IsGreaterThanOrEqual;13import org.jmock.core.constraint.IsBetween;14import org.jmock.core.constraint.IsCollectionContaining;15import org.jmock.core.constraint.IsStringContaining;16import org.jmock.core.constraint.IsStringStarting;17import org.jmock.core.constraint.IsStringEnding;18import org.jmock.core.constraint.IsStringMatching;19import org.jmock.core.constraint.IsArrayContaining;20import org.jmock.core.constraint.IsArrayContainingInOrder;21import org.jmock.core.constraint.IsArrayContainingInAnyOrder;22import org.jmock.core.constraint.IsArrayMatching;23import org.jmock.core.constraint.IsMapContaining;24import org.jmock.core.constraint.IsMapContainingKey;25import org.jmock.core.constraint.IsMapContainingValue;26import org.jmock.core.constraint.IsMapMatching;27import org.jmock.core.constraint.IsCollectionMatching;28import org.jmock.core.constraint.IsEqualList;29import org.jmock.core.constraint.IsEqualSet;30import org.jmock.core.constraint.IsEqualMap;31import org.jmock.core.constraint.IsEqualArray;32import org.jmock.core.constraint.IsEqualSequence;33import org.jmock.core.constraint.IsEqualIterator;34import org.jmock.core.constraint.IsEqualEnumeration;35import org.jmock.core.constraint.IsEqualCollection;36import org.jmock.core.constraint.IsEqualComparable;37import org.jmock.core.constraint.IsEqualComparableArray;38import org.jmock.core.constraint.IsEqualComparableCollection;39import org.jmock.core.constraint.IsEqualComparableList;40import org.jmock.core.constraint.IsEqualComparableSet;41import org.jmock.core.constraint.IsEqualComparableSequence;42import org.jmock.core.constraint.IsEqualComparableIterator;43import org.jmock.core.constraint.IsEqualComparableEnumeration;44import org.jmock.core.constraint.IsEqualComparableMap;45import org.jmock.core.constraint.IsEqualComparableArrayInAnyOrder;46import org.jmock.core.constraint.IsEqualComparableArrayInOrder;47import org.jmock.core.constraint.IsEqualComparableCollectionIn

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1package org.jmock;2public class AbstractExpectations {3 public static void exactly(int count, Object mockObject) {4 }5}6package org.jmock;7import org.jmock.AbstractExpectations;8public class AbstractExpectationsTest {9 public static void main(String[] args) {10 AbstractExpectations.exactly(2, new Object());11 }12}13package org.jmock;14import org.jmock.AbstractExpectations;15public class AbstractExpectationsTest {16 public static void main(String[] args) {17 AbstractExpectations.exactly(2, new Object());18 }19}

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.acceptance;2import org.jmock.Mock;3import org.jmock.MockObjectTestCase;4public class MaxInvocationsTest extends MockObjectTestCase {5 public void testMaxInvocations() {6 Mock mockMap = mock(Map.class);7 mockMap.expects(once()).method("get").with(eq("key1")).will(returnValue("value1"));8 mockMap.expects(exactly(3)).method("get").with(eq("key2")).will(returnValue("value2"));9 mockMap.expects(atLeastOnce()).method("get").with(eq("key3")).will(returnValue("value3"));10 mockMap.expects(atLeast(2)).method("get").with(eq("key4")).will(returnValue("value4"));11 mockMap.expects(atMost(2)).method("get").with(eq("key5")).will(returnValue("value5"));12 mockMap.expects(never()).method("get").with(eq("key6")).will(returnValue("value6"));13 mockMap.expects(atLeast(2)).method("get").with(eq("key7")).will(returnValue("value7"));14 mockMap.expects(atLeast(2)).method("get").with(eq("key8")).will(returnValue("value8"));15 mockMap.expects(atLeast(2)).method("get").with(eq("key9")).will(returnValue("value9"));16 mockMap.expects(once()).method("get").with(eq("key10")).will(returnValue("value10"));17 mockMap.expects(once()).method("get").with(eq("key11")).will(returnValue("value11"));18 mockMap.expects(once()).method("get").with(eq("key12")).will(returnValue("value12"));19 mockMap.expects(once()).method("get").with(eq("key13")).will(returnValue("value13"));20 mockMap.expects(once()).method("get").with(eq("key14")).will(returnValue("value14"));21 mockMap.expects(once()).method("get").with(eq("key15")).will(returnValue("value15"));22 mockMap.expects(once()).method("get").with(eq("key16")).will(returnValue("value16"));

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful