fix most unit tests and improve usage of assumeThat

This commit is contained in:
Michael Hoennig 2024-01-04 08:43:52 +01:00
parent 378e1ec584
commit 73f147c557
14 changed files with 26 additions and 57 deletions

View File

@ -83,7 +83,7 @@ class HsOfficeBankAccountControllerRestTest {
enum InvalidBicTestCase {
TOO_SHORT("BEVODEB", "Bic length must be 8 or 11"),
TOO_LONG("BEVODEBBX", "Bic length must be 8 or 11"),
INVALID_CHARACTER("BEV-ODEB", "Bank code must contain only letters.");
INVALID_CHARACTER("BEV-ODEB", "Bank code must contain only alphanumeric.");
private final String givenBic;
private final String expectedErrorMessage;

View File

@ -28,7 +28,6 @@ import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantD
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.roleNamesOf;
import static net.hostsharing.test.JpaAttempt.attempt;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
@DataJpaTest
@Import( { Context.class, JpaAttempt.class })
@ -237,10 +236,6 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTest {
final var initialRoleNames = roleNamesOf(rawRoleRepo.findAll());
final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll());
final var givenContact = givenSomeTemporaryContact("selfregistered-user-drew@hostsharing.org");
assumeThat(rawRoleRepo.findAll().size()).as("unexpected number of roles created")
.isEqualTo(initialRoleNames.size() + 3);
assumeThat(rawGrantRepo.findAll().size()).as("unexpected number of grants created")
.isEqualTo(initialGrantNames.size() + 7);
// when
final var result = jpaAttempt.transacted(() -> {

View File

@ -26,7 +26,6 @@ import java.util.UUID;
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
import static net.hostsharing.test.JsonMatcher.lenientlyEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.hamcrest.Matchers.*;
@SpringBootTest(
@ -481,7 +480,7 @@ class HsOfficeDebitorControllerAcceptanceTest {
void contactAdminUser_canNotDeleteRelatedDebitor() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = givenSomeTemporaryDebitor();
assumeThat(givenDebitor.getBillingContact().getLabel()).isEqualTo("forth contact");
assertThat(givenDebitor.getBillingContact().getLabel()).isEqualTo("forth contact");
RestAssured // @formatter:off
.given()
@ -501,7 +500,7 @@ class HsOfficeDebitorControllerAcceptanceTest {
void normalUser_canNotDeleteUnrelatedDebitor() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = givenSomeTemporaryDebitor();
assumeThat(givenDebitor.getBillingContact().getLabel()).isEqualTo("forth contact");
assertThat(givenDebitor.getBillingContact().getLabel()).isEqualTo("forth contact");
RestAssured // @formatter:off
.given()

View File

@ -32,7 +32,6 @@ import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantD
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.roleNamesOf;
import static net.hostsharing.test.JpaAttempt.attempt;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
@DataJpaTest
@Import( { Context.class, JpaAttempt.class })
@ -327,7 +326,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest {
// when
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_debitor#10003ThirdOHG-thirdcontact.admin");
assumeThat(membershipRepo.findByUuid(givenMembership.getUuid())).isPresent();
assertThat(membershipRepo.findByUuid(givenMembership.getUuid())).isPresent();
membershipRepo.deleteByUuid(givenMembership.getUuid());
});

View File

@ -24,7 +24,6 @@ import java.util.UUID;
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
import static net.hostsharing.test.JsonMatcher.lenientlyEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
@ -408,7 +407,7 @@ class HsOfficePartnerControllerAcceptanceTest {
void contactAdminUser_canNotDeleteRelatedPartner() {
context.define("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler();
assumeThat(givenPartner.getContact().getLabel()).isEqualTo("forth contact");
assertThat(givenPartner.getContact().getLabel()).isEqualTo("forth contact");
RestAssured // @formatter:off
.given()
@ -428,7 +427,7 @@ class HsOfficePartnerControllerAcceptanceTest {
void normalUser_canNotDeleteUnrelatedPartner() {
context.define("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler();
assumeThat(givenPartner.getContact().getLabel()).isEqualTo("forth contact");
assertThat(givenPartner.getContact().getLabel()).isEqualTo("forth contact");
RestAssured // @formatter:off
.given()

View File

@ -29,7 +29,6 @@ import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantD
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.roleNamesOf;
import static net.hostsharing.test.JpaAttempt.attempt;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
@DataJpaTest
@Import( { Context.class, JpaAttempt.class })
@ -330,7 +329,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
// when
final var result = jpaAttempt.transacted(() -> {
context("person-ErbenBesslerMelBessler@example.com");
assumeThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent();
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent();
partnerRepo.deleteByUuid(givenPartner.getUuid());
});
@ -352,10 +351,6 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
final var initialRoleNames = Array.from(roleNamesOf(rawRoleRepo.findAll()));
final var initialGrantNames = Array.from(grantDisplaysOf(rawGrantRepo.findAll()));
final var givenPartner = givenSomeTemporaryPartnerBessler("twelfth");
assumeThat(rawRoleRepo.findAll().size()).as("unexpected number of roles created")
.isEqualTo(initialRoleNames.length + 3);
assumeThat(rawGrantRepo.findAll().size()).as("unexpected number of grants created")
.isEqualTo(initialGrantNames.length + 10);
// when
final var result = jpaAttempt.transacted(() -> {

View File

@ -27,7 +27,6 @@ import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantD
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.roleNamesOf;
import static net.hostsharing.test.JpaAttempt.attempt;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
@DataJpaTest
@Import( { Context.class, JpaAttempt.class })
@ -244,10 +243,6 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTest {
final var initialRoleNames = roleNamesOf(rawRoleRepo.findAll());
final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll());
final var givenPerson = givenSomeTemporaryPerson("selfregistered-user-drew@hostsharing.org");
assumeThat(rawRoleRepo.findAll().size()).as("unexpected number of roles created")
.isEqualTo(initialRoleNames.size() + 3);
assumeThat(rawGrantRepo.findAll().size()).as("unexpected number of grants created")
.isEqualTo(initialGrantNames.size() + 7);
// when
final var result = jpaAttempt.transacted(() -> {

View File

@ -25,7 +25,6 @@ import java.util.UUID;
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
import static net.hostsharing.test.JsonMatcher.lenientlyEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;

View File

@ -31,7 +31,6 @@ import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantD
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.roleNamesOf;
import static net.hostsharing.test.JpaAttempt.attempt;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
@DataJpaTest
@Import({ Context.class, JpaAttempt.class })
@ -346,7 +345,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTest {
// when
final var result = jpaAttempt.transacted(() -> {
context("bankaccount-admin@ThirdOHG.example.com");
assumeThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent();
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent();
sepaMandateRepo.deleteByUuid(givenSepaMandate.getUuid());
});

View File

@ -26,7 +26,6 @@ import java.util.List;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.*;
@ -343,7 +342,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
}
private void assumeCreated(final ValidatableResponse response) {
assumeThat(response.extract().response().statusCode()).isEqualTo(201);
assertThat(response.extract().response().statusCode()).isEqualTo(201);
}
class Subject {
@ -479,7 +478,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
}
private void assumeGrantExists(final Subject grantingSubject, final String expectedGrant) {
assumeThat(findAllGrantsOf(grantingSubject))
assertThat(findAllGrantsOf(grantingSubject))
.extracting(RbacGrantEntity::toDisplay)
.contains(expectedGrant);
}

View File

@ -25,7 +25,6 @@ import java.util.UUID;
import static net.hostsharing.test.JpaAttempt.attempt;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
@DataJpaTest
@Import( { Context.class, JpaAttempt.class })
@ -186,9 +185,8 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
// when
context("customer-admin@xxx.example.com", "test_customer#xxx.admin");
final var revokeAttempt = attempt(em, () -> {
rbacGrantRepository.deleteByRbacGrantId(grant.getRbacGrantId());
});
final var revokeAttempt = attempt(em, () ->
rbacGrantRepository.deleteByRbacGrantId(grant.getRbacGrantId()));
// then
context("customer-admin@xxx.example.com", "test_customer#xxx.admin");
@ -208,9 +206,8 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
// when
context("pac-admin-xxx00@xxx.example.com", "test_package#xxx00.admin");
final var revokeAttempt = attempt(em, () -> {
rbacGrantRepository.deleteByRbacGrantId(grant.getRbacGrantId());
});
final var revokeAttempt = attempt(em, () ->
rbacGrantRepository.deleteByRbacGrantId(grant.getRbacGrantId()));
// then
assertThat(revokeAttempt.caughtExceptionsRootCause()).isNull();
@ -230,9 +227,8 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
// when
context("pac-admin-xxx00@xxx.example.com", "test_package#xxx00.admin");
final var revokeAttempt = attempt(em, () -> {
rbacGrantRepository.deleteByRbacGrantId(grant.getRbacGrantId());
});
final var revokeAttempt = attempt(em, () ->
rbacGrantRepository.deleteByRbacGrantId(grant.getRbacGrantId()));
// then
revokeAttempt.assertExceptionWithRootCauseMessage(
@ -255,8 +251,8 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
rbacGrantRepository.save(grant)
);
assumeThat(grantAttempt.caughtException()).isNull();
assumeThat(rawRbacGrantRepository.findAll())
assertThat(grantAttempt.caughtException()).isNull();
assertThat(rawRbacGrantRepository.findAll())
.extracting(RawRbacGrantEntity::toDisplay)
.contains("{ grant role %s to user %s by role %s and assume }".formatted(
with.grantedRole, with.granteeUserName, with.assumedRole

View File

@ -61,11 +61,6 @@ class RbacUserRepositoryIntegrationTest extends ContextBasedTest {
assertThat(result.returnedValue()).isNotNull()
.extracting(RbacUserEntity::getUuid).isEqualTo(givenUuid);
assertThat(rbacUserRepository.findByName(result.returnedValue().getName())).isNotNull();
// jpaAttempt.transacted(() -> {
// context(givenUser.getName());
// assertThat(em.find(RbacUserEntity.class, givenUser.getUuid()))
// .isNotNull().extracting(RbacUserEntity::getName).isEqualTo(givenUser.getName());
// }).assertSuccessful();
}
}
@ -87,9 +82,6 @@ class RbacUserRepositoryIntegrationTest extends ContextBasedTest {
// then the user is deleted
result.assertSuccessful();
assertThat(rbacUserRepository.findByName(givenUser.getName())).isNull();
// jpaAttempt.transacted(() -> {
// assertThat(rbacUserRepository.findByName(givenUser.getName())).isNull();
// }).assertSuccessful();
}
}

View File

@ -16,7 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
import static java.lang.String.format;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
@ -85,7 +85,8 @@ class TestPackageControllerAcceptanceTest {
@Test
void withDescriptionUpdatesDescription() {
assumeThat(getDescriptionOfPackage("xxx00"))
assertThat(getDescriptionOfPackage("xxx00"))
.as("precondition failed")
.isEqualTo("Here you can add your own description of package xxx00.");
final var randomDescription = RandomStringUtils.randomAlphanumeric(80);
@ -117,7 +118,8 @@ class TestPackageControllerAcceptanceTest {
@Test
void withNullDescriptionUpdatesDescriptionToNull() {
assumeThat(getDescriptionOfPackage("xxx01"))
assertThat(getDescriptionOfPackage("xxx01"))
.as("precondition failed")
.isEqualTo("Here you can add your own description of package xxx01.");
// @formatter:off
@ -146,7 +148,8 @@ class TestPackageControllerAcceptanceTest {
@Test
void withoutDescriptionDoesNothing() {
assumeThat(getDescriptionOfPackage("xxx02"))
assertThat(getDescriptionOfPackage("xxx02"))
.as("precondition failed")
.isEqualTo("Here you can add your own description of package xxx02.");
// @formatter:off

View File

@ -12,7 +12,6 @@ import java.util.Optional;
import java.util.function.Supplier;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
/**
* Wraps the 'when' part of a DataJpaTest to improve readability of tests.
@ -138,7 +137,7 @@ public class JpaAttempt {
}
public JpaResult<T> assumeSuccessful() {
assumeThat(exception).as(firstRootCauseMessageLineOf(exception)).isNull();
assertThat(exception).as(firstRootCauseMessageLineOf(exception)).isNull();
return this;
}