This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ScoreCleaner cleaner = action -> action.run(); // or Runnable::run | |
@Test | |
void delete() { | |
var profile = ScoringProfile.builder().id(profileId).build(); | |
when(versioner.nextVersion(profile)).thenReturn(version); | |
when(persisterSupplier.getPersister(profileId, version)).thenReturn(persister); | |
recalculateService.calculateAndPersist(profile); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ScoreCleaner cleaner = mock(ScoreCleaner.class); | |
@Test | |
void delete() { | |
// I don't care whether the profile is default of not | |
var profile = ScoringProfile.builder().id(profileId).build(); | |
when(versioner.nextVersion(profile)).thenReturn(version); | |
when(persisterSupplier.getPersister(profileId, version)).thenReturn(persister); | |
recalculateService.calculateAndPersist(profile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static Stream<Arguments> deleteParams() { | |
return Stream.of( | |
Arguments.of(true, inactiveScoresToKeep), | |
Arguments.of(false, 0) | |
); | |
} | |
@ParameterizedTest | |
@MethodSource("deleteParams") | |
void delete(boolean isDefault, int expectedScoresToKeep) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void deleteDefault() { | |
var profile = ScoringProfile.builder().id(profileId).defaultProfile(true).build(); | |
setupStubs(profile); | |
recalculateService.calculateAndPersist(profile); | |
verifyMocks(profile, inactiveScoresToKeep); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inOrder.verify(persister).deleteInactive(profileId, inactiveScoresToKeep); | |
inOrder.verify(versioner).deleteInactive(profileId, inactiveScoresToKeep); | |
inOrder.verify(calculator).calculateScores(profile, persister); | |
inOrder.verify(versioner).calculationFinished(version); | |
inOrder.verify(versioner).activateVersion(profile, version); | |
inOrder.verify(persister).deleteInactive(profileId, inactiveScoresToKeep); | |
inOrder.verify(versioner).deleteInactive(profileId, inactiveScoresToKeep); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalculateScoresServiceTest { | |
ScorePersisterSupplier persisterSupplier = mock(ScorePersisterSupplier.class); | |
ScoreVersioner versioner = mock(ScoreVersioner.class); | |
ScoreCalculator calculator = mock(ScoreCalculator.class); | |
int inactiveScoresToKeep = 2; | |
ScorePersister persister = mock(ScorePersister.class); | |
String profileId = "::profileId::"; | |
int version = 1; | |
CalculateScoresService recalculateService = new CalculateScoresService( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExtendWith(PactConsumerTestExt::class) | |
@PactTestFor(providerName = "inventory") | |
class InventoryRepositoryPactTest { | |
@Pact(consumer = "pricing") | |
fun `some items available pact`(builder: PactDslWithProvider): RequestResponsePact = | |
builder | |
.given("some items are available") | |
.uponReceiving("inventory check") | |
.method("POST") | |
.path("/inventory/check") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PriceCartUseCaseTest { | |
val inventory = mockk<Inventory>() | |
val pricingEngine = mockk<PricingEngine>() | |
val useCase = PriceCartUseCase(inventory, pricingEngine) | |
val cartToPrice = Cart(listOf(CartItem("::sku1::", 2), CartItem("::sku2::", 1))) | |
val availableCart = Cart(listOf(CartItem("::sku1::", 1), CartItem("::sku2::", 0))) | |
val unavailableCart = Cart(listOf(CartItem("::sku1::", 0), CartItem("::sku2::", 0))) | |
val pricedCard = PricedCart(emptyList(), 0.toBigDecimal()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExtendWith(SpringExtension::class) | |
@Provider("pricing") | |
@PactBroker(host = "localhost", port = "9292") | |
@WebMvcTest | |
class PricingControllerPactTest { | |
@MockkBean | |
lateinit var useCase: PriceCartUseCase | |
@TestTemplate | |
@ExtendWith(PactVerificationSpringProvider::class) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"description": "get cart total", | |
"request": { | |
"method": "POST", | |
"path": "/cart/total", | |
"body": { | |
"items": [{ | |
"quantity": 4, | |
"sku": "croissants" | |
}, { |
NewerOlder