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

Mock Fusion instance correctly in IndexStageTestBase #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.lucidworks.indexing.api.Document;
import com.lucidworks.indexing.api.IndexStage;
import com.lucidworks.indexing.api.fusion.Documents;
import com.lucidworks.indexing.api.fusion.Fusion;
import com.lucidworks.indexing.config.IndexStageConfig;
import org.junit.runner.RunWith;
Expand All @@ -11,6 +12,8 @@

import java.util.function.Consumer;

import static org.mockito.ArgumentMatchers.any;

/**
* Base class for index stage unit tests.
* @param <C> index stage config class
Expand All @@ -31,12 +34,21 @@ public abstract class IndexStageTestBase<C extends IndexStageConfig> {
* @throws ReflectiveOperationException when unable to instantiate stage class using default no param constructor
*/
public <S extends IndexStage<C>> S createStage(Class<S> stageClass, C config) throws ReflectiveOperationException {
mockDocumentsInFusion();

S stage = stageClass.getDeclaredConstructor().newInstance();
stage.init(config, fusion);

return stage;
}

private void mockDocumentsInFusion() {
Documents documents = Mockito.mock(Documents.class);
Mockito.when(documents.newDocument()).then(invocation -> newDocument());
Mockito.when(documents.newDocument(any())).then(invocation -> newDocument(invocation.getArgument(0)));
Mockito.when(fusion.documents()).thenReturn(documents);
}

/**
* Create new document without id.
*
Expand Down