Program: 22125
Project: 22125
Buggy source:
private void phrasePrefixQueryTestCase(boolean phraseAsTerms){
  MultiPhrasePrefixQuery query=new MultiPhrasePrefixQuery();
  Term foo=new Term("String_Node_Str","String_Node_Str");
  Term qux=new Term("String_Node_Str","String_Node_Str");
  Term quux=new Term("String_Node_Str","String_Node_Str");
  Term bar=new Term("String_Node_Str","String_Node_Str");
  Term anoth=new Term("String_Node_Str","String_Node_Str");
  query.add(foo);
  query.add(new Term[]{qux,quux});
  query.add(new Term[]{bar,anoth});
  Callback callback=mock(Callback.class);
  new ElasticsearchQueryFlattener(1,phraseAsTerms).flatten(query,null,callback);
  verify(callback).flattened(foo.bytes(),phraseAsTerms ? 1f : 0,null);
  verify(callback,never()).flattened(eq(bar.bytes()),anyFloat(),isNull(Query.class));
  ArgumentCaptor<Automaton> a=ArgumentCaptor.forClass(Automaton.class);
  verify(callback,times(2)).flattened(a.capture(),phraseAsTerms ? eq(1f) : eq(0f),anyInt());
  assertThat(a.getAllValues().get(0),allOf(recognises("String_Node_Str"),recognises("String_Node_Str"),recognises("String_Node_Str"),not(recognises("String_Node_Str")),not(recognises("String_Node_Str"))));
  assertThat(a.getAllValues().get(1),allOf(recognises("String_Node_Str"),recognises("String_Node_Str"),recognises("String_Node_Str"),not(recognises("String_Node_Str")),not(recognises("String_Node_Str"))));
  if (phraseAsTerms) {
    verify(callback,never()).startPhrase(anyInt());
    verify(callback,never()).startPhrasePosition(anyInt());
    verify(callback,never()).endPhrasePosition();
    verify(callback,never()).endPhrase(anyInt(),anyFloat());
  }
 else {
    verify(callback).startPhrase(3);
    verify(callback).startPhrasePosition(1);
    verify(callback,times(2)).startPhrasePosition(2);
    verify(callback,times(3)).endPhrasePosition();
    verify(callback).endPhrase(0,1);
  }
}

Fixed version (ground truth):
private void phrasePrefixQueryTestCase(boolean phraseAsTerms){
  MultiPhrasePrefixQuery query=new MultiPhrasePrefixQuery();
  Term foo=new Term("String_Node_Str","String_Node_Str");
  Term qux=new Term("String_Node_Str","String_Node_Str");
  Term quux=new Term("String_Node_Str","String_Node_Str");
  Term bar=new Term("String_Node_Str","String_Node_Str");
  Term anoth=new Term("String_Node_Str","String_Node_Str");
  query.add(foo);
  query.add(new Term[]{qux,quux});
  query.add(new Term[]{bar,anoth});
  Callback callback=mock(Callback.class);
  new ElasticsearchQueryFlattener(1,phraseAsTerms).flatten(query,null,callback);
  verify(callback).flattened(foo.bytes(),phraseAsTerms ? 1f : 0,null);
  verify(callback,never()).flattened(eq(bar.bytes()),anyFloat(),isNull(Query.class));
  ArgumentCaptor<Automaton> a=ArgumentCaptor.forClass(Automaton.class);
  verify(callback,times(2)).flattened(a.capture(),phraseAsTerms ? eq(1f) : eq(0f),anyInt());
  assertThat(a.getAllValues().get(0),allOf(recognises("String_Node_Str"),recognises("String_Node_Str"),recognises("String_Node_Str"),not(recognises("String_Node_Str")),not(recognises("String_Node_Str"))));
  assertThat(a.getAllValues().get(1),allOf(recognises("String_Node_Str"),recognises("String_Node_Str"),recognises("String_Node_Str"),not(recognises("String_Node_Str")),not(recognises("String_Node_Str"))));
  if (phraseAsTerms) {
    verify(callback,never()).startPhrase(anyInt());
    verify(callback,never()).startPhrasePosition(anyInt());
    verify(callback,never()).endPhrasePosition();
    verify(callback,never()).endPhrase(anyString(),anyInt(),anyFloat());
  }
 else {
    verify(callback).startPhrase(3);
    verify(callback).startPhrasePosition(1);
    verify(callback,times(2)).startPhrasePosition(2);
    verify(callback,times(3)).endPhrasePosition();
    verify(callback).endPhrase("String_Node_Str",0,1);
  }
}