Skip to content

Commit

Permalink
Add MockWebServerExtension constructor that accepts a server customiz…
Browse files Browse the repository at this point in the history
…er (#561)
  • Loading branch information
sleberknight authored Feb 8, 2025
1 parent 1e52f0d commit b841d39
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ public class MockWebServerExtension implements BeforeEachCallback, AfterEachCall
* use the builder instead of this constructor.
*/
public MockWebServerExtension() {
this(new MockWebServer(), KiwiConsumers.noOp());
this(KiwiConsumers.noOp());
}

/**
* Create a new instance that will create a new {@link MockWebServer} and
* customize it using the {@code serverCustomizer}.
*
* @param serverCustomizer allows a test to configure the server, e.g., to customize the protocols
* it supports or to serve requests via HTTPS over TLS. Must not be {@code null}.
*/
public MockWebServerExtension(Consumer<MockWebServer> serverCustomizer) {
this(new MockWebServer(), requireNotNull(serverCustomizer, "serverCustomizer must not be null"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,29 @@
class MockWebServerExtensionTest {

@Nested
class Constructors {
class NoArgsConstructor {

@Test
void shouldCreateServer() {
var extension = new MockWebServerExtension();

assertThat(extension.server()).isNotNull();
}
}

@Nested
class ConstructorWithServerCustomizer {

@Test
void shouldRequireNonNullCustomizer() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new MockWebServerExtension(null))
.withMessage("serverCustomizer must not be null");
}
}

@Nested
class AllArgsConstructor {

@Test
void shouldRequireNonNullServer() {
Expand All @@ -47,13 +69,6 @@ void shouldAllowNullServerCustomizer() {
.doesNotThrowAnyException();
}

@Test
void shouldCreateServer() {
var extension = new MockWebServerExtension();

assertThat(extension.server()).isNotNull();
}

@Test
void shouldSetSpecificServer() {
var server = new MockWebServer();
Expand Down

0 comments on commit b841d39

Please sign in to comment.