How to use getControl method of org.easymock.tests.Util class

Best Easymock code snippet using org.easymock.tests.Util.getControl

Source:HiveMindTestCase.java Github

copy

Full Screen

...360 * <p>361 * This method is not deprecated, but is rarely used; typically {@link #newMock(Class)} is used362 * to create the control and the mock, and {@link #setReturnValue(Object, Object)} and363 * {@link #setThrowable(Object, Throwable)} are used to while training it.364 * {@link #getControl(Object)} is used for the rare cases where the MockControl itself is365 * needed.366 */367 protected MockControl newControl(Class mockClass)368 {369 MockControlFactory factory = mockClass.isInterface() ? _interfaceMockControlFactory370 : _classMockControlFactory;371 MockControl result = factory.newControl(mockClass);372 addControl(result);373 return result;374 }375 /**376 * Accesses the control for a previously created mock object. Iterates over the list of managed377 * controls until one is found whose mock object identity equals the mock object provided.378 * 379 * @param mock380 * object whose control is needed381 * @return the corresponding MockControl if found382 * @throws IllegalArgumentException383 * if not found384 * @since 1.1385 */386 protected MockControl getControl(Object mock)387 {388 Iterator i = _controls.iterator();389 while (i.hasNext())390 {391 MockControl control = (MockControl) i.next();392 if (control.getMock() == mock)393 return control;394 }395 throw new IllegalArgumentException(mock396 + " is not a mock object controlled by any registered MockControl instance.");397 }398 /**399 * Invoked when training a mock object to set the Throwable for the most recently invoked400 * method.401 * 402 * @param mock403 * the mock object being trained404 * @param t405 * the exception the object should throw when it replays406 * @since 1.1407 */408 protected void setThrowable(Object mock, Throwable t)409 {410 getControl(mock).setThrowable(t);411 }412 /**413 * Invoked when training a mock object to set the return value for the most recently invoked414 * method. Overrides of this method exist to support a number of primitive types.415 * 416 * @param mock417 * the mock object being trained418 * @param returnValue419 * the value to return from the most recently invoked methods420 * @since 1.1421 */422 protected void setReturnValue(Object mock, Object returnValue)423 {424 getControl(mock).setReturnValue(returnValue);425 }426 /**427 * Invoked when training a mock object to set the return value for the most recently invoked428 * method. Overrides of this method exist to support a number of primitive types.429 * 430 * @param mock431 * the mock object being trained432 * @param returnValue433 * the value to return from the most recently invoked methods434 * @since 1.1435 */436 protected void setReturnValue(Object mock, long returnValue)437 {438 getControl(mock).setReturnValue(returnValue);439 }440 /**441 * Invoked when training a mock object to set the return value for the most recently invoked442 * method. Overrides of this method exist to support a number of primitive types.443 * 444 * @param mock445 * the mock object being trained446 * @param returnValue447 * the value to return from the most recently invoked methods448 * @since 1.1449 */450 protected void setReturnValue(Object mock, float returnValue)451 {452 getControl(mock).setReturnValue(returnValue);453 }454 /**455 * Invoked when training a mock object to set the return value for the most recently invoked456 * method. Overrides of this method exist to support a number of primitive types.457 * 458 * @param mock459 * the mock object being trained460 * @param returnValue461 * the value to return from the most recently invoked methods462 * @since 1.1463 */464 protected void setReturnValue(Object mock, double returnValue)465 {466 getControl(mock).setReturnValue(returnValue);467 }468 /**469 * Invoked when training a mock object to set the return value for the most recently invoked470 * method. Overrides of this method exist to support a number of primitive types.471 * 472 * @param mock473 * the mock object being trained474 * @param returnValue475 * the value to return from the most recently invoked methods476 * @since 1.1477 */478 protected void setReturnValue(Object mock, boolean returnValue)479 {480 getControl(mock).setReturnValue(returnValue);481 }482 /**483 * Adds the control to the list of managed controls used by {@link #replayControls()} and484 * {@link #verifyControls()}.485 */486 protected void addControl(MockControl control)487 {488 _controls.add(control);489 }490 /**491 * Convienience for invoking {@link #newControl(Class)} and then invoking492 * {@link MockControl#getMock()} on the result.493 */494 protected Object newMock(Class mockClass)...

Full Screen

Full Screen

Source:TestMockAbstractBbTableMasterForm.java Github

copy

Full Screen

...132 final ActionCommand newFormObjectCommand = masterForm.getNewFormObjectCommand();133 final ActionCommand saveCommand = masterForm.getSaveCommand();134 final String property = "name";135 final ValueModel valueModel = childForm.getFormModel().getValueModel(property);136 final JTextField nameComponent = ((JTextField) SwingUtils.getDescendantNamed(property, childForm.getControl()));137 // (1). Begin new person creation138 SwingUtils.runInEventDispatcherThread(newFormObjectCommand);139 // Record expected behaviour140 final String nameBeforeInsert = "nameBeforeInsert";141 final String nameAfterInsert = "nameAfterInsert";142 final String nameAfterUpdate = "nameAfterUpdate";143 final Person personBeforeInsert = (Person) childForm.getFormObject();144 final Person personAfterInsert = Person.createPerson(nameAfterInsert);145 final Person personAfterUpdate = Person.createPerson(nameAfterUpdate);146 EasyMock.expect(mockPersonService.insertPerson(personBeforeInsert)).andReturn(personAfterInsert);147 EasyMock.expect(mockPersonService.updatePerson(personAfterInsert)).andReturn(personAfterUpdate);148 this.iMocksControl.replay();149 // (2). Change name150 this.userAction(childForm, property, nameBeforeInsert);151 // (3). Insert person and make assertions152 SwingUtils.runInEventDispatcherThread(saveCommand);153 TestCase.assertEquals(personAfterInsert, childForm.getFormObject());154 TestCase.assertEquals(nameAfterInsert, valueModel.getValue());155 TestCase.assertEquals(nameAfterInsert, nameComponent.getText());156 // (4). Change name again157 this.userAction(childForm, property, nameBeforeInsert);158 // (5). Update person and make assertions159 SwingUtils.runInEventDispatcherThread(saveCommand);160 TestCase.assertEquals(personAfterUpdate, childForm.getFormObject());161 TestCase.assertEquals(nameAfterUpdate, valueModel.getValue());162 TestCase.assertEquals(nameAfterUpdate, nameComponent.getText());163 }164 /**165 * Tests the correct behaviour of selection change ensuring raised operations (<code>doRefresh</code>) are expected.166 */167 @Test168 public void testRefreshCommandAfterSelectionChange() {169 final PersonMasterForm masterForm = (PersonMasterForm) FormUtils.getBackingForm(this.getMasterView());170 final PersonSearchForm searchForm = (PersonSearchForm) FormUtils.getBackingForm(this.getSearchView());171 final PersonChildForm childForm = (PersonChildForm) FormUtils.getBackingForm(this.getChildView());172 final PersonService mockPersonService = masterForm.getPersonService();173 final ActionCommand searchCommand = searchForm.getSearchCommand();174 final String property = "name";175 final ValueModel valueModel = childForm.getFormModel().getValueModel(property);176 final JTextField nameComponent = ((JTextField) SwingUtils.getDescendantNamed(property, childForm.getControl()));177 // Record expected behaviour178 final String nameAfterRefresh = "nameAfterRefresh";179 final Person personAfterRefresh = Person.createPerson(nameAfterRefresh);180 final List<Person> searchResults = TestMockAbstractBbTableMasterForm.PERSONS_1;181 final Person personToSelect = searchResults.get(0);182 EasyMock.expect(mockPersonService.searchPersons((Person) searchForm.getFormObject())).andReturn(searchResults);183 EasyMock.expect(mockPersonService.refreshPerson(personToSelect)).andReturn(personAfterRefresh);184 this.iMocksControl.replay();185 // (1). Begin new person creation186 SwingUtils.runInEventDispatcherThread(searchCommand);187 // (2). Change selection and make assertions188 masterForm.changeSelection(Arrays.asList(personToSelect));189 TestCase.assertTrue(ListUtils.isEqualList(Arrays.asList(personAfterRefresh), masterForm.getSelection()));190 TestCase.assertEquals(personAfterRefresh, childForm.getFormObject());191 TestCase.assertEquals(nameAfterRefresh, valueModel.getValue());192 TestCase.assertEquals(nameAfterRefresh, nameComponent.getText());193 }194 /**195 * Tests the correct behaviour of refresh command.196 */197 @Test198 public void testRefreshCommand() {199 final PersonMasterForm masterForm = (PersonMasterForm) FormUtils.getBackingForm(this.getMasterView());200 final PersonSearchForm searchForm = (PersonSearchForm) FormUtils.getBackingForm(this.getSearchView());201 final PersonChildForm childForm = (PersonChildForm) FormUtils.getBackingForm(this.getChildView());202 final PersonService mockPersonService = masterForm.getPersonService();203 final ActionCommand searchCommand = searchForm.getSearchCommand();204 final ActionCommand refreshCommand = masterForm.getRefreshCommand();205 final String property = "name";206 final ValueModel valueModel = childForm.getFormModel().getValueModel(property);207 final JTextField nameComponent = ((JTextField) SwingUtils.getDescendantNamed(property, childForm.getControl()));208 // Record expected behaviour209 final String nameAfter1stRefresh = "nameAfter1stRefresh";210 final String nameAfter2ndRefresh = "nameAfter2ndRefresh";211 final Person personAfter1stRefresh = Person.createPerson(nameAfter1stRefresh);212 final Person personAfter2ndRefresh = Person.createPerson(nameAfter2ndRefresh);213 final List<Person> searchResults = TestMockAbstractBbTableMasterForm.PERSONS_1;214 final Person personToSelect = searchResults.get(0);215 EasyMock.expect(mockPersonService.searchPersons((Person) searchForm.getFormObject())).andReturn(searchResults);216 EasyMock.expect(mockPersonService.refreshPerson(personToSelect)).andReturn(personAfter1stRefresh);217 EasyMock.expect(mockPersonService.refreshPerson(personAfter1stRefresh)).andReturn(personAfter2ndRefresh);218 this.iMocksControl.replay();219 // (1). Begin new person creation220 SwingUtils.runInEventDispatcherThread(searchCommand);221 // (2). Change selection and make assertions...

Full Screen

Full Screen

Source:ThredweaverMultithreadedLiftTest.java Github

copy

Full Screen

...3132 @ThreadedTest33 public void testConcurrentInvocation2() {34 MethodRecorder<Lift> recorder = new MethodRecorder<Lift>(Lift.class);35 Lift lift = recorder.getControl();36 lift.moveLift();37 recorder.inLastMethod();38 Door door = recorder.createTarget(Door.class);39 door.open(5);40 CodePosition afterDoorOpenedAt5 = recorder.beforeCallingLastMethod().position();4142 RunResult result = InterleavedRunner.interleave(new MultithreadedLiftMainRunnable(),43 new MultithreadedLifSecondaryRunnableImpl(), Arrays.asList(afterDoorOpenedAt5));44 result.throwExceptionsIfAny();45 }4647 private static class MultithreadedLifSecondaryRunnableImpl extends SecondaryRunnableImpl<Lift, MultithreadedLiftMainRunnable> {48 private Lift lift;49 ...

Full Screen

Full Screen

getControl

Using AI Code Generation

copy

Full Screen

1package org.easymock.tests;2import org.easymock.internal.MocksControl;3public class Util {4 public static MocksControl getControl(Object mock) {5 return (MocksControl) mock;6 }7}8package org.easymock.tests;9public class UtilTest extends AbstractMockControlTest {10 public void testGetControl() {11 assertSame(getControl(), Util.getControl(getMock()));12 }13}14package org.easymock.tests;15import org.easymock.internal.MocksControl;16public class AbstractMockControlTest {17 private final MocksControl control = new MocksControl();18 private final MockedType mock = (MockedType) control.createMock(MockedType.class);19 protected MocksControl getControl() {20 return control;21 }22 protected MockedType getMock() {23 return mock;24 }25}26package org.easymock.tests;27public interface MockedType {28}

Full Screen

Full Screen

getControl

Using AI Code Generation

copy

Full Screen

1package org.easymock.tests;2import org.easymock.classextension.EasyMock;3public class Util {4 public static org.easymock.classextension.IMocksControl getControl(Object mock){5 return EasyMock.getControl(mock);6 }7}8package org.easymock.tests;9import org.easymock.classextension.IMocksControl;10import org.easymock.classextension.EasyMock;11public class TestUtil {12 public void test1(){13 IMocksControl control = EasyMock.createControl();14 IMethods mock = control.createMock(IMethods.class);15 mock.simpleMethod();16 control.replay();17 mock.simpleMethod();18 control.verify();19 }20 public void test2(){21 IMethods mock = EasyMock.createMock(IMethods.class);22 mock.simpleMethod();23 EasyMock.replay(mock);24 mock.simpleMethod();25 org.easymock.tests.Util.getControl(mock).verify();26 }27}28java.lang.AssertionError: Unexpected method call IMethods.simpleMethod():29 IMethods.simpleMethod();30 at org.easymock.internal.MocksControl.verify(MocksControl.java:123)31 at org.easymock.tests.TestUtil.test2(TestUtil.java:23)

Full Screen

Full Screen

getControl

Using AI Code Generation

copy

Full Screen

1package org.easymock.tests;2import org.easymock.classextension.IMocksControl;3import org.easymock.classextension.MockClassControl;4import org.junit.Assert;5import org.junit.Test;6public class UtilTest {7 public void testOrder() {8 IMocksControl control = MockClassControl.createControl(IMethods.class);9 IMethods mock = (IMethods) control.getMock();10 mock.oneArg('a');11 mock.oneArg('b');12 mock.oneArg('c');13 control.checkOrder(true);14 control.replay();15 mock.oneArg('a');16 mock.oneArg('b');17 mock.oneArg('c');18 control.verify();19 }20 public void testOrderFail() {21 IMocksControl control = MockClassControl.createControl(IMethods.class);22 IMethods mock = (IMethods) control.getMock();23 mock.oneArg('a');24 mock.oneArg('b');25 mock.oneArg('c');26 control.checkOrder(true);27 control.replay();28 mock.oneArg('b');29 mock.oneArg('a');30 mock.oneArg('c');31 try {32 control.verify();33 Assert.fail();34 } catch (AssertionError e) {35 }36 }37 public void testOrderFail2() {38 IMocksControl control = MockClassControl.createControl(IMethods.class);39 IMethods mock = (IMethods) control.getMock();40 mock.oneArg('a');41 mock.oneArg('b');42 mock.oneArg('c');43 control.checkOrder(true);44 control.replay();45 mock.oneArg('a');46 mock.oneArg('c');47 mock.oneArg('b');48 try {49 control.verify();50 Assert.fail();51 } catch (AssertionError e) {52 }53 }54 public void testOrderFail3() {55 IMocksControl control = MockClassControl.createControl(IMethods.class);56 IMethods mock = (IMethods) control.getMock();57 mock.oneArg('a');58 mock.oneArg('b');59 mock.oneArg('c');

Full Screen

Full Screen

getControl

Using AI Code Generation

copy

Full Screen

1package org.easymock.tests;2import org.easymock.EasyMock;3public class Util {4 public static IMethods createMock() {5 return (IMethods) EasyMock.createMock(IMethods.class);6 }7 public static IMethods createMock(ClassLoader loader) {8 return (IMethods) EasyMock.createMock(loader, IMethods.class, null);9 }10 public static IMethods createMock(String name) {11 return (IMethods) EasyMock.createMock(IMethods.class, name);12 }13 public static IMethods createMock(ClassLoader loader, String name) {14 return (IMethods) EasyMock.createMock(loader, IMethods.class, name);15 }16 public static IMethods createStrictMock() {17 return (IMethods) EasyMock.createStrictMock(IMethods.class);18 }19 public static IMethods createStrictMock(ClassLoader loader) {20 return (IMethods) EasyMock.createStrictMock(loader, IMethods.class,21 null);22 }23 public static IMethods createStrictMock(String name) {24 return (IMethods) EasyMock.createStrictMock(IMethods.class, name);25 }26 public static IMethods createStrictMock(ClassLoader loader, String name) {27 return (IMethods) EasyMock.createStrictMock(loader, IMethods.class,28 name);29 }30 public static IMethods createNiceMock() {31 return (IMethods) EasyMock.createNiceMock(IMethods.class);32 }33 public static IMethods createNiceMock(ClassLoader loader) {34 return (IMethods) EasyMock.createNiceMock(loader, IMethods.class, null);35 }36 public static IMethods createNiceMock(String name) {37 return (IMethods) EasyMock.createNiceMock(IMethods.class, name);38 }39 public static IMethods createNiceMock(ClassLoader loader, String name) {40 return (IMethods) EasyMock.createNiceMock(loader, IMethods.class, name);41 }42 public static IMethods createControl() {43 return (IMethods) EasyMock.createControl().getMock();44 }45 public static IMethods createControl(ClassLoader loader) {46 return (IMethods) EasyMock.createControl(loader).getMock

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.

Run Easymock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful