VariantListBuilderImpl extends VariantListBuilder { @Override public VariantListBuilder add() { checkState(!(mediaTypes.isEmpty() && languages.isEmpty() && encodings.isEmpty()), "At least one media type, language or encoding must be set"); if (variants == null) { variants = new ArrayList<>(); } Iterator<MediaType> mediaTypesIterator = mediaTypes.iterator(); do { MediaType mediaType = mediaTypesIterator.hasNext() ? mediaTypesIterator.next() : null; Iterator<Locale> languagesIterator = languages.iterator(); do { Locale language = languagesIterator.hasNext() ? languagesIterator.next() : null; Iterator<String> encodingsIterator = encodings.iterator(); do { String encoding = encodingsIterator.hasNext() ? encodingsIterator.next() : null; variants.add(new Variant(mediaType, language, encoding)); } while (encodingsIterator.hasNext()); } while (languagesIterator.hasNext()); } while (mediaTypesIterator.hasNext()); clearAll(); return this; } VariantListBuilderImpl(); @Override VariantListBuilder add(); @Override List<Variant> build(); @Override VariantListBuilder encodings(String... encodings); @Override VariantListBuilder languages(Locale... languages); @Override VariantListBuilder mediaTypes(MediaType... mediaTypes);  }
@Test(expected = IllegalStateException.class) public void throwsExceptionOnAddIfNotAtLeastOneMediaTypeLanguageOrEncodingSet() { variantListBuilder.add(); }