@Test
public void testFit() {

    BatchOperator data = new MemSourceBatchOp(new Object[]{1}, "colName");
    TransformerBase stage1 = mockTransformer("stage1");
    TransformerBase stage2 = mockTransformer("stage2");
    Pair<EstimatorBase, ModelBase> stage3 = mockEstimator("stage3");
    TransformerBase stage4 = mockTransformer("stage4");
    Pair<EstimatorBase, ModelBase> stage5 = mockEstimator("stage5");
    TransformerBase stage6 = mockTransformer("stage6");
    Pipeline pipe = new Pipeline().add(stage1).add(stage2).add(stage3.getLeft())
        .add(stage4).add(stage5.getLeft()).add(stage6);
    pipe.fit(data);
    // The transform methods of the first 2 transformers should be invoked.
    // because they are expected transform input data to fit estimators.
    verify(stage1, times(1)).transform(any(BatchOperator.class));
    verify(stage2, times(1)).transform(any(BatchOperator.class));
    // Verify that estimator of stage 3 is fitted.
    verify(stage3.getLeft(), times(1)).fit(any(BatchOperator.class));
    // And the generated model is used to transform data for estimator on stage 5.
    verify(stage3.getRight(), times(1)).transform(any(BatchOperator.class));
    verify(stage4, times(1)).transform(any(BatchOperator.class));
    // Verify that estimator of stage 5 is fitted.
    verify(stage5.getLeft(), times(1)).fit(any(BatchOperator.class));
    // But we don't have to transform data with the generated model.
    verify(stage5.getRight(), never()).transform(any(BatchOperator.class));
    verify(stage6, never()).transform(any(BatchOperator.class));
}