0

我对 Apache Crunch 很陌生。这是我写的第一个测试用例。目前我正在为 DoFn 编写测试用例,但它显示 NullPointerException。

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import org.apache.crunch.Emitter;
import org.apache.crunch.Pair;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class OutputResultTest {

  @Mock
  InMemoryEmitter <String>  emitter = new InMemoryEmitter<>();

  @Test
  public void TestProcess(){
    OutputResult outputResult = new OutputResult();
    //String expected = "Thor Odinson scored 97.8";
    Pair<String,Double> input = Pair.of("Thor Odinson",97.8);
    outputResult.process(input,emitter);
    assertEquals(expected,emitter.getOutput());
    //verify(emitter).emit("Thor Odinson scored 97.8");//this works
    //verifyNoMoreInteractions(emitter);//this works
  }
}
4

0 回答 0