This repository was archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
h1alexbel
committed
Jun 1, 2023
1 parent
1f16cb6
commit 4b0888d
Showing
8 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.github.eocqrs.events; | ||
|
||
import org.cactoos.set.SetOf; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
import pre.Book; | ||
import pre.BookChain; | ||
import pre.IsbnUpperCase; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski ([email protected]) | ||
* @since 0.0.0 | ||
*/ | ||
public final class EventChainTest { | ||
|
||
@Test | ||
void createsChain() { | ||
final EventChain<Book> chain = new BookChain(new SetOf<>()); | ||
MatcherAssert.assertThat( | ||
"Chain is not null", | ||
chain, | ||
Matchers.notNullValue() | ||
); | ||
} | ||
|
||
@Test | ||
void appendsEventsToChain() { | ||
final EventChain<Book> chain = new BookChain(new SetOf<>()); | ||
final EventChain<Book> after = chain.append(new IsbnUpperCase("test")); | ||
MatcherAssert.assertThat( | ||
"Event is appended to the chain", | ||
after.value(), | ||
Matchers.hasSize(1) | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.eocqrs.events; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
import pre.Book; | ||
import pre.IsbnUpperCase; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski ([email protected]) | ||
* @since 0.0.0 | ||
*/ | ||
public final class EventTest { | ||
|
||
@Test | ||
void changesIsbn() { | ||
final String before = "test"; | ||
final Book book = new Book.Default(before); | ||
final String after = new IsbnUpperCase(book.isbn()) | ||
.value(book) | ||
.isbn(); | ||
MatcherAssert.assertThat( | ||
"ISBN has changed", | ||
after, | ||
Matchers.equalTo(before.toUpperCase(Locale.ROOT)) | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package pre; | ||
|
||
import io.github.eocqrs.events.Resource; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski ([email protected]) | ||
* @since 0.0.0 | ||
*/ | ||
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass") | ||
public interface Book extends Resource<Book> { | ||
|
||
String isbn(); | ||
|
||
@RequiredArgsConstructor | ||
final class Default implements Book { | ||
|
||
private final String isbn; | ||
|
||
@Override | ||
public String isbn() { | ||
return this.isbn; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package pre; | ||
|
||
import io.github.eocqrs.events.Event; | ||
import io.github.eocqrs.events.EventChain; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski ([email protected]) | ||
* @since 0.0.0 | ||
*/ | ||
@RequiredArgsConstructor | ||
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass") | ||
public final class BookChain implements EventChain<Book> { | ||
|
||
private final Set<Event<Book>> events; | ||
|
||
@Override | ||
public Set<Event<Book>> value() { | ||
return Collections.unmodifiableSet(this.events); | ||
} | ||
|
||
@Override | ||
public EventChain<Book> append(final Event<Book> event) { | ||
this.events.add(event); | ||
return new BookChain(this.events); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package pre; | ||
|
||
import io.github.eocqrs.events.Event; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski ([email protected]) | ||
* @since 0.0.0 | ||
*/ | ||
@RequiredArgsConstructor | ||
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass") | ||
public final class IsbnUpperCase implements Event<Book> { | ||
|
||
private final String value; | ||
|
||
@Override | ||
public Book value(final Book book) { | ||
return new Book.Default(this.value.toUpperCase(Locale.ROOT)); | ||
} | ||
|
||
@Override | ||
public String payload() { | ||
return "isbn upper cased -> %s" | ||
.formatted( | ||
this.value | ||
); | ||
} | ||
} |