@Test
  public void testThatTermIsRemovedIfThereASecondDMQWithoutTheTerm() throws Exception {
    RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false);
    DeleteInstruction delete = new DeleteInstruction(Arrays.asList(mkTerm("a")));
    builder.addRule(
        new Input(Arrays.asList(mkTerm("a")), false, false),
        new Instructions(Arrays.asList((Instruction) delete)));
    RulesCollection rules = builder.build();
    CommonRulesRewriter rewriter = new CommonRulesRewriter(rules);

    Query rewritten = rewriter.rewrite(makeQuery("a b"), EMPTY_CONTEXT).getUserQuery();

    assertThat(rewritten, bq(dmq(term("b"))));
  }
  @Test
  public void testThatNothingIsDeletedIfWeWouldEndUpWithAnEmptyQuery() {

    RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false);
    DeleteInstruction delete = new DeleteInstruction(Arrays.asList(mkTerm("a")));
    builder.addRule(
        new Input(Arrays.asList(mkTerm("a")), false, false),
        new Instructions(Arrays.asList((Instruction) delete)));
    RulesCollection rules = builder.build();
    CommonRulesRewriter rewriter = new CommonRulesRewriter(rules);

    ExpandedQuery query = makeQuery("a");
    Query rewritten = rewriter.rewrite(query, EMPTY_CONTEXT).getUserQuery();

    assertThat(rewritten, bq(dmq(term("a"))));
  }
  @Test
  public void testThatTermIsRemovedIfThereIsAnotherTermInTheSameDMQ() throws Exception {
    RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false);
    DeleteInstruction delete = new DeleteInstruction(Arrays.asList(mkTerm("a")));
    builder.addRule(
        new Input(Arrays.asList(mkTerm("a")), false, false),
        new Instructions(Arrays.asList((Instruction) delete)));
    RulesCollection rules = builder.build();
    CommonRulesRewriter rewriter = new CommonRulesRewriter(rules);

    ExpandedQuery expandedQuery = makeQuery("a");
    Query query = expandedQuery.getUserQuery();

    DisjunctionMaxQuery dmq = query.getClauses(DisjunctionMaxQuery.class).get(0);
    querqy.model.Term termB = new querqy.model.Term(dmq, null, "b");
    dmq.addClause(termB);

    Query rewritten = rewriter.rewrite(expandedQuery, EMPTY_CONTEXT).getUserQuery();

    assertThat(rewritten, bq(dmq(term("b"))));
  }