Skip to content

Commit

Permalink
Use Hamcrest assertions instead of JUnit in tests/apps/bookstore-mp -…
Browse files Browse the repository at this point in the history
… backport main (helidon-io#1749) (helidon-io#6077)
  • Loading branch information
Captain1653 authored Feb 7, 2023
1 parent 3eaed67 commit 5b668f5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
7 changes: 6 additions & 1 deletion tests/apps/bookstore/bookstore-mp/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019, 2022 Oracle and/or its affiliates.
Copyright (c) 2019, 2023 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,6 +70,11 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.tests</groupId>
<artifactId>helidon-microprofile-tests-junit5</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022 Oracle and/or its affiliates.
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,8 +30,10 @@
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize;

@HelidonTest
class BookResourceTest {
Expand All @@ -46,28 +48,28 @@ void testBooks() {
Response res = webTarget.path("/books")
.request()
.post(Entity.json(getBookAsJson()));
assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
assertThat(res.getStatus(), is(Response.Status.OK.getStatusCode()));

assertBookStoreSize(1);

res = webTarget.path("/books/123456")
.request()
.get();
assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
assertThat(res.getStatus(), is(Response.Status.OK.getStatusCode()));

assertBookStoreSize(1);

res = webTarget.path("/books/123456")
.request()
.put(Entity.json(getBookAsJson()));
assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
assertThat(res.getStatus(), is(Response.Status.OK.getStatusCode()));

assertBookStoreSize(1);

res = webTarget.path("/books/123456")
.request()
.delete();
assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
assertThat(res.getStatus(), is(Response.Status.OK.getStatusCode()));

assertBookStoreSize(0);
}
Expand All @@ -79,28 +81,28 @@ void testBooks2() {
Response res = webTarget.path("/books2")
.request()
.post(Entity.json(getBookAsJson()));
assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
assertThat(res.getStatus(), is(Response.Status.OK.getStatusCode()));

assertBookStoreSize(1);

res = webTarget.path("/books2/123456")
.request()
.get();
assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
assertThat(res.getStatus(), is(Response.Status.OK.getStatusCode()));

assertBookStoreSize(1);

res = webTarget.path("/books2/123456")
.request()
.put(Entity.json(getBookAsJson()));
assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
assertThat(res.getStatus(), is(Response.Status.OK.getStatusCode()));

assertBookStoreSize(1);

res = webTarget.path("/books2/123456")
.request()
.delete();
assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
assertThat(res.getStatus(), is(Response.Status.OK.getStatusCode()));

assertBookStoreSize(0);
}
Expand All @@ -118,6 +120,6 @@ private void assertBookStoreSize(int size) {
Book[] jsonArray = webTarget.path("/books")
.request()
.get(Book[].class);
assertEquals(size, jsonArray.length);
assertThat(jsonArray, arrayWithSize(size));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,8 @@
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

/**
* Test that the resource class {@link VetoedResource} is not part
Expand All @@ -38,6 +39,6 @@ class VetoedResourceTest {
@Test
void testVetoed() {
Response res = webTarget.path("/vetoed").request().get();
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), res.getStatus());
assertThat(res.getStatus(), is(Response.Status.NOT_FOUND.getStatusCode()));
}
}

0 comments on commit 5b668f5

Please sign in to comment.