Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support recursive partial mocking #40

Open
johanhaleby opened this issue Jul 23, 2015 · 1 comment
Open

Support recursive partial mocking #40

johanhaleby opened this issue Jul 23, 2015 · 1 comment

Comments

@johanhaleby
Copy link
Collaborator

It would be cool to support "recursive partial mocking".

Imagine this:

void addFolderToLogPaths(final File logFolder, final List<LogFile> logFileList,
        final Collection<ITargetPersistenceUnit> persistentUnits) {
        if (!logFolder.isDirectory()) {
            throw new IllegalArgumentException("logPath is not a directory.");
        }

        final File[] allLogFiles = logFolder.listFiles();
        for (File fileOrDirectory : allLogFiles) {
            if (fileOrDirectory.isDirectory()) {
                addFolderToLogPaths(fileOrDirectory, logFileList,
persistentUnits);
            } else {
                logFileList.add(new
LogFile(getRelativeLogPath(fileOrDirectory), fileOrDirectory.lastModified(),
                    isFileReplayable(persistentUnits, fileOrDirectory)));
            }
        }
    }

We could implement so that one call to addFolderToLogPaths (the actual test
invocation) passes the MockGateway but sequential invocations should be
mocked.

@astafev
Copy link
Contributor

astafev commented Mar 22, 2018

@thekingnothing I believe it already works ok. Probably the ticket can be closed...

Here's the test to check it:

    @Test
    public void testRecursive() throws Exception {
        CUT o = PowerMockito.spy(object);
        PowerMockito.doCallRealMethod().doAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                System.out.println("mock");
                return null;
            }
        }).when(o).addFolderToLogPaths(any(Boolean.class));
        o.addFolderToLogPaths(true);
    }

    public static class CUT {
        public void addFolderToLogPaths(final boolean first) {
            System.out.println("original");
            if(first) {
                addFolderToLogPaths(false);
            }
        }
    }

will print

original
mock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants