Skip to content

Commit

Permalink
fix : assertion in junit
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Sep 30, 2023
1 parent c1c1dc3 commit f9c4e38
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

class WebRouterConfigIT extends AbstractIntegrationTest {

Expand Down Expand Up @@ -62,7 +60,11 @@ void searchPosts() {
void willCreatePosts() {
CreatePostCommand createPost =
new CreatePostCommand("junitTitle", "junitContent", List.of("junitTag"));
Mono<Long> count = tagRepository.count();

// Save the initial count of tags
Long initialCount = tagRepository.count().block();

// Create the first post
this.webTestClient
.post()
.uri("/posts")
Expand All @@ -75,6 +77,13 @@ void willCreatePosts() {
.exists("Location")
.expectBody(UUID.class);

// Calculate the difference in tag count after creating posts
Long afterCount = tagRepository.count().block();

// Use Assertions to verify the result
assertThat(afterCount - initialCount).isEqualTo(1);

// Create the second post
createPost = new CreatePostCommand("junitTitle1", "junitContent1", List.of("junitTag"));
this.webTestClient
.post()
Expand All @@ -88,13 +97,10 @@ void willCreatePosts() {
.exists("Location")
.expectBody(UUID.class);

Mono<Long> resultMono =
tagRepository.count().zipWith(count, (value1, value2) -> value2 - value1);
// Calculate the difference in tag count after creating posts
afterCount = tagRepository.count().block();

// Use StepVerifier to assert the behavior
StepVerifier.create(resultMono)
.expectNext(0L) // Expected result after subtraction
.expectComplete()
.verify();
// Use Assertions to verify the result that no newer one is created
assertThat(afterCount - initialCount).isEqualTo(1);
}
}

0 comments on commit f9c4e38

Please sign in to comment.