|
| 1 | +package io.securecodebox.persistence.defectdojo.http; |
| 2 | + |
| 3 | +import nl.jqno.equalsverifier.EqualsVerifier; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import org.junit.jupiter.params.ParameterizedTest; |
| 6 | +import org.junit.jupiter.params.provider.Arguments; |
| 7 | +import org.junit.jupiter.params.provider.MethodSource; |
| 8 | + |
| 9 | +import java.util.stream.Stream; |
| 10 | + |
| 11 | +import static org.junit.jupiter.api.Assertions.*; |
| 12 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 13 | +import static org.hamcrest.Matchers.*; |
| 14 | + |
| 15 | +/** |
| 16 | + * Tests for {@link ProxyConfig} |
| 17 | + */ |
| 18 | +class ProxyConfigTest { |
| 19 | + @Test |
| 20 | + void equalsAndHashCode() { |
| 21 | + EqualsVerifier.forClass(ProxyConfig.class).verify(); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + void builderCreatesDefault() { |
| 26 | + final var sut = ProxyConfig.builder().build(); |
| 27 | + |
| 28 | + assertAll( |
| 29 | + () -> assertThat(sut.getUser(), is(emptyString())), |
| 30 | + () -> assertThat(sut.getPassword(), is(emptyString())), |
| 31 | + () -> assertThat(sut.getHost(), is(emptyString())), |
| 32 | + () -> assertThat(sut.getPort(), is(0)) |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + void buildersDefaultIsEqualToNullObject() { |
| 38 | + assertThat(ProxyConfig.builder().build(), is(ProxyConfig.NULL)); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void isComplete_falseForNullObject() { |
| 43 | + assertThat(ProxyConfig.NULL.isComplete(), is(false)); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + void isComplete_falseForDefault() { |
| 48 | + assertThat(ProxyConfig.builder().build().isComplete(), is(false)); |
| 49 | + } |
| 50 | + |
| 51 | + @ParameterizedTest |
| 52 | + @MethodSource("incompleteConfigs") |
| 53 | + void isComplete_falseUnlessAllFieldsAreSet(final ProxyConfig sut) { |
| 54 | + |
| 55 | + } |
| 56 | + |
| 57 | + private static Stream<Arguments> incompleteConfigs() { |
| 58 | + return Stream.of( |
| 59 | + // Only one is set: |
| 60 | + Arguments.of(ProxyConfig.builder().user("user").build()), |
| 61 | + Arguments.of(ProxyConfig.builder().password("pw").build()), |
| 62 | + Arguments.of(ProxyConfig.builder().host("host").build()), |
| 63 | + Arguments.of(ProxyConfig.builder().port(42).build()), |
| 64 | + // All but one is set: |
| 65 | + Arguments.of(ProxyConfig.builder().password("pwd").host("host").port(42).build()), |
| 66 | + Arguments.of(ProxyConfig.builder().user("user").host("host").port(42).build()), |
| 67 | + Arguments.of(ProxyConfig.builder().user("user").password("pwd").port(42).build()), |
| 68 | + Arguments.of(ProxyConfig.builder().user("user").password("pwd").host("host").build()) |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + void isComplete_trueIfAllFieldsAreNonDefaults() { |
| 74 | + final var sut = ProxyConfig.builder() |
| 75 | + .user("user") |
| 76 | + .password("pw") |
| 77 | + .host("host") |
| 78 | + .port(42) |
| 79 | + .build(); |
| 80 | + |
| 81 | + assertThat(sut.isComplete(), is(true)); |
| 82 | + } |
| 83 | +} |
0 commit comments