-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from wiremock/feature/issue-62-validate-name
fix: give helpful error message when using same name in mocks (refs #62)
- Loading branch information
Showing
2 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/org/wiremock/spring/test/ConfigurationValidationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.wiremock.spring.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.wiremock.spring.ConfigureWireMock; | ||
import org.wiremock.spring.EnableWireMock; | ||
import org.wiremock.spring.internal.WireMockContextCustomizerFactory; | ||
|
||
class ConfigurationValidationTest { | ||
|
||
@EnableWireMock({@ConfigureWireMock, @ConfigureWireMock}) | ||
private static class EnableWireMockSameDefaultName {} | ||
|
||
@EnableWireMock({@ConfigureWireMock(name = "w1"), @ConfigureWireMock(name = "w1")}) | ||
private static class EnableWireMockSameGivenName {} | ||
|
||
@Test | ||
void testDuplicateNames_default() { | ||
final IllegalStateException thrown = | ||
assertThrows( | ||
IllegalStateException.class, | ||
() -> | ||
new WireMockContextCustomizerFactory() | ||
.createContextCustomizer(EnableWireMockSameDefaultName.class, null)); | ||
assertThat(thrown.getMessage()) | ||
.isEqualTo("Names of mocks must be unique, found duplicates of: wiremock"); | ||
} | ||
|
||
@Test | ||
void testDuplicateNames_given() { | ||
final IllegalStateException thrown = | ||
assertThrows( | ||
IllegalStateException.class, | ||
() -> | ||
new WireMockContextCustomizerFactory() | ||
.createContextCustomizer(EnableWireMockSameGivenName.class, null)); | ||
assertThat(thrown.getMessage()) | ||
.isEqualTo("Names of mocks must be unique, found duplicates of: w1"); | ||
} | ||
} |