Skip to content

Commit

Permalink
Simplify parametrized test
Browse files Browse the repository at this point in the history
  • Loading branch information
murdos committed Jan 20, 2024
1 parent d56eb15 commit a0577f9
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package tech.jhipster.lite.module.domain.properties;

import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.CsvSource;
import tech.jhipster.lite.UnitTest;
import tech.jhipster.lite.shared.error.domain.NumberValueTooHighException;
import tech.jhipster.lite.shared.error.domain.NumberValueTooLowException;

@UnitTest
class JHipsterServerPortTest {
Expand All @@ -24,19 +22,18 @@ void shouldGetServerPortFromPort() {
}

@ParameterizedTest
@MethodSource("validations")
void shouldValidatePortNumbers(Setup setup) {
assertThatExceptionOfType(setup.exceptionType).isThrownBy(() -> new JHipsterServerPort(setup.number));
@CsvSource(
{
"-90000,tech.jhipster.lite.shared.error.domain.NumberValueTooLowException",
"90000,tech.jhipster.lite.shared.error.domain.NumberValueTooHighException",
}
)
void shouldValidatePortNumbers(int port, Class<Exception> exceptionClass) {
assertThatExceptionOfType(exceptionClass).isThrownBy(() -> new JHipsterServerPort(port));
}

@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 a0577f9

Please sign in to comment.