From 97549c35431456099c26995c6469eed77998a3c5 Mon Sep 17 00:00:00 2001 From: Jacek Milewski Date: Fri, 29 Dec 2023 17:43:05 +0100 Subject: [PATCH] task-builder-done --- .../domain/Concert_initConcert_unitTest.java | 9 +-- .../promoter/concert/fixtures/Builder.java | 65 ------------------- .../concert/fixtures/ConcertBuilder.java | 45 +++++++++++-- .../promoter/fixtures/TestBuilders.java | 10 +-- 4 files changed, 46 insertions(+), 83 deletions(-) delete mode 100644 services/Promoter/src/test/java/com/bottega/promoter/concert/fixtures/Builder.java diff --git a/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/Concert_initConcert_unitTest.java b/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/Concert_initConcert_unitTest.java index 247d032e..9cc0979e 100644 --- a/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/Concert_initConcert_unitTest.java +++ b/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/Concert_initConcert_unitTest.java @@ -1,12 +1,11 @@ package com.bottega.promoter.concert.domain; -import java.util.*; +import java.util.Set; import java.util.stream.Stream; import com.bottega.promoter.concert.fixtures.ConcertLogicTestBase; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.*; -import static com.bottega.sharedlib.config.TestClockConfig.TEST_TIME_PLUS_30_DAYS; import static java.util.stream.Collectors.toSet; import static org.assertj.core.api.Assertions.assertThat; @@ -27,8 +26,7 @@ private static Stream provideStringsForTags() { @MethodSource("provideStringsForTags") void initConcert_addsTags(String title, Set expectedTags) { //given - //TODO use builder - Concert newConcert = new Concert(new ConcertId(), Title.from(title).get(), ConcertDate.from(TEST_TIME_PLUS_30_DAYS.toString(), sharedFixtures.clock).get(), "vendor-id", new HashSet<>(), null); + Concert newConcert = builders.aConcert().withTitle(title).build(); //when newConcert.initNewConcert(concertFixtures.tagService, concertFixtures.categoryService); @@ -52,8 +50,7 @@ private static Stream provideStringsForCategories() { @MethodSource("provideStringsForCategories") void initConcert_assignsCategory(String title, String expectedCategory) { //given - //TODO use builder - Concert newConcert = new Concert(new ConcertId(), Title.from(title).get(), ConcertDate.from(TEST_TIME_PLUS_30_DAYS.toString(), sharedFixtures.clock).get(), "vendor-id", new HashSet<>(), null); + Concert newConcert = builders.aConcert().withTitle(title).build(); //when newConcert.initNewConcert(concertFixtures.tagService, concertFixtures.categoryService); diff --git a/services/Promoter/src/test/java/com/bottega/promoter/concert/fixtures/Builder.java b/services/Promoter/src/test/java/com/bottega/promoter/concert/fixtures/Builder.java deleted file mode 100644 index a430eb58..00000000 --- a/services/Promoter/src/test/java/com/bottega/promoter/concert/fixtures/Builder.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.bottega.promoter.concert.fixtures; - -import java.time.*; -import java.util.HashSet; - -import com.bottega.promoter.concert.domain.*; -import com.bottega.promoter.concert.infra.repo.ConcertRepo; -import com.bottega.promoter.concertRead.ConcertFinderRepo; -import org.springframework.stereotype.Component; -import static com.bottega.sharedlib.config.TestClockConfig.TEST_TIME_PLUS_30_DAYS; - -@Component -public class Builder { - - private final ConcertRepo concertRepo; - private final ConcertFinderRepo concertFinderRepo; - private final Clock clock; - private final Concert.ConcertBuilder builder; - - public Builder(ConcertRepo concertRepo, ConcertFinderRepo concertFinderRepo, Clock clock) { - this.concertRepo = concertRepo; - this.concertFinderRepo = concertFinderRepo; - this.clock = clock; - this.builder = Concert.builder() - .id(new ConcertId()) - .tags(new HashSet<>()) - .category(null); - - this.withTitle("mock title of a concert") - .withDate(TEST_TIME_PLUS_30_DAYS) - .withPromoterId("mock-promoter-id"); - } - - public Concert build() { - return builder.build(); - } - - public Concert inDb() { - return concertRepo.save(build()); - } - - public Concert inFinderDb() { - return concertFinderRepo.save(build()); - } - - public Builder withTitle(String title) { - builder.title(Title.from(title).get()); - return this; - } - - public Builder withDate(Instant date) { - builder.date(ConcertDate.from(date.toString(), clock).get()); - return this; - } - - public Builder withPromoterId(String promoterId) { - builder.promoterId(promoterId); - return this; - } - - public Builder withId(String id) { - builder.id(new ConcertId(id)); - return this; - } -} diff --git a/services/Promoter/src/test/java/com/bottega/promoter/concert/fixtures/ConcertBuilder.java b/services/Promoter/src/test/java/com/bottega/promoter/concert/fixtures/ConcertBuilder.java index 4d1d5f12..1aa85bc6 100644 --- a/services/Promoter/src/test/java/com/bottega/promoter/concert/fixtures/ConcertBuilder.java +++ b/services/Promoter/src/test/java/com/bottega/promoter/concert/fixtures/ConcertBuilder.java @@ -12,19 +12,54 @@ @Component public class ConcertBuilder { + private final ConcertRepo concertRepo; + private final ConcertFinderRepo concertFinderRepo; private final Clock clock; private final Concert.ConcertBuilder builder; - public ConcertBuilder(Clock clock) { + public ConcertBuilder(ConcertRepo concertRepo, ConcertFinderRepo concertFinderRepo, Clock clock) { + this.concertRepo = concertRepo; + this.concertFinderRepo = concertFinderRepo; this.clock = clock; this.builder = Concert.builder() .id(new ConcertId()) - .title(Title.from("mock title of a concert").get()) - .date(ConcertDate.from(TEST_TIME_PLUS_30_DAYS.toString(), this.clock).get()) - .promoterId("mock-promoter-id") .tags(new HashSet<>()) .category(null); + + this.withTitle("mock title of a concert") + .withDate(TEST_TIME_PLUS_30_DAYS) + .withPromoterId("mock-promoter-id"); + } + + public Concert build() { + return builder.build(); + } + + public Concert inDb() { + return concertRepo.save(build()); + } + + public Concert inFinderDb() { + return concertFinderRepo.save(build()); } - //TODO implement builder + public ConcertBuilder withTitle(String title) { + builder.title(Title.from(title).get()); + return this; + } + + public ConcertBuilder withDate(Instant date) { + builder.date(ConcertDate.from(date.toString(), clock).get()); + return this; + } + + public ConcertBuilder withPromoterId(String promoterId) { + builder.promoterId(promoterId); + return this; + } + + public ConcertBuilder withId(String id) { + builder.id(new ConcertId(id)); + return this; + } } diff --git a/services/Promoter/src/test/java/com/bottega/promoter/fixtures/TestBuilders.java b/services/Promoter/src/test/java/com/bottega/promoter/fixtures/TestBuilders.java index ae6fd7a8..8916c08c 100644 --- a/services/Promoter/src/test/java/com/bottega/promoter/fixtures/TestBuilders.java +++ b/services/Promoter/src/test/java/com/bottega/promoter/fixtures/TestBuilders.java @@ -2,7 +2,7 @@ import java.time.Clock; -import com.bottega.promoter.concert.fixtures.*; +import com.bottega.promoter.concert.fixtures.ConcertBuilder; import com.bottega.promoter.concert.infra.repo.ConcertRepo; import com.bottega.promoter.concertRead.ConcertFinderRepo; import com.bottega.sharedlib.config.ApiVersions; @@ -24,8 +24,8 @@ public class TestBuilders { @Value("${server.port}") private int port; - public Builder aConcert() { - return new Builder(concertRepo, concertFinderRepo, clock); + public ConcertBuilder aConcert() { + return new ConcertBuilder(concertRepo, concertFinderRepo, clock); } public PromoterAgreementBuilder aPromoterAgreement() { @@ -40,8 +40,4 @@ public RequestSpecification aRequestSpec(){ .basePath(ApiVersions.V1) .contentType(JSON); } - - public ConcertBuilder concert(){ - return new ConcertBuilder(clock); - } }