-
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.
fix: give helpful error message when using same name in mocks (refs #62)
- Loading branch information
1 parent
fdb382c
commit 5725b1c
Showing
2 changed files
with
101 additions
and
47 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
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
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"); | ||
} | ||
|
||
} |