Skip to content

Commit

Permalink
task-builder-done
Browse files Browse the repository at this point in the history
  • Loading branch information
yacekmm committed Dec 6, 2024
1 parent e9ef46e commit 97549c3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -27,8 +26,7 @@ private static Stream<Arguments> provideStringsForTags() {
@MethodSource("provideStringsForTags")
void initConcert_addsTags(String title, Set<String> 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);
Expand All @@ -52,8 +50,7 @@ private static Stream<Arguments> 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);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -40,8 +40,4 @@ public RequestSpecification aRequestSpec(){
.basePath(ApiVersions.V1)
.contentType(JSON);
}

public ConcertBuilder concert(){
return new ConcertBuilder(clock);
}
}

0 comments on commit 97549c3

Please sign in to comment.