// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class InventoryDecreased implements Event {
//     @NonNull
//     UUID id;
//     @NonNull
//     Integer howMany;
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class InventoryIncreased implements Event {
//     @NonNull
//     UUID id;
//     @NonNull
//     Integer howMany;
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Data
// public static class InventoryItemAggregateRoot implements AggregateRoot {
// 
//     UUID id;
//     String description;
//     Integer available = 0;
// 
//     public void on(InventoryItemCreated event) {
//         this.id = event.id;
//         this.description = event.description;
//         this.available = 0;
//     }
// 
//     public void on(InventoryIncreased event) {
//         this.available = this.available + event.howMany;
//     }
// 
//     public void on(InventoryDecreased event) {
//         this.available = this.available - event.howMany;
//     }
//         
//     public boolean isAvailable(int howMany) {
//         return getAvailable() - howMany >= 0;
//     }
// 
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class InventoryItemCreated implements Event {
//     @NonNull
//     UUID id;
//     @NonNull
//     String description;
// }


import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.UUID;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.myeslib.example.SampleDomain.InventoryDecreased;
import org.myeslib.example.SampleDomain.InventoryIncreased;
import org.myeslib.example.SampleDomain.InventoryItemAggregateRoot;
import org.myeslib.example.SampleDomain.InventoryItemCreated;
		
		InventoryItemAggregateRoot aggregateRoot = new InventoryItemAggregateRoot();
		
		UUID id = UUID.randomUUID();
		String desc = "item1";
		
		aggregateRoot.setAvailable(0);
		aggregateRoot.setDescription(desc);
		aggregateRoot.setId(id);
		
		InventoryIncreased event = new InventoryIncreased(id, 2);
		
		aggregateRoot.on(event);
		
		assertThat(aggregateRoot.getAvailable(), equalTo(2));
		
	}
	
	@Test
	public void decreased() {
		
		InventoryItemAggregateRoot aggregateRoot = new InventoryItemAggregateRoot();
		
		UUID id = UUID.randomUUID();
		String desc = "item1";
		
		aggregateRoot.setAvailable(5);
		aggregateRoot.setDescription(desc);
		aggregateRoot.setId(id);
		
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class InventoryDecreased implements Event {
//     @NonNull
//     UUID id;
//     @NonNull
//     Integer howMany;
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class InventoryIncreased implements Event {
//     @NonNull
//     UUID id;
//     @NonNull
//     Integer howMany;
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Data
// public static class InventoryItemAggregateRoot implements AggregateRoot {
// 
//     UUID id;
//     String description;
//     Integer available = 0;
// 
//     public void on(InventoryItemCreated event) {
//         this.id = event.id;
//         this.description = event.description;
//         this.available = 0;
//     }
// 
//     public void on(InventoryIncreased event) {
//         this.available = this.available + event.howMany;
//     }
// 
//     public void on(InventoryDecreased event) {
//         this.available = this.available - event.howMany;
//     }
//         
//     public boolean isAvailable(int howMany) {
//         return getAvailable() - howMany >= 0;
//     }
// 
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class InventoryItemCreated implements Event {
//     @NonNull
//     UUID id;
//     @NonNull
//     String description;
// }


// Path: inventory-aggregate-root/src/test/java/org/myeslib/example/InventoryItemAggregateRootTest.java
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.UUID;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.myeslib.example.SampleDomain.InventoryDecreased;
import org.myeslib.example.SampleDomain.InventoryIncreased;
import org.myeslib.example.SampleDomain.InventoryItemAggregateRoot;
import org.myeslib.example.SampleDomain.InventoryItemCreated;

		
		InventoryItemAggregateRoot aggregateRoot = new InventoryItemAggregateRoot();
		
		UUID id = UUID.randomUUID();
		String desc = "item1";
		
		aggregateRoot.setAvailable(0);
		aggregateRoot.setDescription(desc);
		aggregateRoot.setId(id);
		
		InventoryIncreased event = new InventoryIncreased(id, 2);
		
		aggregateRoot.on(event);
		
		assertThat(aggregateRoot.getAvailable(), equalTo(2));
		
	}
	
	@Test
	public void decreased() {
		
		InventoryItemAggregateRoot aggregateRoot = new InventoryItemAggregateRoot();
		
		UUID id = UUID.randomUUID();
		String desc = "item1";
		
		aggregateRoot.setAvailable(5);
		aggregateRoot.setDescription(desc);
		aggregateRoot.setId(id);
		
		InventoryDecreased event = new InventoryDecreased(id, 2);