Skip to content

Commit 93906c0

Browse files
committed
EXCH-13811 Make test more readable
1 parent 252d4db commit 93906c0

File tree

2 files changed

+57
-32
lines changed

2 files changed

+57
-32
lines changed

src/main/java/org/prebid/server/bidder/openx/proto/OpenxBidExt.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package org.prebid.server.bidder.openx.proto;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
46
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
58

69
@Getter
10+
@Builder
11+
@NoArgsConstructor
12+
@AllArgsConstructor
713
public class OpenxBidExt {
814

915
@JsonProperty("dsp_id")

src/test/java/org/prebid/server/bidder/openx/OpenxBidderTest.java

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.prebid.server.bidder.model.HttpRequest;
2828
import org.prebid.server.bidder.model.HttpResponse;
2929
import org.prebid.server.bidder.model.Result;
30+
import org.prebid.server.bidder.openx.proto.OpenxBidExt;
3031
import org.prebid.server.bidder.openx.proto.OpenxBidResponse;
3132
import org.prebid.server.bidder.openx.proto.OpenxBidResponseExt;
3233
import org.prebid.server.bidder.openx.proto.OpenxRequestExt;
@@ -996,23 +997,50 @@ private static BidderCall<BidRequest> givenHttpCall(String body) {
996997
return BidderCall.succeededHttp(null, HttpResponse.of(200, null, body), null);
997998
}
998999

999-
private static Stream<Arguments> makeBidsShouldReturnBidWithExtBidPrebidMetaArgs() throws JsonProcessingException {
1000-
final ObjectNode allBuyerExt = new ObjectNode(JsonNodeFactory.instance);
1001-
final ObjectNode onlyBrandExt = new ObjectNode(JsonNodeFactory.instance);
1002-
final ObjectNode badExt = new ObjectNode(JsonNodeFactory.instance);
1003-
1004-
allBuyerExt.put("dsp_id", "1").put("buyer_id", "2").put("brand_id", "3");
1005-
onlyBrandExt.put("brand_id", "4");
1006-
badExt.put("dsp_id", "abc").put("brand_id", "cba");
1007-
1008-
final String allBuyerExpectedExtJson = "{\"dsp_id\":\"1\",\"buyer_id\":\"2\",\"brand_id\":\"3\",\"prebid\":"
1009-
+ "{\"meta\":{\"advertiserId\":2,\"brandId\":3,\"networkId\":1}}}";
1010-
final String onlyBrandExpectedExtJson = "{\"brand_id\":\"4\",\"prebid\":{\"meta\":{\"brandId\":4}}}";
1011-
final String badExpectedExtJson = "{\"dsp_id\":\"abc\",\"brand_id\":\"cba\"}";
1012-
1013-
final ObjectNode allBuyerExpectedExt = (ObjectNode) mapper.readTree(allBuyerExpectedExtJson);
1014-
final ObjectNode onlyBrandExpectedExt = (ObjectNode) mapper.readTree(onlyBrandExpectedExtJson);
1015-
final ObjectNode badExpectedExt = (ObjectNode) mapper.readTree(badExpectedExtJson);
1000+
private static Stream<Arguments> bidWithExtTestCases() throws JsonProcessingException {
1001+
final ObjectNode allBuyerExt = mapper.valueToTree(OpenxBidExt.builder()
1002+
.dspId("1")
1003+
.buyerId("2")
1004+
.brandId("3")
1005+
.build());
1006+
final ObjectNode onlyBrandExt = mapper.valueToTree(OpenxBidExt.builder()
1007+
.brandId("4")
1008+
.build());
1009+
final ObjectNode badExt = mapper.valueToTree(OpenxBidExt.builder()
1010+
.dspId("abc")
1011+
.brandId("cba")
1012+
.build());
1013+
1014+
final ObjectNode allBuyerExpectedExt = (ObjectNode) mapper.readTree("""
1015+
{
1016+
"dsp_id": "1",
1017+
"buyer_id": "2",
1018+
"brand_id": "3",
1019+
"prebid": {
1020+
"meta": {
1021+
"advertiserId":2,
1022+
"brandId":3,
1023+
"networkId":1
1024+
}
1025+
}
1026+
}
1027+
""");
1028+
final ObjectNode onlyBrandExpectedExt = (ObjectNode) mapper.readTree("""
1029+
{
1030+
"brand_id": "4",
1031+
"prebid": {
1032+
"meta": {
1033+
"brandId":4
1034+
}
1035+
}
1036+
}
1037+
""");
1038+
final ObjectNode badExpectedExt = (ObjectNode) mapper.readTree("""
1039+
{
1040+
"dsp_id": "abc",
1041+
"brand_id": "cba"
1042+
}
1043+
""");
10161044

10171045
return Stream.of(
10181046
Arguments.of(allBuyerExt, allBuyerExpectedExt),
@@ -1023,8 +1051,8 @@ private static Stream<Arguments> makeBidsShouldReturnBidWithExtBidPrebidMetaArgs
10231051
}
10241052

10251053
@ParameterizedTest
1026-
@MethodSource("makeBidsShouldReturnBidWithExtBidPrebidMetaArgs")
1027-
public void makeBidsShouldReturnBidWithExtBidPrebidMeta(
1054+
@MethodSource("bidWithExtTestCases")
1055+
public void makeBidsShouldReturnBidWithExt(
10281056
ObjectNode bidExt,
10291057
ObjectNode expectedExtWithBidMeta) throws JsonProcessingException {
10301058
// given
@@ -1058,18 +1086,9 @@ public void makeBidsShouldReturnBidWithExtBidPrebidMeta(
10581086

10591087
// then
10601088
assertThat(result.getErrors()).isEmpty();
1061-
assertThat(result.getBids()).hasSize(1).containsExactlyInAnyOrder(
1062-
BidderBid.of(
1063-
Bid.builder()
1064-
.impid("impId1")
1065-
.price(BigDecimal.ONE)
1066-
.dealid("dealid")
1067-
.w(200)
1068-
.h(150)
1069-
.adm("<div>This is an Ad</div>")
1070-
.ext(expectedExtWithBidMeta)
1071-
.build(),
1072-
BidType.banner, "USD")
1073-
);
1089+
assertThat(result.getBids()).hasSize(1)
1090+
.extracting(BidderBid::getBid)
1091+
.extracting(Bid::getExt)
1092+
.containsExactly(expectedExtWithBidMeta);
10741093
}
10751094
}

0 commit comments

Comments
 (0)