Best Easymock code snippet using org.easymock.EasyMock.anyLong
Source:GTestResultParserTest.java  
...37                EasyMock.createMock(ITestInvocationListener.class);38        mockRunListener.testRunStarted(TEST_MODULE_NAME, 11);39        // 11 passing test cases in this run40        for (int i=0; i<11; ++i) {41            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());42            mockRunListener.testEnded(43                    (TestDescription) EasyMock.anyObject(),44                    EasyMock.anyLong(),45                    EasyMock.<HashMap<String, Metric>>anyObject());46        }47        // TODO: validate param values48        mockRunListener.testRunEnded(49                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());50        EasyMock.replay(mockRunListener);51        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);52        resultParser.processNewLines(contents);53        resultParser.flush();54        EasyMock.verify(mockRunListener);55    }56    /** Tests the parser for a simple test run output with 53 tests and no times. */57    @Test58    public void testParseSimpleFileNoTimes() throws Exception {59        String[] contents =  readInFile(GTEST_OUTPUT_FILE_2);60        ITestInvocationListener mockRunListener =61                EasyMock.createMock(ITestInvocationListener.class);62        mockRunListener.testRunStarted(TEST_MODULE_NAME, 53);63        // 53 passing test cases in this run64        for (int i=0; i<53; ++i) {65            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());66            mockRunListener.testEnded(67                    (TestDescription) EasyMock.anyObject(),68                    EasyMock.anyLong(),69                    EasyMock.<HashMap<String, Metric>>anyObject());70        }71        // TODO: validate param values72        mockRunListener.testRunEnded(73                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());74        EasyMock.replay(mockRunListener);75        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);76        resultParser.processNewLines(contents);77        resultParser.flush();78        EasyMock.verify(mockRunListener);79    }80    /** Tests the parser for a simple test run output with 0 tests and no times. */81    @Test82    public void testParseNoTests() throws Exception {83        String[] contents =  readInFile(GTEST_OUTPUT_FILE_3);84        HashMap<String, Metric> expected = new HashMap<>();85        ITestInvocationListener mockRunListener =86                EasyMock.createMock(ITestInvocationListener.class);87        mockRunListener.testRunStarted(TEST_MODULE_NAME, 0);88        mockRunListener.testRunEnded(EasyMock.anyLong(), EasyMock.eq(expected));89        EasyMock.replay(mockRunListener);90        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);91        resultParser.processNewLines(contents);92        resultParser.flush();93        EasyMock.verify(mockRunListener);94    }95    /** Tests the parser for a run with 268 tests. */96    @Test97    public void testParseLargerFile() throws Exception {98        String[] contents =  readInFile(GTEST_OUTPUT_FILE_4);99        ITestInvocationListener mockRunListener =100                EasyMock.createMock(ITestInvocationListener.class);101        mockRunListener.testRunStarted(TEST_MODULE_NAME, 268);102        // 268 passing test cases in this run103        for (int i=0; i<268; ++i) {104            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());105            mockRunListener.testEnded(106                    (TestDescription) EasyMock.anyObject(),107                    EasyMock.anyLong(),108                    EasyMock.<HashMap<String, Metric>>anyObject());109        }110        // TODO: validate param values111        mockRunListener.testRunEnded(112                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());113        EasyMock.replay(mockRunListener);114        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);115        resultParser.processNewLines(contents);116        resultParser.flush();117        EasyMock.verify(mockRunListener);118    }119    /** Tests the parser for a run with test failures. */120    @Test121    public void testParseWithFailures() throws Exception {122        String MESSAGE_OUTPUT =123                "This is some random text that should get captured by the parser.";124        String[] contents =  readInFile(GTEST_OUTPUT_FILE_5);125        ITestInvocationListener mockRunListener =126                EasyMock.createMock(ITestInvocationListener.class);127        // 13 test cases in this run128        mockRunListener.testRunStarted(TEST_MODULE_NAME, 13);129        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());130        mockRunListener.testEnded(131                (TestDescription) EasyMock.anyObject(),132                EasyMock.anyLong(),133                EasyMock.<HashMap<String, Metric>>anyObject());134        // test failure135        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());136        mockRunListener.testFailed(137                (TestDescription) EasyMock.anyObject(), (String) EasyMock.anyObject());138        mockRunListener.testEnded(139                (TestDescription) EasyMock.anyObject(),140                EasyMock.anyLong(),141                EasyMock.<HashMap<String, Metric>>anyObject());142        // 4 passing tests143        for (int i=0; i<4; ++i) {144            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());145            mockRunListener.testEnded(146                    (TestDescription) EasyMock.anyObject(),147                    EasyMock.anyLong(),148                    EasyMock.<HashMap<String, Metric>>anyObject());149        }150        // 2 consecutive test failures151        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());152        mockRunListener.testFailed(153                (TestDescription) EasyMock.anyObject(), (String) EasyMock.anyObject());154        mockRunListener.testEnded(155                (TestDescription) EasyMock.anyObject(),156                EasyMock.anyLong(),157                EasyMock.<HashMap<String, Metric>>anyObject());158        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());159        mockRunListener.testFailed(160                (TestDescription) EasyMock.anyObject(), EasyMock.matches(MESSAGE_OUTPUT));161        mockRunListener.testEnded(162                (TestDescription) EasyMock.anyObject(),163                EasyMock.anyLong(),164                EasyMock.<HashMap<String, Metric>>anyObject());165        // 5 passing tests166        for (int i=0; i<5; ++i) {167            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());168            mockRunListener.testEnded(169                    (TestDescription) EasyMock.anyObject(),170                    EasyMock.anyLong(),171                    EasyMock.<HashMap<String, Metric>>anyObject());172        }173        // TODO: validate param values174        mockRunListener.testRunEnded(175                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());176        EasyMock.replay(mockRunListener);177        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);178        resultParser.processNewLines(contents);179        resultParser.flush();180        EasyMock.verify(mockRunListener);181    }182    /** Tests the parser for a run with test errors. */183    @Test184    public void testParseWithErrors() throws Exception {185        String[] contents =  readInFile(GTEST_OUTPUT_FILE_6);186        ITestInvocationListener mockRunListener =187                EasyMock.createMock(ITestInvocationListener.class);188        // 10 test cases in this run189        mockRunListener.testRunStarted(TEST_MODULE_NAME, 10);190        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());191        mockRunListener.testEnded(192                (TestDescription) EasyMock.anyObject(),193                EasyMock.anyLong(),194                EasyMock.<HashMap<String, Metric>>anyObject());195        // test failure196        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());197        mockRunListener.testFailed(198                (TestDescription) EasyMock.anyObject(), (String) EasyMock.anyObject());199        mockRunListener.testEnded(200                (TestDescription) EasyMock.anyObject(),201                EasyMock.anyLong(),202                EasyMock.<HashMap<String, Metric>>anyObject());203        // 5 passing tests204        for (int i=0; i<5; ++i) {205            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());206            mockRunListener.testEnded(207                    (TestDescription) EasyMock.anyObject(),208                    EasyMock.anyLong(),209                    EasyMock.<HashMap<String, Metric>>anyObject());210        }211        // another test error212        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());213        mockRunListener.testFailed(214                (TestDescription) EasyMock.anyObject(), (String) EasyMock.anyObject());215        mockRunListener.testEnded(216                (TestDescription) EasyMock.anyObject(),217                EasyMock.anyLong(),218                EasyMock.<HashMap<String, Metric>>anyObject());219        // 2 passing tests220        for (int i=0; i<2; ++i) {221            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());222            mockRunListener.testEnded(223                    (TestDescription) EasyMock.anyObject(),224                    EasyMock.anyLong(),225                    EasyMock.<HashMap<String, Metric>>anyObject());226        }227        // TODO: validate param values228        mockRunListener.testRunEnded(229                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());230        EasyMock.replay(mockRunListener);231        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);232        resultParser.processNewLines(contents);233        resultParser.flush();234        EasyMock.verify(mockRunListener);235    }236    /** Tests the parser for a run with 11 tests. */237    @Test238    public void testParseNonAlignedTag() throws Exception {239        String[] contents =  readInFile(GTEST_OUTPUT_FILE_7);240        ITestInvocationListener mockRunListener =241                EasyMock.createMock(ITestInvocationListener.class);242        mockRunListener.testRunStarted(TEST_MODULE_NAME, 11);243        // 11 passing test cases in this run244        for (int i=0; i<11; ++i) {245            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());246            mockRunListener.testEnded(247                    (TestDescription) EasyMock.anyObject(),248                    EasyMock.anyLong(),249                    EasyMock.<HashMap<String, Metric>>anyObject());250        }251        mockRunListener.testRunEnded(252                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());253        EasyMock.replay(mockRunListener);254        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);255        resultParser.processNewLines(contents);256        resultParser.flush();257        EasyMock.verify(mockRunListener);258    }259    /**260     * Tests the parser for a simple test run output with 18 tests with Non GTest format Should not261     * crash.262     */263    @Test264    public void testParseSimpleFile_AltFormat() throws Exception {265        String[] contents =  readInFile(GTEST_OUTPUT_FILE_8);266        ITestInvocationListener mockRunListener =267                EasyMock.createMock(ITestInvocationListener.class);268        mockRunListener.testRunStarted(TEST_MODULE_NAME, 18);269        // 13 passing tests270        for (int i = 0; i < 13; ++i) {271            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());272            mockRunListener.testEnded(273                    (TestDescription) EasyMock.anyObject(),274                    EasyMock.anyLong(),275                    EasyMock.<HashMap<String, Metric>>anyObject());276        }277        // 3 consecutive test failures278        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());279        mockRunListener.testFailed(280                (TestDescription) EasyMock.anyObject(), (String) EasyMock.anyObject());281        mockRunListener.testEnded(282                (TestDescription) EasyMock.anyObject(),283                EasyMock.anyLong(),284                EasyMock.<HashMap<String, Metric>>anyObject());285        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());286        mockRunListener.testFailed(287                (TestDescription) EasyMock.anyObject(), (String) EasyMock.anyObject());288        mockRunListener.testEnded(289                (TestDescription) EasyMock.anyObject(),290                EasyMock.anyLong(),291                EasyMock.<HashMap<String, Metric>>anyObject());292        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());293        mockRunListener.testFailed(294                (TestDescription) EasyMock.anyObject(), (String) EasyMock.anyObject());295        mockRunListener.testEnded(296                (TestDescription) EasyMock.anyObject(),297                EasyMock.anyLong(),298                EasyMock.<HashMap<String, Metric>>anyObject());299        // 1 passing test300        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());301        mockRunListener.testEnded(302                (TestDescription) EasyMock.anyObject(),303                EasyMock.anyLong(),304                EasyMock.<HashMap<String, Metric>>anyObject());305        // 1 ignored test306        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());307        mockRunListener.testIgnored((TestDescription) EasyMock.anyObject());308        mockRunListener.testEnded(309                (TestDescription) EasyMock.anyObject(),310                EasyMock.anyLong(),311                EasyMock.<HashMap<String, Metric>>anyObject());312        mockRunListener.testRunEnded(313                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());314        EasyMock.replay(mockRunListener);315        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);316        resultParser.processNewLines(contents);317        resultParser.flush();318        EasyMock.verify(mockRunListener);319    }320    /** Tests the parser for a simple test run output with a link error. */321    @Test322    public void testParseSimpleFile_LinkError() throws Exception {323        String[] contents = readInFile(GTEST_OUTPUT_FILE_9);324        ITestInvocationListener mockRunListener =325                EasyMock.createMock(ITestInvocationListener.class);326        mockRunListener.testRunStarted(TEST_MODULE_NAME, 0);327        Capture<FailureDescription> captured = new Capture<>();328        mockRunListener.testRunFailed(EasyMock.capture(captured));329        mockRunListener.testRunEnded(330                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());331        EasyMock.replay(mockRunListener);332        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);333        resultParser.processNewLines(contents);334        resultParser.flush();335        EasyMock.verify(mockRunListener);336        assertTrue(337                captured.getValue()338                        .getErrorMessage()339                        .contains(340                                "module did not report any run:\nCANNOT LINK EXECUTABLE "341                                        + "\"/data/installd_cache_test\": "342                                        + "library \"liblogwrap.so\" not found"));343    }344    /**345     * Test that if the binary simply doesn't output something obvious and doesn't report any run we346     * report all the logs we currently have and an error.347     */348    @Test349    public void testParseSimpleFile_earlyError() throws Exception {350        String[] contents = readInFile(GTEST_OUTPUT_FILE_10);351        ITestInvocationListener mockRunListener =352                EasyMock.createMock(ITestInvocationListener.class);353        mockRunListener.testRunStarted(TEST_MODULE_NAME, 0);354        Capture<FailureDescription> captured = new Capture<>();355        mockRunListener.testRunFailed(EasyMock.capture(captured));356        mockRunListener.testRunEnded(357                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());358        EasyMock.replay(mockRunListener);359        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);360        resultParser.processNewLines(contents);361        resultParser.flush();362        EasyMock.verify(mockRunListener);363        assertTrue(364                captured.getValue()365                        .getErrorMessage()366                        .contains(367                                "module did not report any run:\n"368                                        + "failed to read section .testzipdata"));369    }370    /** Tests the parser for a simple test run output with 11 tests where some are skipped. */371    @Test372    public void testParseSimpleFileWithSkips() throws Exception {373        String[] contents = readInFile(GTEST_OUTPUT_FILE_11);374        ITestInvocationListener mockRunListener =375                EasyMock.createMock(ITestInvocationListener.class);376        mockRunListener.testRunStarted(TEST_MODULE_NAME, 11);377        // 11 tests run, with the fifth and sixth tests being ignored378        for (int i = 0; i < 11; ++i) {379            mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());380            if (i == 4 || i == 5) {381                mockRunListener.testIgnored((TestDescription) EasyMock.anyObject());382            }383            mockRunListener.testEnded(384                    (TestDescription) EasyMock.anyObject(),385                    EasyMock.anyLong(),386                    EasyMock.<HashMap<String, Metric>>anyObject());387        }388        // TODO: validate param values389        mockRunListener.testRunEnded(390                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());391        EasyMock.replay(mockRunListener);392        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);393        resultParser.processNewLines(contents);394        resultParser.flush();395        EasyMock.verify(mockRunListener);396    }397    /** Tests the parser for a test runs but doesn't finish run completely. */398    @Test399    public void testParseSimpleFileWithoutRunComplete() throws Exception {400        String[] contents = readInFile(GTEST_OUTPUT_FILE_12);401        ITestInvocationListener mockRunListener =402                EasyMock.createMock(ITestInvocationListener.class);403        mockRunListener.testRunStarted(TEST_MODULE_NAME, 11);404        mockRunListener.testStarted((TestDescription) EasyMock.anyObject(), EasyMock.anyLong());405        mockRunListener.testFailed(406                (TestDescription) EasyMock.anyObject(), (FailureDescription) EasyMock.anyObject());407        mockRunListener.testEnded(408                (TestDescription) EasyMock.anyObject(),409                EasyMock.<HashMap<String, Metric>>anyObject());410        Capture<FailureDescription> captured = new Capture<>();411        mockRunListener.testRunFailed(EasyMock.capture(captured));412        mockRunListener.testRunEnded(413                EasyMock.anyLong(), EasyMock.<HashMap<String, Metric>>anyObject());414        EasyMock.replay(mockRunListener);415        GTestResultParser resultParser = new GTestResultParser(TEST_MODULE_NAME, mockRunListener);416        resultParser.processNewLines(contents);417        resultParser.flush();418        EasyMock.verify(mockRunListener);419        FailureDescription cap = captured.getValue();420        assertEquals("Test run incomplete. Expected 11 tests, received 0", cap.getErrorMessage());421    }422}...Source:WaitDeviceRecoveryTest.java  
...65     */66    @Test67    public void testRecoverDevice_success() throws DeviceNotAvailableException {68        // expect initial sleep69        mMockRunUtil.sleep(EasyMock.anyLong());70        mMockMonitor.waitForDeviceBootloaderStateUpdate();71        EasyMock.expect(mMockMonitor.getDeviceState()).andReturn(TestDeviceState.NOT_AVAILABLE);72        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong())).andReturn(mMockDevice);73        EasyMock.expect(mMockMonitor.waitForDeviceShell(EasyMock.anyLong())).andReturn(true);74        EasyMock.expect(mMockMonitor.waitForDeviceAvailable(EasyMock.anyLong())).andReturn(75                mMockDevice);76        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong())).andReturn(mMockDevice);77        replayMocks();78        mRecovery.recoverDevice(mMockMonitor, false);79        verifyMocks();80    }81    /**82     * Test {@link WaitDeviceRecovery#recoverDevice(IDeviceStateMonitor, boolean)} when device is83     * not available.84     */85    @Test86    public void testRecoverDevice_unavailable() {87        // expect initial sleep88        mMockRunUtil.sleep(EasyMock.anyLong());89        mMockMonitor.waitForDeviceBootloaderStateUpdate();90        EasyMock.expect(mMockMonitor.getDeviceState()).andStubReturn(TestDeviceState.NOT_AVAILABLE);91        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong())).andReturn(null);92        replayMocks();93        try {94            mRecovery.recoverDevice(mMockMonitor, false);95            fail("DeviceNotAvailableException not thrown");96        } catch (DeviceNotAvailableException e) {97            // expected98        }99        verifyMocks();100    }101    @Test102    public void testRecoverDevice_unavailable_recovers() throws Exception {103        // expect initial sleep104        mMockRunUtil.sleep(EasyMock.anyLong());105        mMockMonitor.waitForDeviceBootloaderStateUpdate();106        EasyMock.expect(mMockMonitor.getDeviceState()).andStubReturn(TestDeviceState.NOT_AVAILABLE);107        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong())).andReturn(null);108        UsbDevice mockDevice = Mockito.mock(UsbDevice.class);109        doReturn(mockDevice).when(mMockUsbHelper).getDevice("serial");110        EasyMock.expect(mMockMonitor.waitForDeviceAvailable()).andReturn(mMockDevice);111        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong()))112                .andReturn(mMockDevice);113        replayMocks();114        // Device recovers successfully115        mRecovery.recoverDevice(mMockMonitor, false);116        verifyMocks();117        verify(mockDevice).reset();118    }119    @Test120    public void testRecoverDevice_unavailable_recovery() throws Exception {121        // expect initial sleep122        mMockRunUtil.sleep(EasyMock.anyLong());123        mMockMonitor.waitForDeviceBootloaderStateUpdate();124        EasyMock.expect(mMockMonitor.getDeviceState()).andStubReturn(TestDeviceState.RECOVERY);125        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong())).andReturn(null);126        UsbDevice mockDevice = Mockito.mock(UsbDevice.class);127        doReturn(mockDevice).when(mMockUsbHelper).getDevice("serial");128        EasyMock.expect(mMockMonitor.waitForDeviceAvailable()).andReturn(null);129        EasyMock.expect(mMockMonitor.waitForDeviceInRecovery()).andReturn(mMockDevice);130        mMockDevice.reboot(null);131        EasyMock.expect(mMockMonitor.waitForDeviceAvailable()).andReturn(mMockDevice);132        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong()))133                .andReturn(mMockDevice);134        replayMocks();135        // Device recovers successfully136        mRecovery.recoverDevice(mMockMonitor, false);137        verifyMocks();138        verify(mockDevice).reset();139    }140    @Test141    public void testRecoverDevice_unavailable_recovery_fail() throws Exception {142        // expect initial sleep143        mMockRunUtil.sleep(EasyMock.anyLong());144        mMockMonitor.waitForDeviceBootloaderStateUpdate();145        EasyMock.expect(mMockMonitor.getDeviceState()).andReturn(TestDeviceState.RECOVERY).times(3);146        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong())).andReturn(null);147        UsbDevice mockDevice = Mockito.mock(UsbDevice.class);148        doReturn(mockDevice).when(mMockUsbHelper).getDevice("serial");149        EasyMock.expect(mMockMonitor.waitForDeviceAvailable()).andReturn(null);150        EasyMock.expect(mMockMonitor.waitForDeviceInRecovery()).andReturn(null);151        replayMocks();152        try {153            mRecovery.recoverDevice(mMockMonitor, false);154            fail("DeviceNotAvailableException not thrown");155        } catch (DeviceNotAvailableException e) {156            // expected157        }158        verifyMocks();159        verify(mockDevice).reset();160    }161    @Test162    public void testRecoverDevice_unavailable_fastboot() throws Exception {163        // expect initial sleep164        mMockRunUtil.sleep(EasyMock.anyLong());165        mMockMonitor.waitForDeviceBootloaderStateUpdate();166        EasyMock.expect(mMockMonitor.getDeviceState()).andStubReturn(TestDeviceState.FASTBOOT);167        CommandResult result = new CommandResult();168        result.setStatus(CommandStatus.SUCCESS);169        // expect reboot170        EasyMock.expect(171                        mMockRunUtil.runTimedCmd(172                                EasyMock.anyLong(),173                                EasyMock.eq("fastboot"),174                                EasyMock.eq("-s"),175                                EasyMock.eq("serial"),176                                EasyMock.eq("reboot")))177                .andReturn(result);178        EasyMock.expect(mMockMonitor.getFastbootSerialNumber()).andReturn("serial");179        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong())).andReturn(null);180        replayMocks();181        try {182            mRecovery.recoverDevice(mMockMonitor, false);183            fail("DeviceNotAvailableException not thrown");184        } catch (DeviceNotAvailableException e) {185            // expected186        }187        verifyMocks();188    }189    /**190     * Test {@link WaitDeviceRecovery#recoverDevice(IDeviceStateMonitor, boolean)} when device is191     * not responsive.192     */193    @Test194    public void testRecoverDevice_unresponsive() throws Exception {195        // expect initial sleep196        mMockRunUtil.sleep(EasyMock.anyLong());197        mMockMonitor.waitForDeviceBootloaderStateUpdate();198        EasyMock.expect(mMockMonitor.getDeviceState()).andReturn(TestDeviceState.ONLINE);199        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong()))200                .andReturn(mMockDevice).anyTimes();201        EasyMock.expect(mMockMonitor.waitForDeviceShell(EasyMock.anyLong())).andReturn(true);202        EasyMock.expect(mMockMonitor.waitForDeviceAvailable(EasyMock.anyLong()))203                .andReturn(null).anyTimes();204        mMockDevice.reboot((String)EasyMock.isNull());205        replayMocks();206        try {207            mRecovery.recoverDevice(mMockMonitor, false);208            fail("DeviceUnresponsiveException not thrown");209        } catch (DeviceUnresponsiveException e) {210            // expected211        }212        verifyMocks();213    }214    /**215     * Test {@link WaitDeviceRecovery#recoverDevice(IDeviceStateMonitor, boolean)} when device is in216     * fastboot.217     */218    @Test219    public void testRecoverDevice_fastboot() throws DeviceNotAvailableException {220        // expect initial sleep221        mMockRunUtil.sleep(EasyMock.anyLong());222        mMockMonitor.waitForDeviceBootloaderStateUpdate();223        EasyMock.expect(mMockMonitor.getDeviceState()).andReturn(TestDeviceState.FASTBOOT);224        CommandResult result = new CommandResult();225        result.setStatus(CommandStatus.SUCCESS);226        // expect reboot227        EasyMock.expect(mMockMonitor.getFastbootSerialNumber()).andReturn("serial");228        EasyMock.expect(mMockRunUtil.runTimedCmd(EasyMock.anyLong(), EasyMock.eq("fastboot"),229                EasyMock.eq("-s"), EasyMock.eq("serial"), EasyMock.eq("reboot"))).230                andReturn(result);231        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong()))232                .andReturn(mMockDevice);233        EasyMock.expect(mMockMonitor.waitForDeviceShell(EasyMock.anyLong())).andReturn(true);234        EasyMock.expect(mMockMonitor.waitForDeviceAvailable(EasyMock.anyLong())).andReturn(235                mMockDevice);236        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong()))237                .andReturn(mMockDevice);238        replayMocks();239        mRecovery.recoverDevice(mMockMonitor, false);240        verifyMocks();241    }242    /**243     * Test {@link WaitDeviceRecovery#recoverDeviceBootloader(IDeviceStateMonitor)} when device is244     * already in bootloader245     */246    @Test247    public void testRecoverDeviceBootloader_fastboot() throws DeviceNotAvailableException {248        mMockRunUtil.sleep(EasyMock.anyLong());249        // expect reboot250        EasyMock.expect(mMockRunUtil.runTimedCmd(EasyMock.anyLong(), EasyMock.eq("fastboot"),251                EasyMock.eq("-s"), EasyMock.eq("serial"), EasyMock.eq("reboot-bootloader"))).252                andReturn(new CommandResult(CommandStatus.SUCCESS));253        EasyMock.expect(mMockMonitor.waitForDeviceNotAvailable(EasyMock.anyLong())).andReturn(254                Boolean.TRUE);255        EasyMock.expect(mMockMonitor.waitForDeviceBootloader(EasyMock.anyLong())).andReturn(256                Boolean.TRUE).times(2);257        EasyMock.expect(mMockRunUtil.runTimedCmd(EasyMock.anyLong(), EasyMock.eq("fastboot"),258                EasyMock.eq("-s"), EasyMock.eq("serial"), EasyMock.eq("getvar"),259                EasyMock.eq("product"))).260                andReturn(new CommandResult(CommandStatus.SUCCESS));261        replayMocks();262        mRecovery.recoverDeviceBootloader(mMockMonitor);263        verifyMocks();264    }265    /**266     * Test {@link WaitDeviceRecovery#recoverDeviceBootloader(IDeviceStateMonitor)} when device is267     * unavailable but comes back to bootloader on its own268     */269    @Test270    public void testRecoverDeviceBootloader_unavailable() throws DeviceNotAvailableException {271        mMockRunUtil.sleep(EasyMock.anyLong());272        EasyMock.expect(mMockMonitor.waitForDeviceBootloader(EasyMock.anyLong())).andReturn(273                Boolean.FALSE);274        EasyMock.expect(mMockMonitor.getDeviceState()).andReturn(TestDeviceState.NOT_AVAILABLE);275        // expect reboot276        EasyMock.expect(mMockRunUtil.runTimedCmd(EasyMock.anyLong(), EasyMock.eq("fastboot"),277                EasyMock.eq("-s"), EasyMock.eq("serial"), EasyMock.eq("reboot-bootloader"))).278                andReturn(new CommandResult(CommandStatus.SUCCESS));279        EasyMock.expect(mMockMonitor.waitForDeviceNotAvailable(EasyMock.anyLong())).andReturn(280                Boolean.TRUE);281        EasyMock.expect(mMockMonitor.waitForDeviceBootloader(EasyMock.anyLong())).andReturn(282                Boolean.TRUE).times(2);283        EasyMock.expect(mMockRunUtil.runTimedCmd(EasyMock.anyLong(), EasyMock.eq("fastboot"),284                EasyMock.eq("-s"), EasyMock.eq("serial"), EasyMock.eq("getvar"),285                EasyMock.eq("product"))).286                andReturn(new CommandResult(CommandStatus.SUCCESS));287        replayMocks();288        mRecovery.recoverDeviceBootloader(mMockMonitor);289        verifyMocks();290    }291    /**292     * Test {@link WaitDeviceRecovery#recoverDeviceBootloader(IDeviceStateMonitor)} when device is293     * online when bootloader is expected294     */295    @Test296    public void testRecoverDeviceBootloader_online() throws Exception {297        mMockRunUtil.sleep(EasyMock.anyLong());298        EasyMock.expect(mMockMonitor.waitForDeviceBootloader(EasyMock.anyLong())).andReturn(299                Boolean.FALSE);300        EasyMock.expect(mMockMonitor.getDeviceState()).andReturn(TestDeviceState.ONLINE);301        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong()))302                .andReturn(mMockDevice);303        mMockDevice.reboot("bootloader");304        EasyMock.expect(mMockMonitor.waitForDeviceBootloader(EasyMock.anyLong())).andReturn(305                Boolean.TRUE);306        replayMocks();307        mRecovery.recoverDeviceBootloader(mMockMonitor);308        verifyMocks();309    }310    /**311     * Test {@link WaitDeviceRecovery#recoverDeviceBootloader(IDeviceStateMonitor)} when device is312     * initially unavailable, then comes online when bootloader is expected313     */314    @Test315    public void testRecoverDeviceBootloader_unavailable_online() throws Exception {316        mMockRunUtil.sleep(EasyMock.anyLong());317        EasyMock.expect(mMockMonitor.waitForDeviceBootloader(EasyMock.anyLong())).andReturn(318                Boolean.FALSE);319        EasyMock.expect(mMockMonitor.getDeviceState()).andReturn(TestDeviceState.NOT_AVAILABLE);320        EasyMock.expect(mMockMonitor.waitForDeviceBootloader(EasyMock.anyLong())).andReturn(321                Boolean.FALSE);322        EasyMock.expect(mMockMonitor.getDeviceState()).andReturn(TestDeviceState.ONLINE);323        EasyMock.expect(mMockMonitor.waitForDeviceOnline(EasyMock.anyLong()))324                .andReturn(mMockDevice);325        mMockDevice.reboot("bootloader");326        EasyMock.expect(mMockMonitor.waitForDeviceBootloader(EasyMock.anyLong())).andReturn(327                Boolean.TRUE);328        replayMocks();329        mRecovery.recoverDeviceBootloader(mMockMonitor);330        verifyMocks();331    }332    /**333     * Test {@link WaitDeviceRecovery#recoverDeviceBootloader(IDeviceStateMonitor)} when device is334     * unavailable335     */336    @Test337    public void testRecoverDeviceBootloader_unavailable_failure() throws Exception {338        mMockRunUtil.sleep(EasyMock.anyLong());339        EasyMock.expect(mMockMonitor.waitForDeviceBootloader(EasyMock.anyLong())).andStubReturn(340                Boolean.FALSE);341        EasyMock.expect(mMockMonitor.getDeviceState()).andStubReturn(TestDeviceState.NOT_AVAILABLE);342        replayMocks();343        try {344            mRecovery.recoverDeviceBootloader(mMockMonitor);345            fail("DeviceNotAvailableException not thrown");346        } catch (DeviceNotAvailableException e) {347            // expected348        }349        verifyMocks();350    }351    /**352     * Test {@link WaitDeviceRecovery#checkMinBatteryLevel(IDevice)} throws an exception if battery353     * level is not readable....Source:AsyncMonitorTest.java  
...16 * specific language governing permissions and limitations17 * under the License.18 */19package org.jclouds.abiquo.internal;20import static org.easymock.EasyMock.anyLong;21import static org.easymock.EasyMock.anyObject;22import static org.easymock.EasyMock.expect;23import static org.easymock.EasyMock.replay;24import static org.easymock.EasyMock.verify;25import static org.testng.Assert.assertEquals;26import static org.testng.Assert.assertFalse;27import static org.testng.Assert.assertNotNull;28import static org.testng.Assert.assertNull;29import static org.testng.Assert.assertTrue;30import java.util.concurrent.ScheduledExecutorService;31import java.util.concurrent.ScheduledFuture;32import java.util.concurrent.TimeUnit;33import org.easymock.EasyMock;34import org.jclouds.abiquo.events.monitor.MonitorEvent;35import org.jclouds.abiquo.internal.BaseMonitoringService.AsyncMonitor;36import org.jclouds.abiquo.monitor.MonitorStatus;37import org.jclouds.rest.RestContext;38import org.testng.annotations.Test;39import com.google.common.base.Function;40import com.google.common.eventbus.EventBus;41import com.google.common.eventbus.Subscribe;42/**43 * Unit tests for the {@link AsyncMonitor} class.44 * 45 * @author Ignasi Barrera46 */47@Test(groups = "unit")48public class AsyncMonitorTest49{50    @SuppressWarnings({"rawtypes", "unchecked"})51    public void testStartMonitoringWithoutTimeout()52    {53        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);54        ScheduledExecutorService schedulerMock =55            EasyMock.createMock(ScheduledExecutorService.class);56        expect(57            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),58                anyObject(TimeUnit.class))).andReturn(mockFuture);59        replay(mockFuture);60        replay(schedulerMock);61        AsyncMonitor<Object> monitor =62            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE),63                new EventBus());64        assertNull(monitor.getFuture());65        assertNull(monitor.getTimeout());66        monitor.startMonitoring(null);67        assertNotNull(monitor.getFuture());68        assertNull(monitor.getTimeout());69        verify(mockFuture);70        verify(schedulerMock);71    }72    @SuppressWarnings({"rawtypes", "unchecked"})73    public void testStartMonitoringWithTimeout()74    {75        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);76        ScheduledExecutorService schedulerMock =77            EasyMock.createMock(ScheduledExecutorService.class);78        expect(79            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),80                anyObject(TimeUnit.class))).andReturn(mockFuture);81        replay(mockFuture);82        replay(schedulerMock);83        AsyncMonitor<Object> monitor =84            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE),85                new EventBus());86        assertNull(monitor.getFuture());87        assertNull(monitor.getTimeout());88        monitor.startMonitoring(100L);89        assertNotNull(monitor.getFuture());90        assertNotNull(monitor.getTimeout());91        assertTrue(monitor.getTimeout() > 100L);92        verify(mockFuture);93        verify(schedulerMock);94    }95    @SuppressWarnings({"rawtypes", "unchecked"})96    public void testIsTimeoutWhenNullTimeout()97    {98        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);99        ScheduledExecutorService schedulerMock =100            EasyMock.createMock(ScheduledExecutorService.class);101        expect(102            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),103                anyObject(TimeUnit.class))).andReturn(mockFuture);104        replay(mockFuture);105        replay(schedulerMock);106        AsyncMonitor<Object> monitor =107            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE),108                new EventBus());109        assertNull(monitor.getFuture());110        assertNull(monitor.getTimeout());111        monitor.startMonitoring(null);112        assertNotNull(monitor.getFuture());113        assertNull(monitor.getTimeout());114        assertFalse(monitor.isTimeout());115        verify(mockFuture);116        verify(schedulerMock);117    }118    @SuppressWarnings({"rawtypes", "unchecked"})119    public void testIsTimeoutReturnsFalseWhenNotFinished()120    {121        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);122        ScheduledExecutorService schedulerMock =123            EasyMock.createMock(ScheduledExecutorService.class);124        expect(125            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),126                anyObject(TimeUnit.class))).andReturn(mockFuture);127        replay(mockFuture);128        replay(schedulerMock);129        AsyncMonitor<Object> monitor =130            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE),131                new EventBus());132        assertNull(monitor.getFuture());133        assertNull(monitor.getTimeout());134        monitor.startMonitoring(60000L);135        assertNotNull(monitor.getFuture());136        assertNotNull(monitor.getTimeout());137        assertFalse(monitor.isTimeout());138        verify(mockFuture);139        verify(schedulerMock);140    }141    @SuppressWarnings({"rawtypes", "unchecked"})142    public void testIsTimeoutReturnsTrueWhenFinished() throws InterruptedException143    {144        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);145        ScheduledExecutorService schedulerMock =146            EasyMock.createMock(ScheduledExecutorService.class);147        expect(148            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),149                anyObject(TimeUnit.class))).andReturn(mockFuture);150        replay(mockFuture);151        replay(schedulerMock);152        AsyncMonitor<Object> monitor =153            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE),154                new EventBus());155        assertNull(monitor.getFuture());156        assertNull(monitor.getTimeout());157        monitor.startMonitoring(1L);158        Thread.sleep(2L);159        assertNotNull(monitor.getFuture());160        assertNotNull(monitor.getTimeout());161        assertTrue(monitor.isTimeout());162        verify(mockFuture);163        verify(schedulerMock);164    }165    @SuppressWarnings({"rawtypes", "unchecked"})166    public void testStopMonitoringWhenFutureIsCancelled()167    {168        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);169        expect(mockFuture.isCancelled()).andReturn(true);170        ScheduledExecutorService schedulerMock =171            EasyMock.createMock(ScheduledExecutorService.class);172        expect(173            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),174                anyObject(TimeUnit.class))).andReturn(mockFuture);175        replay(mockFuture);176        replay(schedulerMock);177        AsyncMonitor<Object> monitor =178            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE),179                new EventBus());180        assertNull(monitor.getFuture());181        assertNull(monitor.getTimeout());182        monitor.startMonitoring(null);183        assertNotNull(monitor.getFuture());184        assertNull(monitor.getTimeout());185        monitor.stopMonitoring();186        verify(mockFuture);187        verify(schedulerMock);188    }189    @SuppressWarnings({"rawtypes", "unchecked"})190    public void testStopMonitoringWhenFutureIsDone()191    {192        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);193        expect(mockFuture.isCancelled()).andReturn(false);194        expect(mockFuture.isDone()).andReturn(true);195        ScheduledExecutorService schedulerMock =196            EasyMock.createMock(ScheduledExecutorService.class);197        expect(198            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),199                anyObject(TimeUnit.class))).andReturn(mockFuture);200        replay(mockFuture);201        replay(schedulerMock);202        AsyncMonitor<Object> monitor =203            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE),204                new EventBus());205        assertNull(monitor.getFuture());206        assertNull(monitor.getTimeout());207        monitor.startMonitoring(null);208        assertNotNull(monitor.getFuture());209        assertNull(monitor.getTimeout());210        monitor.stopMonitoring();211        verify(mockFuture);212        verify(schedulerMock);213    }214    @SuppressWarnings({"rawtypes", "unchecked"})215    public void testStopMonitoringWhenFutureIsNotComplete()216    {217        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);218        expect(mockFuture.isCancelled()).andReturn(false);219        expect(mockFuture.isDone()).andReturn(false);220        expect(mockFuture.cancel(false)).andReturn(true);221        ScheduledExecutorService schedulerMock =222            EasyMock.createMock(ScheduledExecutorService.class);223        expect(224            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),225                anyObject(TimeUnit.class))).andReturn(mockFuture);226        replay(mockFuture);227        replay(schedulerMock);228        AsyncMonitor<Object> monitor =229            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE),230                new EventBus());231        assertNull(monitor.getFuture());232        assertNull(monitor.getTimeout());233        monitor.startMonitoring(null);234        assertNotNull(monitor.getFuture());235        assertNull(monitor.getTimeout());236        monitor.stopMonitoring();237        verify(mockFuture);238        verify(schedulerMock);239    }240    @SuppressWarnings({"rawtypes", "unchecked"})241    public void testMonitorAndDone()242    {243        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);244        expect(mockFuture.isCancelled()).andReturn(true);245        ScheduledExecutorService schedulerMock =246            EasyMock.createMock(ScheduledExecutorService.class);247        expect(248            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),249                anyObject(TimeUnit.class))).andReturn(mockFuture);250        replay(mockFuture);251        replay(schedulerMock);252        CoutingEventHandler handler = new CoutingEventHandler();253        EventBus eventBus = new EventBus();254        eventBus.register(handler);255        AsyncMonitor<Object> monitor =256            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), eventBus);257        assertNull(monitor.getFuture());258        assertNull(monitor.getTimeout());259        monitor.startMonitoring(null);260        assertNotNull(monitor.getFuture());261        assertNull(monitor.getTimeout());262        monitor.run();263        assertEquals(handler.numCompletes, 1);264        assertEquals(handler.numFailures, 0);265        assertEquals(handler.numTimeouts, 0);266        verify(mockFuture);267        verify(schedulerMock);268    }269    @SuppressWarnings({"rawtypes", "unchecked"})270    public void testMonitorAndFail()271    {272        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);273        expect(mockFuture.isCancelled()).andReturn(true);274        ScheduledExecutorService schedulerMock =275            EasyMock.createMock(ScheduledExecutorService.class);276        expect(277            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),278                anyObject(TimeUnit.class))).andReturn(mockFuture);279        replay(mockFuture);280        replay(schedulerMock);281        CoutingEventHandler handler = new CoutingEventHandler();282        EventBus eventBus = new EventBus();283        eventBus.register(handler);284        AsyncMonitor<Object> monitor =285            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.FAILED), eventBus);286        assertNull(monitor.getFuture());287        assertNull(monitor.getTimeout());288        monitor.startMonitoring(null);289        assertNotNull(monitor.getFuture());290        assertNull(monitor.getTimeout());291        monitor.run();292        assertEquals(handler.numCompletes, 0);293        assertEquals(handler.numFailures, 1);294        assertEquals(handler.numTimeouts, 0);295        verify(mockFuture);296        verify(schedulerMock);297    }298    @SuppressWarnings({"rawtypes", "unchecked"})299    public void testMonitorAndContinueWithoutTimeout()300    {301        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);302        ScheduledExecutorService schedulerMock =303            EasyMock.createMock(ScheduledExecutorService.class);304        expect(305            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),306                anyObject(TimeUnit.class))).andReturn(mockFuture);307        replay(mockFuture);308        replay(schedulerMock);309        CoutingEventHandler handler = new CoutingEventHandler();310        EventBus eventBus = new EventBus();311        eventBus.register(handler);312        AsyncMonitor<Object> monitor =313            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.CONTINUE), eventBus);314        assertNull(monitor.getFuture());315        assertNull(monitor.getTimeout());316        monitor.startMonitoring(null);317        assertNotNull(monitor.getFuture());318        assertNull(monitor.getTimeout());319        monitor.run();320        assertEquals(handler.numCompletes, 0);321        assertEquals(handler.numFailures, 0);322        assertEquals(handler.numTimeouts, 0);323        verify(mockFuture);324        verify(schedulerMock);325    }326    @SuppressWarnings({"rawtypes", "unchecked"})327    public void testMonitorAndContinueWithtTimeout() throws InterruptedException328    {329        ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class);330        expect(mockFuture.isCancelled()).andReturn(true);331        ScheduledExecutorService schedulerMock =332            EasyMock.createMock(ScheduledExecutorService.class);333        expect(334            schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(),335                anyObject(TimeUnit.class))).andReturn(mockFuture);336        replay(mockFuture);337        replay(schedulerMock);338        CoutingEventHandler handler = new CoutingEventHandler();339        EventBus eventBus = new EventBus();340        eventBus.register(handler);341        AsyncMonitor<Object> monitor =342            mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.CONTINUE), eventBus);343        assertNull(monitor.getFuture());344        assertNull(monitor.getTimeout());345        monitor.startMonitoring(1L);346        assertNotNull(monitor.getFuture());347        assertNotNull(monitor.getTimeout());348        Thread.sleep(2L);...anyLong
Using AI Code Generation
1import org.easymock.EasyMock;2import org.easymock.EasyMockSupport;3import org.junit.Test;4public class 1 extends EasyMockSupport {5    public void test() {6        final MyInterface myInterface = createMock(MyInterface.class);7        myInterface.doSomething(anyLong());8        replayAll();9        myInterface.doSomething(1L);10        verifyAll();11    }12    public interface MyInterface {13        void doSomething(long l);14    }15}16        myInterface.doSomething(anyLong());17  symbol:   method anyLong()18Answer: EasyMock.anyLong() is not a method of EasyMock class. It is a method of EasyMockSupport class. So you need to use it like this:anyLong
Using AI Code Generation
1package org.easymock;2import org.easymock.EasyMock;3public class 1 {4public static void main(String[] args) {5MockInterface mock = EasyMock.createMock(MockInterface.class);6EasyMock.expect(mock.method1(anyLong())).andReturn(10);7EasyMock.replay(mock);8mock.method1(10);9EasyMock.verify(mock);10}11}12interface MockInterface {13int method1(long l);14}15package org.easymock;16import org.easymock.EasyMock;17public class 2 {18public static void main(String[] args) {19MockInterface mock = EasyMock.createMock(MockInterface.class);20EasyMock.expect(mock.method1(anyLong())).andReturn(10);21EasyMock.replay(mock);22mock.method1(10);23EasyMock.verify(mock);24}25}26interface MockInterface {27int method1(long l);28}29package org.easymock;30import org.easymock.EasyMock;31public class 3 {32public static void main(String[] args) {33MockInterface mock = EasyMock.createMock(MockInterface.class);34EasyMock.expect(mock.method1(anyLong())).andReturn(10);35EasyMock.replay(mock);36mock.method1(10);37EasyMock.verify(mock);38}39}40interface MockInterface {41int method1(long l);42}43package org.easymock;44import org.easymock.EasyMock;45public class 4 {46public static void main(String[] args) {47MockInterface mock = EasyMock.createMock(MockInterface.class);48EasyMock.expect(mock.method1(anyLong())).andReturn(10);49EasyMock.replay(mock);50mock.method1(10);51EasyMock.verify(mock);52}53}54interface MockInterface {55int method1(long l);56}57package org.easymock;58import org.easymock.EasyMock;59public class 5 {60public static void main(String[] args) {61MockInterface mock = EasyMock.createMock(MockInterface.class);62EasyMock.expect(mock.method1(anyLong())).andReturn(10);anyLong
Using AI Code Generation
1package com.ack.j2se.mock;2import org.easymock.EasyMock;3import org.easymock.IMocksControl;4public class AnyLongMethod {5  public static void main( String[] args ) {6    IMocksControl control = EasyMock.createControl();7    AnyLongMethodIF anyLongMethodIF = control.createMock( AnyLongMethodIF.class );8    EasyMock.expect( anyLongMethodIF.anyLongMethod() ).andReturn( EasyMock.anyLong() );9    control.replay();10    System.out.println( "anyLongMethod() returned " + anyLongMethodIF.anyLongMethod() );11    control.verify();12  }13}14interface AnyLongMethodIF {15  public long anyLongMethod();16}17package com.ack.j2se.mock;18import org.easymock.EasyMock;19import org.easymock.IMocksControl;20public class AnyObjectMethod {21  public static void main( String[] args ) {22    IMocksControl control = EasyMock.createControl();23    AnyObjectMethodIF anyObjectMethodIF = control.createMock( AnyObjectMethodIF.class );24    EasyMock.expect( anyObjectMethodIF.anyObjectMethod() ).andReturn( EasyMock.anyObject() );25    control.replay();26    System.out.println( "anyObjectanyLong
Using AI Code Generation
1public class 1 {2	public static void main(String[] args) {3		Maths m = EasyMock.createMock(Maths.class);4		EasyMock.expect(m.add(EasyMock.anyLong(), EasyMock.anyLong())).andReturn(10L);5		EasyMock.replay(m);6		System.out.println(m.add(100L, 200L));7	}8}anyLong
Using AI Code Generation
1import org.easymock.EasyMock;2import org.junit.Test;3import static org.easymock.EasyMock.*;4public class testclass {5public void test() {6IInterface iinterface = EasyMock.createMock(IInterface.class);7iinterface.method1(anyLong());8EasyMock.replay(iinterface);9iinterface.method1(5);10EasyMock.verify(iinterface);11}12}13org.easymock.internal.MocksControl.verify(MocksControl.java:210)14org.easymock.internal.MocksControl.verify(MocksControl.java:200)15org.easymock.internal.MocksControl.verify(MocksControl.java:196)16org.easymock.internal.MocksControl.verify(MocksControl.java:192)17org.easymock.internal.MocksControl.verify(MocksControl.java:188)18testclass.test(testclass.java:18)19Related Posts: Easymock: How to use anyLong() method of EasyMock class20Easymock: How to use anyString() method of EasyMock class21Easymock: How to use anyObject() method of EasyMock class22Easymock: How to use anyObject(Class<?> c) method of EasyMock class23Easymock: How to use anyInt() method of EasyMock class24Easymock: How to use anyBoolean() method of EasyMock class25Easymock: How to use anyByte() method of EasyMock class26Easymock: How to use anyChar() method of EasyMock class27Easymock: How to use anyDouble() method of EasyMock class28Easymock: How to use anyFloat() method of EasyMock classLearn 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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
