Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit 72f600c

Browse files
committed
Add the unit test for the VideoPublisher
1 parent 41530f8 commit 72f600c

File tree

5 files changed

+69
-18
lines changed

5 files changed

+69
-18
lines changed

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ targetCompatibility = 1.11
66

77
repositories {
88
mavenCentral()
9+
jcenter()
910
}
1011

1112
dependencies {
1213
// Prod
13-
implementation('io.projectreactor:reactor-bus:2.0.8.RELEASE')
14+
implementation 'io.projectreactor:reactor-bus:2.0.8.RELEASE'
1415

1516
// Test
16-
testCompile('org.junit.jupiter:junit-jupiter-api:5.3.2')
17-
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.3.2')
17+
testCompile "org.mockito:mockito-core:2.+"
18+
testCompile 'org.junit.jupiter:junit-jupiter-api:5.+'
19+
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.+'
1820
}
1921

2022
test {

src/main/java/tv/codely/context/video/module/video/domain/VideoDescription.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,19 @@ public VideoDescription(final String value) {
1010
public String value() {
1111
return value;
1212
}
13+
14+
@Override
15+
public boolean equals(Object o) {
16+
if (this == o) return true;
17+
if (o == null || getClass() != o.getClass()) return false;
18+
19+
VideoDescription that = (VideoDescription) o;
20+
21+
return value.equals(that.value);
22+
}
23+
24+
@Override
25+
public int hashCode() {
26+
return value.hashCode();
27+
}
1328
}

src/main/java/tv/codely/context/video/module/video/domain/VideoPublished.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,22 @@ public String title() {
2424
public String description() {
2525
return description;
2626
}
27+
28+
@Override
29+
public boolean equals(Object o) {
30+
if (this == o) return true;
31+
if (o == null || getClass() != o.getClass()) return false;
32+
33+
VideoPublished that = (VideoPublished) o;
34+
35+
if (!title.equals(that.title)) return false;
36+
return description.equals(that.description);
37+
}
38+
39+
@Override
40+
public int hashCode() {
41+
int result = title.hashCode();
42+
result = 31 * result + description.hashCode();
43+
return result;
44+
}
2745
}

src/main/java/tv/codely/context/video/module/video/domain/VideoTitle.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,19 @@ public VideoTitle(String value) {
1010
public String value() {
1111
return value;
1212
}
13+
14+
@Override
15+
public boolean equals(Object o) {
16+
if (this == o) return true;
17+
if (o == null || getClass() != o.getClass()) return false;
18+
19+
VideoTitle that = (VideoTitle) o;
20+
21+
return value.equals(that.value);
22+
}
23+
24+
@Override
25+
public int hashCode() {
26+
return value.hashCode();
27+
}
1328
}
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
package tv.codely.context.video.module.video.application.publish;
22

33
import org.junit.jupiter.api.Test;
4-
import tv.codely.context.notification.module.push.application.create.SendPushToSubscribersOnVideoPublished;
5-
import tv.codely.shared.application.DomainEventSubscriber;
4+
import tv.codely.context.video.module.video.domain.VideoPublished;
65
import tv.codely.shared.domain.EventBus;
7-
import tv.codely.shared.infrastructure.bus.ReactorEventBus;
86

9-
import java.util.Set;
7+
import java.util.List;
8+
9+
import static org.mockito.Mockito.mock;
10+
import static org.mockito.Mockito.verify;
1011

1112
final class VideoPublisherShould {
12-
@Test
13-
void publish_the_video_published_domain_event() {
14-
final Set<DomainEventSubscriber> subscribers = Set.of(
15-
new SendPushToSubscribersOnVideoPublished()
16-
);
17-
final EventBus eventBus = new ReactorEventBus(subscribers);
18-
final var videoPublisher = new VideoPublisher(eventBus);
13+
@Test
14+
void publish_the_video_published_domain_event() {
15+
final EventBus eventBus = mock(EventBus.class);
16+
final var videoPublisher = new VideoPublisher(eventBus);
17+
18+
final var videoTitle = "\uD83C\uDF89 New YouTube.com/CodelyTV video title";
19+
final var videoDescription = "This should be the video description \uD83D\uDE42";
1920

20-
final var videoTitle = "\uD83C\uDF89 New YouTube.com/CodelyTV video title";
21-
final var videoDescription = "This should be the video description \uD83D\uDE42";
21+
videoPublisher.publish(videoTitle, videoDescription);
2222

23-
videoPublisher.publish(videoTitle, videoDescription);
23+
final var expectedVideoCreated = new VideoPublished(videoTitle, videoDescription);
2424

25-
}
25+
verify(eventBus).publish(List.of(expectedVideoCreated));
26+
}
2627

2728
}

0 commit comments

Comments
 (0)