Skip to content

Commit

Permalink
Use assertj assertions, and make it a bit more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
gzsombor committed Jan 20, 2024
1 parent 902f466 commit d56eb15
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package tech.jhipster.lite.module.domain.properties;

import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import tech.jhipster.lite.UnitTest;
import tech.jhipster.lite.shared.error.domain.NumberValueTooHighException;
import tech.jhipster.lite.shared.error.domain.NumberValueTooLowException;
Expand All @@ -21,14 +23,20 @@ void shouldGetServerPortFromPort() {
assertThat(new JHipsterServerPort(9000).get()).isEqualTo(9000);
}

@Test
void shouldValidatePortNumbers() {
assertThrows(NumberValueTooHighException.class, () -> new JHipsterServerPort(90000));
assertThrows(NumberValueTooLowException.class, () -> new JHipsterServerPort(-90000));
@ParameterizedTest
@MethodSource("validations")
void shouldValidatePortNumbers(Setup setup) {
assertThatExceptionOfType(setup.exceptionType).isThrownBy(() -> new JHipsterServerPort(setup.number));
}

@Test
void testToStringShowsPortNumber() {
assertThat(new JHipsterServerPort(9000)).hasToString("9000");
}

static List<JHipsterServerPortTest.Setup> validations() {
return List.of(new Setup(90000, NumberValueTooHighException.class), new Setup(-90000, NumberValueTooLowException.class));
}

record Setup(int number, Class<? extends Throwable> exceptionType) {}
}

0 comments on commit d56eb15

Please sign in to comment.