How to use Results class of org.easymock.internal package

Best Easymock code snippet using org.easymock.internal.Results

Source:IntegrationTest.java Github

copy

Full Screen

...192 mTest.run(mReporter);193 mReporter.invocationEnded(500);194 EasyMock.verify(mMockDevice, mMockBuildInfo);195 IInvocationResult result = mReporter.getResult();196 assertEquals(2, result.countResults(TestStatus.PASS));197 assertEquals(1, result.countResults(TestStatus.FAIL));198 assertEquals(1, result.getModules().size());199 assertEquals(1, result.getModuleCompleteCount());200 }201 /**202 * Verify that result reporters test run ended callback can receive component name as configured203 * in module config metadata field.204 */205 @Test206 public void testSingleModuleRun_checkMetadata() throws Exception {207 final String moduleName = "AwsomeModule";208 final String mAbi = "arm64-v8a";209 final String component = "CriticalComponent";210 final List<String> receivedComponentsTestEnded = new ArrayList<>();211 final List<String> receivedModuleNameTestEnded = new ArrayList<>();212 final List<String> receivedAbiTestEnded = new ArrayList<>();213 final List<String> receivedComponentsTestRunEnded = new ArrayList<>();214 final List<String> receivedModuleNameTestRunEnded = new ArrayList<>();215 final List<String> receivedAbiTestRunEnded = new ArrayList<>();216 createConfig(mTestDir, moduleName, SIMPLE_TEST_STUB, true, true, true, false, component);217 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);218 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),219 EasyMock.eq(AbiUtils.createId(mAbi, moduleName)));220 EasyMock.expectLastCall();221 EasyMock.replay(mMockDevice, mMockBuildInfo);222 ITestInvocationListener myListener = new ITestInvocationListener() {223 private IInvocationContext myContext;224 @Override225 public void invocationStarted(IInvocationContext context) {226 myContext = context;227 }228 @Override229 public void testRunEnded(long elapsedTimeMillis, HashMap<String, Metric> runMetrics) {230 receivedComponentsTestRunEnded.addAll(myContext.getModuleInvocationContext()231 .getConfigurationDescriptor().getMetaData("component"));232 receivedModuleNameTestRunEnded.addAll(myContext.getModuleInvocationContext()233 .getAttributes().get(IModuleDef.MODULE_NAME));234 receivedAbiTestRunEnded.addAll(myContext.getModuleInvocationContext()235 .getAttributes().get(IModuleDef.MODULE_ABI));236 }237 @Override238 public void testEnded(TestDescription test, long endTime,239 HashMap<String, Metric> testMetrics) {240 receivedComponentsTestEnded.addAll(myContext.getModuleInvocationContext()241 .getConfigurationDescriptor().getMetaData("component"));242 receivedModuleNameTestEnded.addAll(myContext.getModuleInvocationContext()243 .getAttributes().get(IModuleDef.MODULE_NAME));244 receivedAbiTestEnded.addAll(myContext.getModuleInvocationContext()245 .getAttributes().get(IModuleDef.MODULE_ABI));246 }247 };248 myListener.invocationStarted(mContext);249 mTest.run(myListener);250 myListener.invocationEnded(500);251 EasyMock.verify(mMockDevice, mMockBuildInfo);252 // verify metadata was retrieved during testRunEnded callbacks253 assertEquals("[testRunEnded] wrong number of metadata collected",254 1, receivedComponentsTestRunEnded.size());255 assertEquals("[testRunEnded] wrong component metadata field received",256 component, receivedComponentsTestRunEnded.get(0));257 assertEquals("[testRunEnded] wrong number of module name collected",258 1, receivedModuleNameTestRunEnded.size());259 assertEquals(moduleName, receivedModuleNameTestRunEnded.get(0));260 assertEquals("[testEnded] wrong number of module abi collected",261 1, receivedAbiTestRunEnded.size());262 assertEquals(mAbi, receivedAbiTestRunEnded.get(0));263 // verify metadata was retrieved during testEnded callbacks264 assertEquals("[testEnded] wrong number of metadata collected",265 1, receivedComponentsTestEnded.size());266 assertEquals("[testEnded] wrong component metadata field received",267 component, receivedComponentsTestEnded.get(0));268 assertEquals("[testEnded] wrong number of module name collected",269 1, receivedModuleNameTestEnded.size());270 assertEquals(moduleName, receivedModuleNameTestEnded.get(0));271 assertEquals("[testEnded] wrong number of module abi collected",272 1, receivedAbiTestEnded.size());273 assertEquals(mAbi, receivedAbiTestEnded.get(0));274 }275 /**276 * Simple tests running in one module that run some tests but not all of them.277 */278 @Test279 public void testSingleModuleRun_incomplete() throws Exception {280 final String moduleName = "module_run_incomplete";281 final String mAbi = "arm64-v8a";282 createConfig(mTestDir, moduleName, TEST_STUB, true, false, true, false);283 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);284 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),285 EasyMock.eq(AbiUtils.createId(mAbi, moduleName)));286 EasyMock.expectLastCall();287 EasyMock.replay(mMockDevice, mMockBuildInfo);288 mReporter.invocationStarted(mContext);289 mTest.run(mReporter);290 mReporter.invocationEnded(500);291 EasyMock.verify(mMockDevice, mMockBuildInfo);292 IInvocationResult result = mReporter.getResult();293 assertEquals(1, result.countResults(TestStatus.PASS));294 assertEquals(1, result.countResults(TestStatus.FAIL));295 // Module should not be seen as complete.296 assertEquals(1, result.getModules().size());297 assertEquals(0, result.getModuleCompleteCount());298 }299 /**300 * Simple tests running in one module that should be marked complete since it runs all its301 * tests after an internal retry (like InstrumentationTest).302 * FIXME: Fix the expectation of this test303 */304 @Test305 public void testSingleModuleRun_completeAfterInternalRetry() throws Exception {306 final String moduleName = "module_completeAfterRetry";307 final String mAbi = "arm64-v8a";308 createConfig(mTestDir, moduleName, TEST_STUB, true, true, true, true);309 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);310 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),311 EasyMock.eq(AbiUtils.createId(mAbi, moduleName)));312 EasyMock.expectLastCall();313 EasyMock.replay(mMockDevice, mMockBuildInfo);314 mReporter.invocationStarted(mContext);315 mTest.run(mReporter);316 mReporter.invocationEnded(500);317 EasyMock.verify(mMockDevice, mMockBuildInfo);318 IInvocationResult result = mReporter.getResult();319 // FIXME: All tests should be marked as executed and not aggregating the count.320 assertEquals(2, result.countResults(TestStatus.PASS));321 assertEquals(1, result.countResults(TestStatus.FAIL));322 // FIXME: Module should be complete since all its test have run.323 assertEquals(1, result.getModules().size());324 assertEquals(0, result.getModuleCompleteCount());325 }326 /**327 * Simple tests running in one module that run some tests but not all of them, then we328 * attempt to run it again and they still didn't run.329 * FIXME: This test expectation needs to be fixed330 */331 @Test332 public void testSingleModuleRun_incomplete_rerun_incomplete() throws Exception {333 final String moduleName = "module_incomplete_rerun";334 final String mAbi = "arm64-v8a";335 createConfig(mTestDir, moduleName, TEST_STUB, true, false, true, false);336 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);337 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),338 EasyMock.eq(AbiUtils.createId(mAbi, moduleName)));339 EasyMock.expectLastCall();340 // extra calls for retry341 EasyMock.expect(mMockDevice.getProperty("ro.build.fingerprint")).andReturn("fingerprint");342 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);343 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),344 EasyMock.eq(AbiUtils.createId(mAbi, moduleName)));345 EasyMock.expectLastCall();346 mMockBuildInfo.addBuildAttribute(EasyMock.eq("retry_command_line_args"),347 EasyMock.eq(COMMAND_LINE));348 EasyMock.expectLastCall();349 EasyMock.replay(mMockDevice, mMockBuildInfo);350 mReporter.invocationStarted(mContext);351 mTest.run(mReporter);352 mReporter.invocationEnded(500);353 IInvocationResult result = mReporter.getResult();354 assertEquals(1, result.countResults(TestStatus.PASS));355 assertEquals(1, result.countResults(TestStatus.FAIL));356 // Module should not be seen as complete.357 assertEquals(0, result.getModuleCompleteCount());358 // We re-run it359 mReporter = new ResultReporter();360 mTest = new CompatibilityTest() {361 @Override362 protected Set<String> getAbisForBuildTargetArch() {363 Set<String> abis = new HashSet<>();364 abis.add("arm64-v8a");365 return abis;366 }367 };368 mTest.setDevice(mMockDevice);369 mTest.setBuild(mMockBuildInfo);370 mTest.setInvocationContext(mContext);371 OptionSetter setter = new OptionSetter(mTest, mReporter);372 setter.setOptionValue("retry", "0");373 mReporter.invocationStarted(mContext);374 mTest.run(mReporter);375 mReporter.invocationEnded(500);376 EasyMock.verify(mMockDevice, mMockBuildInfo);377 // Check retry results378 result = mReporter.getResult();379 // FIXME: We should only have 1 not_executed in the retry too. They should not aggregate380 // from one run to another.381 assertEquals(1, result.countResults(TestStatus.PASS));382 assertEquals(1, result.countResults(TestStatus.FAIL));383 // Module should not be seen as complete.384 assertEquals(1, result.getModules().size());385 assertEquals(0, result.getModuleCompleteCount());386 }387 /**388 * Simple tests running in one module that run some tests but not all of them, we then attempt389 * to retry run them and this time the not_executed is executed.390 */391 @Test392 public void testSingleModuleRun_incomplete_rerun_complete() throws Exception {393 final String moduleName = "module_incom_rerun_complete";394 final String mAbi = "arm64-v8a";395 createConfig(mTestDir, moduleName, TEST_STUB, true, false, true, false);396 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);397 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),398 EasyMock.eq(AbiUtils.createId(mAbi, moduleName)));399 EasyMock.expectLastCall();400 // extra calls for retry401 EasyMock.expect(mMockDevice.getProperty("ro.build.fingerprint")).andReturn("fingerprint");402 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);403 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),404 EasyMock.eq(AbiUtils.createId(mAbi, moduleName)));405 EasyMock.expectLastCall();406 mMockBuildInfo.addBuildAttribute(EasyMock.eq("retry_command_line_args"),407 EasyMock.eq(COMMAND_LINE));408 EasyMock.expectLastCall();409 EasyMock.replay(mMockDevice, mMockBuildInfo);410 mReporter.invocationStarted(mContext);411 mTest.run(mReporter);412 mReporter.invocationEnded(500);413 IInvocationResult result = mReporter.getResult();414 assertEquals(1, result.countResults(TestStatus.PASS));415 assertEquals(1, result.countResults(TestStatus.FAIL));416 // Module should not be seen as complete.417 assertEquals(0, result.getModuleCompleteCount());418 // We replace the config by one that runs all tests without failures.419 createConfig(mTestDir, moduleName, TEST_STUB, true, true, false, false);420 // Usually configs do not change during the same session so we clear the map to have421 // the new version of the config.422 ((ConfigurationFactory)ConfigurationFactory.getInstance()).clearMapConfig();423 // We re-run it424 mReporter = new ResultReporter();425 mTest = new CompatibilityTest() {426 @Override427 protected Set<String> getAbisForBuildTargetArch() {428 Set<String> abis = new HashSet<>();429 abis.add("arm64-v8a");430 return abis;431 }432 };433 mTest.setDevice(mMockDevice);434 mTest.setBuild(mMockBuildInfo);435 mTest.setInvocationContext(mContext);436 OptionSetter setter = new OptionSetter(mTest, mReporter);437 setter.setOptionValue("retry", "0");438 mReporter.invocationStarted(mContext);439 mTest.run(mReporter);440 mReporter.invocationEnded(500);441 EasyMock.verify(mMockDevice, mMockBuildInfo);442 // Check retry results443 result = mReporter.getResult();444 assertEquals(3, result.countResults(TestStatus.PASS));445 assertEquals(0, result.countResults(TestStatus.FAIL));446 // Module should be marked as complete after retry.447 assertEquals(1, result.getModules().size());448 assertEquals(1, result.getModuleCompleteCount());449 }450 // ***** Case for sharding interaction *****451 /**452 * Helper to create a shard listener with the original reporter as master.453 */454 private ITestInvocationListener getShardListener(ResultReporter masterReporter) {455 List<ITestInvocationListener> shardListeners = new ArrayList<ITestInvocationListener>();456 ShardListener origConfigListener = new ShardListener(masterReporter);457 ResultReporter reporterClone = (ResultReporter) masterReporter.clone();458 shardListeners.add(reporterClone);459 shardListeners.add(origConfigListener);460 ResultForwarder shard = new ResultForwarder(shardListeners);461 return shard;462 }463 /**464 * Helper Thread to run the IShardableTest.465 */466 private class ShardThread extends Thread {467 private IRemoteTest mShardTest;468 private ResultReporter mMasterReporter;469 private IBuildInfo mBuild;470 private ITestDevice mDevice;471 private IInvocationContext mShardContext;472 public ShardThread(IRemoteTest test, ResultReporter masterReporter, IBuildInfo build,473 ITestDevice device, IInvocationContext context) {474 mShardTest = test;475 mMasterReporter = masterReporter;476 mBuild = build;477 mDevice = device;478 mShardContext = context;479 }480 @Override481 public void run() {482 ITestInvocationListener listener = getShardListener(mMasterReporter);483 ((IBuildReceiver)mShardTest).setBuild(mBuild);484 ((IDeviceTest)mShardTest).setDevice(mDevice);485 ((IInvocationContextReceiver)mShardTest).setInvocationContext(mContext);486 listener.invocationStarted(mShardContext);487 try {488 mShardTest.run(listener);489 } catch (DeviceNotAvailableException e) {490 throw new RuntimeException(e);491 } finally {492 listener.invocationEnded(500);493 }494 }495 }496 /**497 * Simple tests running in one module that should be marked complete when each shard run a test498 * from the module. Each Module is going to run 1 pass 1 fail. 2 modules and 2 shards.499 * Using the {@link CompatibilityTest#split()}.500 */501 @Test502 public void testSingleModuleRun_sharded() throws Exception {503 final String moduleName = "module_sharded";504 Set<String> abis = AbiUtils.getAbisForArch(TestSuiteInfo.getInstance().getTargetArch());505 Iterator<String> ite = abis.iterator();506 final String abi1 = ite.next();507 final String abi2 = ite.next();508 createConfig(mTestDir, moduleName, TEST_STUB_SHARDABLE, true, true, true, false);509 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(510 String.format("%s,%s", abi1, abi2));511 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),512 EasyMock.anyObject());513 EasyMock.expectLastCall();514 EasyMock.replay(mMockDevice, mMockBuildInfo);515 OptionSetter setter = new OptionSetter(mTest);516 setter.setOptionValue("shards", "2");517 List<IRemoteTest> tests = (List<IRemoteTest>) mTest.split();518 // We expect 2 shards519 assertEquals(2, tests.size());520 List<ShardThread> threads = new ArrayList<>();521 // Run all shards522 for (IRemoteTest test : tests) {523 ShardThread st = new ShardThread(test, mReporter, mMockBuildInfo, mMockDevice,524 mContext);525 threads.add(st);526 st.start();527 }528 for (ShardThread thread : threads) {529 thread.join(5000);530 }531 // Allow some time for ResultReport to finalize the results coming from the threads.532 boolean finalized = mReporter.waitForFinalized(2, TimeUnit.MINUTES);533 assertTrue(finalized);534 EasyMock.verify(mMockDevice, mMockBuildInfo);535 // Check aggregated results to make sure it's consistent.536 IInvocationResult result = mReporter.getResult();537 assertEquals(4, result.countResults(TestStatus.PASS));538 assertEquals(4, result.countResults(TestStatus.FAIL));539 assertEquals(2, result.getModules().size());540 //assertEquals(2, result.getModuleCompleteCount());541 }542 /**543 * Simple tests running in one module that should be marked incomplete when shards do not544 * complete. Each shard is going to run 1 pass 1 fail 1 not_executed.545 * Using the {@link CompatibilityTest#split()}.546 */547 @Test548 public void testSingleModuleRun_sharded_incomplete() throws Exception {549 final String moduleName = "module_sharded_incomplete";550 Set<String> abis = AbiUtils.getAbisForArch(TestSuiteInfo.getInstance().getTargetArch());551 Iterator<String> ite = abis.iterator();552 final String abi1 = ite.next();553 final String abi2 = ite.next();554 createConfig(mTestDir, moduleName, TEST_STUB_SHARDABLE, true, false, true, false);555 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(556 String.format("%s,%s", abi1, abi2));557 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),558 EasyMock.anyObject());559 EasyMock.expectLastCall();560 EasyMock.replay(mMockDevice, mMockBuildInfo);561 OptionSetter setter = new OptionSetter(mTest);562 setter.setOptionValue("shards", "2");563 List<IRemoteTest> tests = (List<IRemoteTest>) mTest.split();564 // We expect 2 shards565 assertEquals(2, tests.size());566 List<ShardThread> threads = new ArrayList<>();567 // Run all shards568 for (IRemoteTest test : tests) {569 ShardThread st = new ShardThread(test, mReporter, mMockBuildInfo, mMockDevice,570 mContext);571 threads.add(st);572 st.start();573 }574 for (ShardThread thread : threads) {575 thread.join(5000);576 }577 // Allow some time for ResultReport to finalize the results coming from the threads.578 boolean finalized = mReporter.waitForFinalized(2, TimeUnit.MINUTES);579 assertTrue(finalized);580 EasyMock.verify(mMockDevice, mMockBuildInfo);581 // Check aggregated results to make sure it's consistent.582 IInvocationResult result = mReporter.getResult();583 assertEquals(4, result.countResults(TestStatus.PASS));584 assertEquals(4, result.countResults(TestStatus.FAIL));585 assertEquals(2, result.getModules().size());586 assertEquals(0, result.getModuleCompleteCount());587 }588 /**589 * Simple tests running in one module that should be marked complete when each shard run a test590 * from the module.591 * We are going to run only one of the shard since IStrictShardable allows it.592 * Using the {@link CompatibilityTest#getTestShard(int, int)}.593 * FIXME: Fix expectation of this test.594 */595 @Test596 public void testSingleModuleRun_sharded_getTestShard() throws Exception {597 final String moduleName = "module_sharded_getTestShard";598 Set<String> abis = AbiUtils.getAbisForArch(TestSuiteInfo.getInstance().getTargetArch());599 Iterator<String> ite = abis.iterator();600 final String abi1 = ite.next();601 final String abi2 = ite.next();602 createConfig(mTestDir, moduleName, TEST_STUB_SHARDABLE, true, true, true, false);603 EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(604 String.format("%s,%s", abi1, abi2));605 String expectedAdd = AbiUtils.createId(abi1, moduleName) + ","606 + AbiUtils.createId(abi2, moduleName);607 mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),608 EasyMock.anyObject());609 EasyMock.expectLastCall();610 mAttributes.put(CompatibilityBuildHelper.MODULE_IDS, expectedAdd);611 EasyMock.replay(mMockDevice, mMockBuildInfo);612 List<IRemoteTest> tests = new ArrayList<>();613 tests.add(mTest.getTestShard(3, 0));614 // We are only running one of the shards since they should be independent.615 assertEquals(1, tests.size());616 ((IBuildReceiver)tests.get(0)).setBuild(mMockBuildInfo);617 ((IDeviceTest)tests.get(0)).setDevice(mMockDevice);618 ((IInvocationContextReceiver)tests.get(0)).setInvocationContext(mContext);619 mReporter.invocationStarted(mContext);620 try {621 tests.get(0).run(mReporter);622 } catch (DeviceNotAvailableException e) {623 throw new RuntimeException(e);624 } finally {625 mReporter.invocationEnded(500);626 }627 EasyMock.verify(mMockDevice, mMockBuildInfo);628 IInvocationResult result = mReporter.getResult();629 assertEquals(2, result.countResults(TestStatus.PASS));630 assertEquals(2, result.countResults(TestStatus.FAIL));631 // FIXME: Only one module should be expected since within the one shard requested to run632 // only one module existed.633 assertEquals(2, result.getModules().size());634 // FIXME: The module for the shard should be completed since all tests run.635 // TestRunHandler in this case create an expectation of 3 testRunStarted just because of636 // the number of shards.637 assertEquals(0, result.getModuleCompleteCount());638 }639}...

Full Screen

Full Screen

Source:JPQLSelectContextImplTest.java Github

copy

Full Screen

1/*******************************************************************************2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 ******************************************************************************/19package org.apache.olingo.odata2.jpa.processor.core.jpql;20import static org.junit.Assert.assertEquals;21import static org.junit.Assert.assertNull;22import static org.junit.Assert.assertTrue;23import static org.junit.Assert.fail;24import java.util.ArrayList;25import java.util.List;26import org.apache.olingo.odata2.api.edm.EdmEntitySet;27import org.apache.olingo.odata2.api.edm.EdmEntityType;28import org.apache.olingo.odata2.api.edm.EdmException;29import org.apache.olingo.odata2.api.edm.EdmMapping;30import org.apache.olingo.odata2.api.edm.EdmProperty;31import org.apache.olingo.odata2.api.edm.EdmType;32import org.apache.olingo.odata2.api.uri.KeyPredicate;33import org.apache.olingo.odata2.api.uri.SelectItem;34import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;35import org.apache.olingo.odata2.api.uri.expression.FilterExpression;36import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;37import org.apache.olingo.odata2.api.uri.expression.OrderExpression;38import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;39import org.apache.olingo.odata2.api.uri.expression.SortOrder;40import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;41import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;42import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;43import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;44import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;45import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;46import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectContext.JPQLSelectContextBuilder;47import org.easymock.EasyMock;48import org.junit.BeforeClass;49import org.junit.Test;50public class JPQLSelectContextImplTest {51 private static String entityTypeName = "MockEntity";52 private static String[] fields = { "Field1", "Field2" };53 private static List<KeyPredicate> keyPredicates;54 private static SortOrder[] orderType = { SortOrder.asc, SortOrder.desc };55 private static JPQLSelectContextBuilder builder;56 private static JPQLSelectContext selectContext;57 @BeforeClass58 public static void setup() {59 }60 private void buildSelectContext(final boolean orderByIsNull, final boolean selectFieldsIsNull,61 final boolean filterIsNull, final boolean isTopNull, final boolean isSkipNull) {62 builder = null;63 selectContext = null;64 keyPredicates = new ArrayList<KeyPredicate>();65 GetEntitySetUriInfo resultsView = EasyMock.createMock(GetEntitySetUriInfo.class);66 EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);67 EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);68 KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);69 EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);70 EdmType edmType1 = EasyMock.createMock(EdmType.class);71 EdmMapping mapping = EasyMock.createMock(EdmMapping.class);72 EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");73 try {74 EasyMock.expect(mapping.getInternalName()).andStubReturn("Field1");75 EasyMock.expect(kpProperty.getMapping()).andStubReturn(mapping);76 EasyMock.expect(kpProperty.getType()).andStubReturn(edmType1);77 } catch (EdmException e2) {78 fail("this should not happen");79 }80 EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);81 EasyMock.replay(mapping, edmType1, kpProperty, keyPredicate);82 keyPredicates.add(keyPredicate);83 int i = 0;84 List<OrderExpression> orderList = new ArrayList<OrderExpression>(2);85 do {86 EdmType edmType = EasyMock.createMock(EdmType.class);87 try {88 EasyMock.expect(edmType.getName()).andStubReturn(fields[i]);89 EasyMock.replay(edmType);90 } catch (EdmException e2) {91 fail("Exception not Expected");92 }93 PropertyExpression commonExpression = EasyMock.createMock(PropertyExpression.class);94 EasyMock.expect(commonExpression.getKind()).andReturn(ExpressionKind.PROPERTY).anyTimes();95 EasyMock.expect(commonExpression.getEdmType()).andStubReturn(edmType);96 EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);97 EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);98 EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);99 try {100 EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);101 } catch (EdmException e) {102 // TODO Auto-generated catch block103 e.printStackTrace();104 }105 EasyMock.expect(commonExpression.getEdmProperty()).andStubReturn(edmTyped);106 OrderExpression order = EasyMock.createMock(OrderExpression.class);107 EasyMock.expect(order.getExpression()).andStubReturn(commonExpression);108 EasyMock.expect(order.getSortOrder()).andStubReturn(orderType[i]);109 EasyMock.replay(edmMapping, edmTyped, commonExpression);110 EasyMock.replay(order);111 orderList.add(order);112 } while (++i < 2);113 OrderByExpression orderBy = EasyMock.createMock(OrderByExpression.class);114 EasyMock.expect(orderBy.getOrders()).andStubReturn(orderList);115 EasyMock.replay(orderBy);116 try {117 i = 0;118 List<SelectItem> selectItemList = new ArrayList<SelectItem>(2);119 do {120 EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);121 EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);122 EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);123 EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);124 EasyMock.replay(edmMapping, edmProperty);125 SelectItem selectItem = EasyMock.createMock(SelectItem.class);126 EasyMock.expect(selectItem.getProperty()).andStubReturn(edmProperty);127 EasyMock.replay(selectItem);128 selectItemList.add(selectItem);129 } while (++i < 2);130 EasyMock.expect(entityType.getMapping()).andStubReturn(null);131 EasyMock.expect(entityType.getName()).andStubReturn(entityTypeName);132 EasyMock.expect(entityType.getKeyProperties()).andStubReturn(getLocalKeyProperties());133 EasyMock.replay(entityType);134 EasyMock.expect(entitySet.getEntityType()).andStubReturn(entityType);135 EasyMock.replay(entitySet);136 EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);137 if (orderByIsNull) {138 EasyMock.expect(resultsView.getOrderBy()).andStubReturn(null);139 } else {140 EasyMock.expect(resultsView.getOrderBy()).andStubReturn(orderBy);141 }142 if (selectFieldsIsNull) {143 EasyMock.expect(resultsView.getSelect()).andStubReturn(null);144 } else {145 EasyMock.expect(resultsView.getSelect()).andStubReturn(selectItemList);146 }147 // FilterExpression filterExpression =148 // EasyMock.createMock(FilterExpression.class);149 // EasyMock.expect(filterExpression.g)150 if (filterIsNull) {151 EasyMock.expect(resultsView.getFilter()).andStubReturn(null);152 } else {153 EasyMock.expect(resultsView.getFilter()).andStubReturn(154 getFilterExpressionMockedObj(ExpressionKind.PROPERTY, "SalesOrder"));155 }156 if (isTopNull) {157 EasyMock.expect(resultsView.getTop()).andStubReturn(null);158 } else {159 EasyMock.expect(resultsView.getTop()).andStubReturn(10);160 }161 if (isSkipNull) {162 EasyMock.expect(resultsView.getSkip()).andStubReturn(null);163 } else {164 EasyMock.expect(resultsView.getSkip()).andStubReturn(0);165 }166 EasyMock.expect(resultsView.getKeyPredicates()).andStubReturn(keyPredicates);167 EasyMock.replay(resultsView);168 } catch (EdmException e1) {169 fail("Exception not Expected");170 }171 try {172 builder = (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, resultsView);173 selectContext = (JPQLSelectContext) builder.build();174 } catch (ODataJPAModelException e) {175 fail("Exception not Expected");176 } catch (ODataJPARuntimeException e) {177 fail("Runtime Exception thrown");178 }179 }180 private List<EdmProperty> getLocalKeyProperties() {181 List<EdmProperty> propertyList = new ArrayList<EdmProperty>();182 EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);183 try {184 EasyMock.expect(edmProperty.getName()).andStubReturn("Field1");185 EasyMock.expect(edmProperty.getMapping()).andStubReturn(null);186 } catch (EdmException e) {187 fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);188 }189 EasyMock.replay(edmProperty);190 propertyList.add(edmProperty);191 return propertyList;192 }193 @Test194 public void testEntityNameThrowingException() {195 // buildSelectContext(false, false, false);196 GetEntitySetUriInfo resultsView = EasyMock.createMock(GetEntitySetUriInfo.class);197 EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);198 EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);199 try {200 EasyMock.expect(entityType.getName()).andStubThrow(new EdmException(null));201 EasyMock.expect(entitySet.getEntityType()).andStubThrow(new EdmException(null));202 } catch (EdmException e1) {203 // throw new ODataException();204 }205 EasyMock.replay(entityType);206 EasyMock.replay(entitySet);207 EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);208 EasyMock.expect(resultsView.getOrderBy()).andStubReturn(null);209 EasyMock.expect(resultsView.getSelect()).andStubReturn(null);210 EasyMock.expect(resultsView.getFilter()).andStubReturn(null);211 EasyMock.replay(resultsView);212 try {213 JPQLSelectContextBuilder builder1 =214 (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, resultsView);215 builder1.build();216 fail("Should not come here");217 } catch (ODataJPAModelException e) {218 fail();219 } catch (ODataJPARuntimeException e) {220 assertTrue(true);221 }222 }223 @Test224 public void testSelectFieldsAsNull() {225 buildSelectContext(false, true, true, true, true);226 try {227 selectContext = (JPQLSelectContext) builder.build();228 assertEquals("E2", selectContext.getSelectExpression());229 } catch (ODataJPAModelException e) {230 fail();231 } catch (ODataJPARuntimeException e) {232 fail();233 }234 }235 @Test236 public void testGetOrderByCollection() {237 buildSelectContext(false, false, true, true, true);238 assertEquals("E1.Field1 , E1.Field2 DESC", selectContext.getOrderByCollection());239 }240 @Test241 public void testGetWhereExpression() {242 buildSelectContext(false, false, true, true, true);243 // fail("Not yet implemented");244 }245 @Test246 public void testGetJPAEntityName() {247 buildSelectContext(false, false, true, true, true);248 assertEquals(JPQLSelectContextImplTest.entityTypeName, selectContext.getJPAEntityName());249 }250 @Test251 public void testGetType() {252 buildSelectContext(false, false, true, true, true);253 assertEquals(JPQLContextType.SELECT, selectContext.getType());254 }255 @Test256 public void testCreateBuilder() {257 buildSelectContext(false, false, true, true, true);258 assertEquals(JPQLSelectContextBuilder.class.toString(), builder.getClass().toString());259 }260 @Test261 public void testEntitySetAsNull() {262 buildSelectContext(false, false, true, true, true);263 try {264 JPQLSelectContextBuilder builder =265 (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, null);266 JPQLSelectContext selectContext1 = (JPQLSelectContext) builder.build();267 assertNull(selectContext1.getJPAEntityAlias());268 assertNull(selectContext1.getJPAEntityName());269 assertNull(selectContext1.getOrderByCollection());270 assertNull(selectContext1.getSelectExpression());271 assertNull(selectContext1.getType());272 assertNull(selectContext1.getWhereExpression());273 } catch (ODataJPAModelException e) {274 fail("Exception not Expected");275 } catch (ODataJPARuntimeException e) {276 fail("Runtime Exception thrown");277 }278 }279 @Test280 public void testOrderingWithSkip() {281 buildSelectContext(true, false, true, true, false);282 assertEquals("E1.Field1", selectContext.getOrderByCollection());283 }284 @Test285 public void testOrderingWithTop() {286 buildSelectContext(true, false, true, false, true);287 assertEquals("E1.Field1", selectContext.getOrderByCollection());288 }289 @Test290 public void testOrderByTopSkipAsNull() {291 buildSelectContext(true, true, true, true, true);292 assertNull(selectContext.getOrderByCollection());293 }294 @Test295 public void testFilter() {296 buildSelectContext(true, false, false, false, false);297 assertEquals("E1.field", selectContext.whereCondition);298 }299 private FilterExpression getFilterExpressionMockedObj(final ExpressionKind leftOperandExpKind,300 final String propertyName) throws EdmException {301 FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);302 EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);303 EasyMock.expect(filterExpression.getExpression()).andStubReturn(304 getPropertyExpressionMockedObj(leftOperandExpKind, propertyName));305 EasyMock.replay(filterExpression);306 return filterExpression;307 }308 private PropertyExpression getPropertyExpressionMockedObj(final ExpressionKind expKind, final String propertyName) {309 PropertyExpression leftOperandPropertyExpresion = EasyMock.createMock(PropertyExpression.class);310 EasyMock.expect(leftOperandPropertyExpresion.getKind()).andReturn(ExpressionKind.PROPERTY);311 EasyMock.expect(leftOperandPropertyExpresion.getPropertyName()).andReturn(propertyName);312 EdmProperty edmtTyped = EasyMock.createMock(EdmProperty.class);313 EdmMapping mapping = EasyMock.createMock(EdmMapping.class);314 EasyMock.expect(mapping.getInternalName()).andStubReturn("field");315 try {316 EasyMock.expect(edmtTyped.getMapping()).andStubReturn(mapping);317 } catch (EdmException e) {318 // TODO Auto-generated catch block319 e.printStackTrace();320 }321 EasyMock.expect(leftOperandPropertyExpresion.getEdmProperty()).andReturn(edmtTyped);322 EasyMock.replay(mapping, edmtTyped, leftOperandPropertyExpresion);323 return leftOperandPropertyExpresion;324 }325}...

Full Screen

Full Screen

Results

Using AI Code Generation

copy

Full Screen

1import org.easymock.internal.*;2import org.easymock.*;3import org.easymock.internal.matchers.*;4import org.easymock.internal.matchers.And;5import org.easymock.internal.matchers.Or;6import org.easymock.internal.matchers.Equals;7import org.easymock.internal.matchers.Not;8import org.easymock.internal.matchers.InstanceOf;9import org.easymock.internal.matchers.Compare;10import org.easymock.internal.matchers.CompareEqual;11import org.easymock.internal.matchers.CompareGreaterThan;12import org.easymock.internal.matchers.CompareGreaterThanOrEqual;13import org.easymock.internal.matchers.CompareLessThan;14import org.easymock.internal.matchers.CompareLessThanOrEqual;15import org.easymock.internal.matchers.CompareNotEqual;16import org.easymock.internal.matchers.IsNull;17import org.easymock.internal.matchers.IsNull;18import org.easymock.internal.matchers.Compare;19import org.easymock.internal.matchers.CompareEqual;20import org.easymock.internal.matchers.CompareGreaterThan;21import org.easymock.internal.matchers.CompareGreaterThanOrEqual;22import org.easymock.internal.matchers.CompareLessThan;23import org.easymock.internal.matchers.CompareLessThanOrEqual;24import org.easymock.internal.matchers.CompareNotEqual;25import org.easymock.internal.matchers.IsNull;26import org.easymock.internal.matchers.IsNull;27import org.easymock.internal.matchers.Compare;28import org.easymock.internal.matchers.CompareEqual;29import org.easymock.internal.matchers.CompareGreaterThan;30import org.easymock.internal.matchers.CompareGreaterThanOrEqual;31import org.easymock.internal.matchers.CompareLessThan;32import org.easymock.internal.matchers.CompareLessThanOrEqual;33import org.easymock.internal.matchers.CompareNotEqual;34import org.easymock.internal.matchers.IsNull;35import org.easymock.internal.matchers.IsNull;36import org.easymock.internal.matchers.Compare;37import org.easymock.internal.matchers.CompareEqual;38import org.easymock.internal.matchers.CompareGreaterThan;39import org.easymock.internal.matchers.CompareGreaterThanOrEqual;40import org.easymock.internal.matchers.CompareLessThan;41import org.easymock.internal.matchers.CompareLessThanOrEqual;42import org.easymock.internal.match

Full Screen

Full Screen

Results

Using AI Code Generation

copy

Full Screen

1import org.easymock.internal.Results;2import org.easymock.internal.MocksControl;3import org.easymock.internal.MocksBehavior;4import org.easymock.internal.InvocationMatcher;5import org.easymock.internal.MocksControl;6import org.easymock.internal.MocksBehavior;7import org.easymock.internal.InvocationMatcher;8import org.easymock.internal.Invocation;9import org.easymock.internal.Results;10import org.easymock.internal.Invocation;11import org.easymock.internal.InvocationMatcher;12import org.easymock.internal.MocksBehavior;13import org.easymock.internal.MocksControl;14import org.easymock.internal.Results;15import java.util.*;16import javax.swing.*;17import javax.swing.table.*;18import java.awt.*;19import java.awt.event.*;20import java.io.*;21import org.easymock.*;22class 1 extends JFrame {23 private static final long serialVersionUID = 1L;24 private static final int WIDTH = 500;25 private static final int HEIGHT = 300;26 private static final int DEFAULT_ROW_COUNT = 3;27 private static final int DEFAULT_COLUMN_COUNT = 3;28 private static final String[] DEFAULT_COLUMN_NAMES = { "First Name",29 "Last Name", "Age" };30 private static final String[] DEFAULT_ROW_NAMES = { "Row 1", "Row 2",31 "Row 3" };32 private static final String[] DEFAULT_CELL_VALUES = { "John", "Doe",33 "30" };34 private static final String[] DEFAULT_CELL_VALUES2 = { "Jane", "Doe",35 "30" };36 private static final String[] DEFAULT_CELL_VALUES3 = { "Joe", "Doe",37 "30" };38 private static final String[] DEFAULT_CELL_VALUES4 = { "Jack", "Doe",39 "30" };40 private static final String[] DEFAULT_CELL_VALUES5 = { "Jill", "Doe",41 "30" };42 private static final String[] DEFAULT_CELL_VALUES6 = { "Jim", "Doe",43 "30" };44 private static final String[] DEFAULT_CELL_VALUES7 = { "Jenny", "Doe",45 "30" };46 private static final String[] DEFAULT_CELL_VALUES8 = { "Jen", "Doe",47 "30" };48 private static final String[] DEFAULT_CELL_VALUES9 = {

Full Screen

Full Screen

Results

Using AI Code Generation

copy

Full Screen

1import org.easymock.internal.Results;2import org.easymock.internal.RecordState;3import org.easymock.internal.IArgumentMatcher;4import org.easymock.internal.matchers.Equals;5import org.easymock.internal.matchers.ArrayEquals;6import org.easymock.internal.matchers.InstanceOf;7import org.easymock.internal.matchers.NotNull;8import org.easymock.internal.matchers.Null;9import org.easymock.internal.matchers.Same;10import org.easymock.internal.matchers.Compare;11import org.easymock.internal.matchers.Find;12import org.easymock.internal.matchers.Regex;13import org.easymock.internal.matchers.And;14import org.easymock.internal.matchers.Or;15import org.easymock.internal.matchers.Not;16import java.util.List;17import java.util.ArrayList;18public class Test1 {19 public static void main(String[] args) {20 Results r = new Results();21 r.addResult("test");22 r.addResult(1);23 r.addResult(2);24 r.addResult(3);25 r.addResult(4);26 r.addResult(5);27 r.addResult(6);28 r.addResult(7);29 r.addResult(8);30 r.addResult(9);31 r.addResult(10);32 r.addResult(11);33 r.addResult(12);34 r.addResult(13);35 r.addResult(14);36 r.addResult(15);37 r.addResult(16);38 r.addResult(17);39 r.addResult(18);40 r.addResult(19);41 r.addResult(20);42 r.addResult(21);43 r.addResult(22);44 r.addResult(23);45 r.addResult(24);46 r.addResult(25);47 r.addResult(26);48 r.addResult(27);49 r.addResult(28);50 r.addResult(29);51 r.addResult(30);52 r.addResult(31);53 r.addResult(32);54 r.addResult(33);55 r.addResult(34);56 r.addResult(35);57 r.addResult(36);58 r.addResult(37);59 r.addResult(38);60 r.addResult(39);61 r.addResult(40);62 r.addResult(41);63 r.addResult(42

Full Screen

Full Screen

Results

Using AI Code Generation

copy

Full Screen

1import org.easymock.internal.Results;2import org.easymock.internal.MocksControl;3public class 1 {4 public static void main(String[] args) {5 Results results = new Results();6 results.addResult(1);7 results.addResult(2);8 results.addResult(3);9 results.addResult(4);10 results.addResult(5);11 results.addResult(6);12 results.addResult(7);13 results.addResult(8);14 results.addResult(9);15 results.addResult(10);16 MocksControl mocksControl = new MocksControl();17 mocksControl.setReturnValue(results);18 System.out.println(mocksControl.getReturnValue());19 }20}21{1,2,3,4,5,6,7,8,9,10}

Full Screen

Full Screen

Results

Using AI Code Generation

copy

Full Screen

1package org.easymock.internal;2public class Results {3 public static void main(String[] args) {4 System.out.println("Hello World!");5 }6}7package org.easymock.internal;8public class Results {9 public static void main(String[] args) {10 System.out.println("Hello World!");11 }12}13package org.easymock.internal;14public class Results {15 public static void main(String[] args) {16 System.out.println("Hello World!");17 }18}19package org.easymock.internal;20public class Results {21 public static void main(String[] args) {22 System.out.println("Hello World!");23 }24}25package org.easymock.internal;26public class Results {27 public static void main(String[] args) {28 System.out.println("Hello World!");29 }30}31package org.easymock.internal;32public class Results {33 public static void main(String[] args) {34 System.out.println("Hello World!");35 }36}37package org.easymock.internal;38public class Results {39 public static void main(String[] args) {40 System.out.println("Hello World!");41 }42}43package org.easymock.internal;44public class Results {45 public static void main(String[] args) {46 System.out.println("Hello World!");47 }48}49package org.easymock.internal;50public class Results {51 public static void main(String[] args) {52 System.out.println("Hello World!");53 }54}

Full Screen

Full Screen

Results

Using AI Code Generation

copy

Full Screen

1package org.easymock.internal;2import org.easymock.internal.*;3public class Test {4 public static void main(String[] args) {5 Results r = new Results();6 r.addResult(new Object()

Full Screen

Full Screen

Results

Using AI Code Generation

copy

Full Screen

1package org.easymock.internal;2import org.easymock.internal.matchers.Capture;3import org.easymock.internal.matchers.CaptureMatcher;4import org.easymock.internal.matchers.Equals;5import org.easymock.internal.matchers.EqualsMatcher;6import org.easymock.internal.matchers.InstanceOf;7import org.easymock.internal.matchers.InstanceOfMatcher;8import org.easymock.internal.matchers.LessThan;9import org.easymock.internal.matchers.LessThanMatcher;10import org.easymock.internal.matchers.LessThanOrEqual;11import org.easymock.internal.matchers.LessThanOrEqualMatcher;12import org.easymock.internal.matchers.Not;13import org.easymock.internal.matchers.NotMatcher;14import org.easymock.internal.matchers.NotNull;15import org.easymock.internal.matchers.NotNullMatcher;16import org.easymock.internal.matchers.Null;17import org.easymock.internal.matchers.NullMatcher;18import org.easymock.internal.matchers.Or;19import org.easymock.internal.matchers.OrMatcher;20import org.easymock.internal.matchers.Regex;21import org.easymock.internal.matchers.RegexMatcher;22import org.easymock.internal.matchers.Same;23import org.easymock.internal.matchers.SameMatcher;24import org.easymock.internal.matchers.StartsWith;25import org.easymock.internal.matchers.StartsWithMatcher;26import org.easymock.internal.matchers.EndsWith;27import org.easymock.internal.matchers.EndsWithMatcher;28import org.easymock.internal.matchers.GreaterThan;29import org.easymock.internal.matchers.GreaterThanMatcher;30import org.easymock.internal.matchers.GreaterThanOrEqual;31import org.easymock.internal.matchers.GreaterThanOrEqualMatcher;32import org.easymock.internal.matchers.And;33import org.easymock.internal.matchers.AndMatcher;34import org.easymock.internal.matchers.ArrayEquals;35import org.easymock.internal.matchers.ArrayEqualsMatcher;36import org.easymock.internal.matchers.ArrayEqualsWithDelta;37import org.easymock.internal.matchers.ArrayEqualsWithDeltaMatcher;38import org.easymock.internal.matchers.ArrayEqualsWithTolerance;39import org.easymock.internal.matchers.ArrayEqualsWithTolerance

Full Screen

Full Screen

Results

Using AI Code Generation

copy

Full Screen

1public class EasyMockExample {2 private MocksControl control;3 private Results results;4 private IMethods mock;5 protected void setUp() throws Exception {6 control = new MocksControl();7 results = new Results();8 mock = (IMethods) control.createMock(IMethods.class);9 }10 public void test() {11 mock.oneArg(true);12 control.setReturnValue("oneArg", results);13 mock.oneArg(false);14 control.setReturnValue("oneArg", results);15 control.replay();16 assertEquals("oneArg", mock.oneArg(true));17 assertEquals("oneArg", mock.oneArg(false));18 control.verify();19 }20}21public class EasyMockExample {22 private IMethods mock;23 protected void setUp() throws Exception {24 mock = (IMethods) EasyMock.createMock(IMethods.class);25 }26 public void test() {27 EasyMock.expect(mock.oneArg(true)).andReturn("oneArg");28 EasyMock.expect(mock.oneArg(false)).andReturn("oneArg");29 EasyMock.replay(mock);30 assertEquals("oneArg", mock.oneArg(true));31 assertEquals("oneArg", mock.oneArg(false));32 EasyMock.verify(mock);33 }34}

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful