### Question:
TermSubQueryBuilder { public LuceneQueryFactoryAndPRMSQuery positionSequenceToQueryFactoryAndPRMS(PositionSequence<org.apache.lucene.index.Term> sequence) { switch (sequence.size()) { case 0: return null; case 1: final List<org.apache.lucene.index.Term> first = sequence.getFirst(); return first.isEmpty() ? null: newPosition(sequence.iterator(), null, null); default: return newPosition(sequence.iterator(), null, null); } } TermSubQueryBuilder(final Analyzer analyzer, final TermQueryCache termQueryCache); TermSubQueryFactory termToFactory(final String fieldname, final Term sourceTerm, final FieldBoost boost); LuceneQueryFactoryAndPRMSQuery positionSequenceToQueryFactoryAndPRMS(PositionSequence<org.apache.lucene.index.Term> sequence);  }### Answer:
@Test public void testNoTerm() throws Exception { TermSubQueryBuilder builder = new TermSubQueryBuilder(ANALYZER, null); PositionSequence<org.apache.lucene.index.Term> sequence = new PositionSequence<>(); assertNull(builder.positionSequenceToQueryFactoryAndPRMS(sequence)); sequence.nextPosition(); assertNull(builder.positionSequenceToQueryFactoryAndPRMS(sequence)); }
@Test public void testSingleTerm() { TermSubQueryBuilder builder = new TermSubQueryBuilder(ANALYZER, null); PositionSequence<org.apache.lucene.index.Term> sequence = new PositionSequence<>(); sequence.nextPosition(); Term term = new Term("f", "a"); sequence.addElement(term); LuceneQueryFactoryAndPRMSQuery lap = builder.positionSequenceToQueryFactoryAndPRMS(sequence); assertThat( lap, lap(tqf(term), prmsTq(term)) ); }
@Test public void testTwoTermsAtSinglePosition() throws Exception { TermSubQueryBuilder builder = new TermSubQueryBuilder(ANALYZER, null); PositionSequence<org.apache.lucene.index.Term> sequence = new PositionSequence<>(); sequence.nextPosition(); Term term1 = new Term("f", "a"); sequence.addElement(term1); Term term2 = new Term("f", "b"); sequence.addElement(term2); LuceneQueryFactoryAndPRMSQuery lap = builder.positionSequenceToQueryFactoryAndPRMS(sequence); assertThat( lap, lap( dmqf( tqf(term1), tqf(term2) ), prmsDmq( prmsTq(term1), prmsTq(term2)) ) ); }
@Test public void testTwoTermsAtTwoPositions() throws Exception { TermSubQueryBuilder builder = new TermSubQueryBuilder(ANALYZER, null); PositionSequence<org.apache.lucene.index.Term> sequence = new PositionSequence<>(); sequence.nextPosition(); Term term1 = new Term("f", "a"); sequence.addElement(term1); sequence.nextPosition(); Term term2 = new Term("f", "b"); sequence.addElement(term2); LuceneQueryFactoryAndPRMSQuery lap = builder.positionSequenceToQueryFactoryAndPRMS(sequence); assertThat( lap, lap( bqf( tqf(term1), tqf(term2) ), prmsAnd( prmsTq(term1), prmsTq(term2)) ) ); }
@Test public void testTwoTermsAtFirstAndOneTermAtSecondPosition() throws Exception { TermSubQueryBuilder builder = new TermSubQueryBuilder(ANALYZER, null); PositionSequence<org.apache.lucene.index.Term> sequence = new PositionSequence<>(); sequence.nextPosition(); Term term1_1 = new Term("f", "a1"); sequence.addElement(term1_1); Term term1_2 = new Term("f", "a2"); sequence.addElement(term1_2); sequence.nextPosition(); Term term2 = new Term("f", "b"); sequence.addElement(term2); LuceneQueryFactoryAndPRMSQuery lap = builder.positionSequenceToQueryFactoryAndPRMS(sequence); assertThat( lap, lap( dmqf( tqf(term1_1), bqf( tqf(term1_2), tqf(term2) ) ), prmsDmq( prmsTq(term1_1), prmsAnd( prmsTq(term1_2), prmsTq(term2)) ) ) ); }