Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aludwiko committed Dec 27, 2024
1 parent 7d6178a commit 6f804bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package store.customer.api;

import akka.Done;
import akka.javasdk.testkit.EventSourcedResult;
import akka.javasdk.testkit.EventSourcedTestKit;
import org.junit.jupiter.api.Test;
Expand All @@ -8,6 +9,7 @@
import store.customer.domain.Customer;
import store.customer.domain.CustomerEvent;

import static akka.Done.done;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static store.customer.domain.CustomerEvent.CustomerAddressChanged;
import static store.customer.domain.CustomerEvent.CustomerCreated;
Expand All @@ -25,16 +27,16 @@ public void testCustomerNameChange() {
String name = "Some Customer";
Address address = new Address("123 Some Street", "Some City");
Customer customer = new Customer("[email protected]", name, address);
EventSourcedResult<String> result = testKit.call(entity -> entity.create(customer));
assertEquals("OK", result.getReply());
EventSourcedResult<Done> result = testKit.call(entity -> entity.create(customer));
assertEquals(done(), result.getReply());
assertEquals(name, testKit.getState().name());
result.getNextEventOfType(CustomerCreated.class);
}

{
String newName = "Some Name";
EventSourcedResult<String> result = testKit.call(entity -> entity.changeName(newName));
assertEquals("OK", result.getReply());
EventSourcedResult<Done> result = testKit.call(entity -> entity.changeName(newName));
assertEquals(done(), result.getReply());
assertEquals(newName, testKit.getState().name());
result.getNextEventOfType(CustomerNameChanged.class);
}
Expand All @@ -49,17 +51,17 @@ public void testCustomerAddressChange() {
{
Address address = new Address("123 Some Street", "Some City");
Customer customer = new Customer("[email protected]", "Some Customer", address);
EventSourcedResult<String> result = testKit.call(e -> e.create(customer));
assertEquals("OK", result.getReply());
EventSourcedResult<Done> result = testKit.call(e -> e.create(customer));
assertEquals(done(), result.getReply());
assertEquals(address.street(), testKit.getState().address().street());
assertEquals(address.city(), testKit.getState().address().city());
result.getNextEventOfType(CustomerCreated.class);
}

{
Address newAddress = new Address("42 Some Road", "Some Other City");
EventSourcedResult<String> result = testKit.call(e -> e.changeAddress(newAddress));
assertEquals("OK", result.getReply());
EventSourcedResult<Done> result = testKit.call(e -> e.changeAddress(newAddress));
assertEquals(done(), result.getReply());
assertEquals(newAddress.street(), testKit.getState().address().street());
assertEquals(newAddress.city(), testKit.getState().address().city());
result.getNextEventOfType(CustomerAddressChanged.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package store.product.api;

import akka.Done;
import akka.javasdk.testkit.EventSourcedResult;
import akka.javasdk.testkit.EventSourcedTestKit;
import org.junit.jupiter.api.Test;
Expand All @@ -8,6 +9,7 @@
import store.product.domain.Product;
import store.product.domain.ProductEvent;

import static akka.Done.done;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ProductEntityTest {
Expand All @@ -21,16 +23,16 @@ public void testProductNameChange() {
{
String name = "Super Duper Thingamajig";
Product product = new Product(name, new Money("USD", 123, 45));
EventSourcedResult<String> result = testKit.call(entity -> entity.create(product));
assertEquals("OK", result.getReply());
EventSourcedResult<Done> result = testKit.call(entity -> entity.create(product));
assertEquals(done(), result.getReply());
assertEquals(name, testKit.getState().name());
result.getNextEventOfType(ProductEvent.ProductCreated.class);
}

{
String newName = "Thing Supreme";
EventSourcedResult<String> result = testKit.call(entity -> entity.changeName(newName));
assertEquals("OK", result.getReply());
EventSourcedResult<Done> result = testKit.call(entity -> entity.changeName(newName));
assertEquals(done(), result.getReply());
assertEquals(newName, testKit.getState().name());
result.getNextEventOfType(ProductEvent.ProductNameChanged.class);
}
Expand All @@ -45,8 +47,8 @@ public void testProductPriceChange() {
{
Money price = new Money("USD", 123, 45);
Product product = new Product("Super Duper Thingamajig", price);
EventSourcedResult<String> result = testKit.call(e -> e.create(product));
assertEquals("OK", result.getReply());
EventSourcedResult<Done> result = testKit.call(e -> e.create(product));
assertEquals(done(), result.getReply());
assertEquals(price.currency(), testKit.getState().price().currency());
assertEquals(price.units(), testKit.getState().price().units());
assertEquals(price.cents(), testKit.getState().price().cents());
Expand All @@ -55,8 +57,8 @@ public void testProductPriceChange() {

{
Money newPrice = new Money("USD", 56, 78);
EventSourcedResult<String> result = testKit.call(e -> e.changePrice(newPrice));
assertEquals("OK", result.getReply());
EventSourcedResult<Done> result = testKit.call(e -> e.changePrice(newPrice));
assertEquals(done(), result.getReply());
assertEquals(newPrice.currency(), testKit.getState().price().currency());
assertEquals(newPrice.units(), testKit.getState().price().units());
assertEquals(newPrice.cents(), testKit.getState().price().cents());
Expand Down

0 comments on commit 6f804bf

Please sign in to comment.