Метод класса Mocking Helper и возвращаемое логическое значение - PullRequest
0 голосов
/ 01 октября 2019

У меня есть метод main, как показано ниже, и мой класс FileReadHelper содержит статический метод isFileExistsAndNotEmpty (arg1, arg2).

public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {

        if (args != null && args.length == 2) {
            File firstFile = new File(args[0]);
            File secondFile = new File(args[1]);
            boolean isFileExists = FileReadHelper.isFileExistsAndNotEmpty(firstFile, secondFile);
            if (isFileExists) {
                splitAndReadProcess(firstFile, secondFile);
            }

        } else {
            // TODO
        }
    }

Я написал свой тестовый пример, как показано ниже,

@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class FileReadApplicationTest {

    @Mock
    private FileReadHelper fileReadHelper;

    @Test
    void checkWordCountSplitAndReadProcess() throws InterruptedException, ExecutionException, IOException {
        String [] fileNames = {"firstFile.txt","secondFile.txt"};
        when(fileReadHelper.isFileExistsAndNotEmpty(new File(fileNames[0]), new File(fileNames[1]))).thenReturn(true);
        FileReadApplication.main(fileNames);
    }
}

Я пытался вызвать и получить приведенные ниже исключения,

org.mockito.exceptions.misusing.MissingMethodInvocationException: 
when() requires an argument which has to be 'a method call on a mock'.
For example:
    when(mock.getArticles()).thenReturn(articles);

Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
   Those methods *cannot* be stubbed/verified.
   Mocking methods declared on non-public parent classes is not supported.
2. inside when() you don't call method on mock but on some other object.

Я не могу напрямую вызвать, например,

when(FileReadHelper.isFileExistsAndNotEmpty(new File(fileNames[0]), new File(fileNames[1]))).thenReturn(true);

В этом случае, как вернуть логическое значение, и сделатьуверены, что мой поток продолжился?

...