@Test
  public void testNoDocs() throws IOException {
    AnalyzingCompletionLookupProvider provider =
        new AnalyzingCompletionLookupProvider(true, false, true, true);
    RAMDirectory dir = new RAMDirectory();
    IndexOutput output = dir.createOutput("foo.txt", IOContext.DEFAULT);
    FieldsConsumer consumer = provider.consumer(output);
    consumer.write(
        new Fields() {
          @Override
          public Iterator<String> iterator() {
            return Arrays.asList("foo").iterator();
          }

          @Override
          public Terms terms(String field) throws IOException {
            return null;
          }

          @Override
          public int size() {
            return 1;
          }
        });
    consumer.close();
    output.close();

    IndexInput input = dir.openInput("foo.txt", IOContext.DEFAULT);
    LookupFactory load = provider.load(input);
    PostingsFormat format = new Elasticsearch090PostingsFormat();
    NamedAnalyzer analyzer = new NamedAnalyzer("foo", new StandardAnalyzer());
    assertNull(
        load.getLookup(
            new CompletionFieldMapper(
                new Names("foo"),
                analyzer,
                analyzer,
                format,
                null,
                true,
                true,
                true,
                Integer.MAX_VALUE,
                indexSettings,
                AbstractFieldMapper.MultiFields.empty(),
                null,
                ContextMapping.EMPTY_MAPPING),
            new CompletionSuggestionContext(null)));
    dir.close();
  }
 @Override
 public void write(Fields fields) throws IOException {
   delegatesFieldsConsumer.write(fields);
   suggestFieldsConsumer.write(fields);
 }
  // TODO ADD more unittests
  private void writeData(
      Directory dir, Completion090PostingsFormat.CompletionLookupProvider provider)
      throws IOException {
    IndexOutput output = dir.createOutput("foo.txt", IOContext.DEFAULT);
    FieldsConsumer consumer = provider.consumer(output);
    final List<TermPosAndPayload> terms = new ArrayList<>();
    terms.add(
        new TermPosAndPayload(
            "foofightersgenerator",
            256 - 2,
            provider.buildPayload(
                new BytesRef("Generator - Foo Fighters"), 9, new BytesRef("id:10"))));
    terms.add(
        new TermPosAndPayload(
            "generator",
            256 - 1,
            provider.buildPayload(
                new BytesRef("Generator - Foo Fighters"), 9, new BytesRef("id:10"))));
    Fields fields =
        new Fields() {
          @Override
          public Iterator<String> iterator() {
            return Arrays.asList("foo").iterator();
          }

          @Override
          public Terms terms(String field) throws IOException {
            if (field.equals("foo")) {
              return new Terms() {
                @Override
                public TermsEnum iterator(TermsEnum reuse) throws IOException {
                  final Iterator<TermPosAndPayload> iterator = terms.iterator();
                  return new TermsEnum() {
                    private TermPosAndPayload current = null;

                    @Override
                    public SeekStatus seekCeil(BytesRef text) throws IOException {
                      throw new UnsupportedOperationException();
                    }

                    @Override
                    public void seekExact(long ord) throws IOException {
                      throw new UnsupportedOperationException();
                    }

                    @Override
                    public BytesRef term() throws IOException {
                      return current == null ? null : current.term;
                    }

                    @Override
                    public long ord() throws IOException {
                      throw new UnsupportedOperationException();
                    }

                    @Override
                    public int docFreq() throws IOException {
                      return current == null ? 0 : 1;
                    }

                    @Override
                    public long totalTermFreq() throws IOException {
                      throw new UnsupportedOperationException();
                    }

                    @Override
                    public PostingsEnum postings(Bits liveDocs, PostingsEnum reuse, int flags)
                        throws IOException {
                      final TermPosAndPayload data = current;
                      return new PostingsEnum() {
                        boolean done = false;

                        @Override
                        public int nextPosition() throws IOException {
                          return current.pos;
                        }

                        @Override
                        public int startOffset() throws IOException {
                          return 0;
                        }

                        @Override
                        public int endOffset() throws IOException {
                          return 0;
                        }

                        @Override
                        public BytesRef getPayload() throws IOException {
                          return current.payload;
                        }

                        @Override
                        public int freq() throws IOException {
                          return 1;
                        }

                        @Override
                        public int docID() {
                          if (done) {
                            return NO_MORE_DOCS;
                          }
                          return 0;
                        }

                        @Override
                        public int nextDoc() throws IOException {
                          if (done) {
                            return NO_MORE_DOCS;
                          }
                          done = true;
                          return 0;
                        }

                        @Override
                        public int advance(int target) throws IOException {
                          if (done) {
                            return NO_MORE_DOCS;
                          }
                          done = true;
                          return 0;
                        }

                        @Override
                        public long cost() {
                          return 0;
                        }
                      };
                    }

                    @Override
                    public BytesRef next() throws IOException {
                      if (iterator.hasNext()) {
                        current = iterator.next();
                        return current.term;
                      }
                      current = null;
                      return null;
                    }
                  };
                }

                @Override
                public long size() throws IOException {
                  throw new UnsupportedOperationException();
                }

                @Override
                public long getSumTotalTermFreq() throws IOException {
                  throw new UnsupportedOperationException();
                }

                @Override
                public long getSumDocFreq() throws IOException {
                  throw new UnsupportedOperationException();
                }

                @Override
                public int getDocCount() throws IOException {
                  throw new UnsupportedOperationException();
                }

                @Override
                public boolean hasFreqs() {
                  throw new UnsupportedOperationException();
                }

                @Override
                public boolean hasOffsets() {
                  throw new UnsupportedOperationException();
                }

                @Override
                public boolean hasPositions() {
                  throw new UnsupportedOperationException();
                }

                @Override
                public boolean hasPayloads() {
                  throw new UnsupportedOperationException();
                }
              };
            }
            return null;
          }

          @Override
          public int size() {
            return 0;
          }
        };
    consumer.write(fields);
    consumer.close();
    output.close();
  }