Skip to content

Conversation

krook1024
Copy link

Tl;dr

Mock Fusion instance correctly in IndexStageTestBase

Details

Previously, if the IndexStage you were testing contained a call to IndexStage::newDocument, the unit test would fail because of an NPE because the tested IndexStage environment tries to create a document, but it cannot because the behaviour of the Fusion instance that's injected into the IndexStage isn't mocked correctly.

This PR fixes that behaviour and lets IndexStage instances run newDocuments, but it runs the IndexStageTestBase::newDocument in the background.

How to verify

Let's suppose you have an IndexStage that looks something like this:

public class MyStage extends IndexStageBase<MyStageConfig> {
// [...]
    @Override
    public void process(Document document, Context context, Consumer<Document> output) {
       Document document = newDocument();
       output.accept(document);
    }
// [...]
}

And the test looking like this:

public class MyStageTest extends IndexStageTestBase<MyStageConfig> {
// [...]
 @Test
    public void testWhenValidUrlIsProvidedDocumentShouldBeFed() {
         MyStageConfig conf = newConfig(MyStageConfig.class, config -> {
             // [...]
        }); 

        MyStage underTest = createStage(MyStage.class, conf);

        underTest.process(doc, null, System.out::println);
    }
// [...]
}

It would end up in a NPE in the current version, but with this PR it should print the new document.

@krook1024
Copy link
Author

@dzmitryk @sbrowndev can you guys take a look this?

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

Successfully merging this pull request may close these issues.

1 participant