Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
#40
Browse files Browse the repository at this point in the history
h1alexbel committed Jun 1, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1f16cb6 commit 4b0888d
Showing 8 changed files with 155 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/it/events/src/test/java/ChangeUsernameTest.java
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ void changesUsername() {
MatcherAssert.assertThat(
"Name has changed",
new ChangeUsername(name)
.submitTo(user)
.value(user)
.username(),
Matchers.equalTo(name)
);
2 changes: 1 addition & 1 deletion src/it/events/src/test/java/prep/ChangeUsername.java
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ public final class ChangeUsername implements Event<User> {
private final String name;

@Override
public User submitTo(final User user) {
public User value(final User user) {
return new EnUser(user.id(), this.name);
}

2 changes: 1 addition & 1 deletion src/main/java/io/github/eocqrs/events/Event.java
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public interface Event<X extends Resource<X>> {
* @param res Object for whom event will be submitted
* @return New version of Resource
*/
X submitTo(X res);
X value(X res);

/**
* Event payload.
37 changes: 37 additions & 0 deletions src/test/java/io/github/eocqrs/events/EventChainTest.java
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)
);
}
}
30 changes: 30 additions & 0 deletions src/test/java/io/github/eocqrs/events/EventTest.java
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))
);
}
}
25 changes: 25 additions & 0 deletions src/test/java/pre/Book.java
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;
}
}
}
30 changes: 30 additions & 0 deletions src/test/java/pre/BookChain.java
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);
}
}
30 changes: 30 additions & 0 deletions src/test/java/pre/IsbnUpperCase.java
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
);
}
}

0 comments on commit 4b0888d

Please sign in to comment.