public static BidRequest.Builder newBidRequest(String id, Object... adGroupMincpm) {
    BidRequest.Builder request = BidRequest.newBuilder().setId(id);

    for (int i = 0; i < adGroupMincpm.length; i += 3) {
      String adid = String.valueOf(adGroupMincpm[i + 0]);
      request.addImp(
          Impression.newBuilder()
              .setId(adid)
              .setBidfloor(((Number) adGroupMincpm[i + 2]).floatValue())
              .setBanner(Banner.newBuilder().setId(adid).setW(728).setH(90)));
    }

    return request;
  }
  @Test
  public void testRequest() throws IOException {
    // -1=NO_SLOT, 0=no size, 1, 2=multisize/1 MAD, 3=2 MAD/1 deal, 4..8=3 MAD/2 deals
    for (int size = -1; size <= 8; ++size) {
      for (int flags = 0; flags < 0b10000; ++flags) {
        boolean coppa = (flags & 0b1) != 0;
        boolean mobile = (flags & 0b1) != 0;
        boolean impVideo = (flags & 0b10) != 0;
        boolean impNativ = !impVideo && (flags & 0b100) != 0;
        boolean impBanner = !impVideo && !impNativ;
        boolean multiBid = (flags & 0b1000) != 0;
        boolean linkExt = (flags & 0b1000) != 0;
        String testDesc =
            String.format(
                "imp=%s, mobile=%s, coppa=%s, link=%s, size=%s%s",
                (impNativ ? "native" : impVideo ? "video" : "banner"),
                mobile,
                coppa,
                linkExt,
                size,
                multiBid ? "/full" : "");
        ImmutableList.Builder<ExtMapper> extMappers = ImmutableList.builder();
        if (linkExt) {
          extMappers.add(DoubleClickLinkMapper.INSTANCE);
        }
        DoubleClickOpenRtbMapper mapper =
            new DoubleClickOpenRtbMapper(
                new MetricRegistry(),
                TestUtil.getMetadata(),
                OpenRtbJsonFactory.create(),
                extMappers.build());

        NetworkBid.BidRequest.Builder dcRequest = TestData.newRequest(size, coppa, impNativ);
        if (mobile) {
          dcRequest.setMobile(TestData.newMobile(size, coppa));
        }
        if (impVideo) {
          dcRequest.setVideo(TestData.newVideo(size));
        }
        BidRequest request = mapper.toOpenRtbBidRequest(dcRequest.build()).build();

        assertWithMessage(testDesc).that(request.getRegs().hasCoppa()).isEqualTo(coppa);
        assertWithMessage(testDesc).that(request.getRegs().getCoppa()).isEqualTo(coppa);
        assertWithMessage(testDesc)
            .that(request.getUser().getCustomdata())
            .isEqualTo(coppa ? "" : "7CLmnMiwSsq7bNTaiPsztg");

        if (request.getImpCount() == 0) {
          BidResponse response = TestUtil.newBidResponse();
          NetworkBid.BidResponse dcResponse =
              mapper.toExchangeBidResponse(request, response).build();
          assertWithMessage(testDesc).that(dcResponse.getAdCount()).isEqualTo(0);
        } else {
          Imp imp = request.getImp(0);
          assertWithMessage(testDesc).that(imp.hasVideo()).isEqualTo(impVideo);
          assertWithMessage(testDesc).that(imp.hasBanner()).isEqualTo(impBanner);
          assertWithMessage(testDesc).that(imp.hasNative()).isEqualTo(impNativ);
          if (impVideo) {
            if (imp.getVideo().getCompanionadCount() != 0) {
              Banner compAd = imp.getVideo().getCompanionad(0);
              assertWithMessage(testDesc)
                  .that(
                      compAd.hasWmin() && compAd.hasWmax() && compAd.hasHmin() && compAd.hasHmax())
                  .isEqualTo(size > 1);
              assertWithMessage(testDesc)
                  .that(compAd.hasW() && compAd.hasH())
                  .isNotEqualTo(size == 0);
            }
          } else if (impBanner) {
            Banner banner = imp.getBanner();
            assertWithMessage(testDesc)
                .that(banner.hasWmin() && banner.hasWmax() && banner.hasHmin() && banner.hasHmax())
                .isEqualTo(size > 1);
            assertWithMessage(testDesc)
                .that(banner.hasW() && banner.hasH())
                .isNotEqualTo(size == 0);
            assertWithMessage(testDesc).that(banner.hasTopframe()).isEqualTo(size >= 2);
          } else if (impNativ) {
            Native nativ = imp.getNative();
            assertWithMessage(testDesc)
                .that(nativ.getRequestNative().getAssetsCount())
                .isEqualTo(size == 0 ? 5 : 10);
          }

          Bid.Builder bid = TestData.newBid(multiBid || imp.getInstl());
          if (impNativ) {
            NativeResponse nativResp = TestData.newNativeResponse(size - 1).build();
            if (size % 2 == 0) {
              bid.clearAdm().setAdmNative(nativResp);
            } else {
              bid.setAdm(
                  OpenRtbJsonFactory.create().newNativeWriter().writeNativeResponse(nativResp));
            }
          }
          BidResponse response = TestUtil.newBidResponse(bid);
          NetworkBid.BidResponse dcResponse =
              mapper.toExchangeBidResponse(request, response).build();
          if (linkExt) {
            Ad ad = dcResponse.getAd(0);
            assertWithMessage(testDesc)
                .that(ad.hasWidth())
                .isEqualTo(((size > 1 && multiBid) || imp.getInstl()) && !impNativ);
            assertWithMessage(testDesc)
                .that(ad.getAdslot(0).hasBillingId())
                .isEqualTo(size > 2 && multiBid);
          }
        }
      }
    }
  }