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
class BookmarkResolver implements ParameterResolver { | |
@Override | |
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { | |
// Le type d'arguments concernés par le resolver | |
return parameterContext.getParameter().getType() == Bookmark.class; | |
} | |
@Override | |
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { |
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
@IntegrationTest | |
class MyIntegrationTests { | |
// ... | |
} | |
@ExtendWith({ | |
MyIntegrationTestExtension.class, | |
SpringExtension.class // Implémenté par Spring | |
}) | |
@Retention(RetentionPolicy.RUNTIME) |
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
import org.junit.jupiter.api.Test; | |
import org.junit.jupiter.api.extension.*; | |
@ExtendWith(MyIntegrationTestExtension.class) | |
class MyIntegrationTests { | |
@Test | |
void test() { | |
// ... | |
} |
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
junit.jupiter.displayname.generator.default = \ | |
org.junit.jupiter.api.DisplayNameGenerator$ReplaceUnderscores |
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
@CsvSource({ | |
"http://www.junit.org, JUnit, Testing", | |
"https://www.oracle.com/fr/java/, Java, Language" | |
}) | |
@DisplayName("Should create the bookmark") | |
@ParameterizedTest(name = "for the url {0} named {1} & tagged {2}") | |
void should_create_the_bookmark(String url, String name, String tag) {} |
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
import org.junit.jupiter.api.DisplayName; | |
@DisplayName("BookmarkRepository") | |
class BookmarkRepositoryTest { | |
@Test | |
@DisplayName("Should save a bookmark") | |
void should_save_bookmark(Bookmark bookmark) {} | |
@Nested |
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
class BookmarkTest implements EqualityTest<Bookmark> { | |
@Override | |
public Bookmark createValue() { | |
return Bookmark.create("http://www.test.com", "name"); | |
} | |
@Override | |
public Bookmark createOtherValue() { | |
return Bookmark.create("http://www.test2.com", "other name"); |
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
public interface EqualityTest<T> { | |
T createValue(); | |
T createOtherValue(); | |
@Test | |
default void should_be_equal() { | |
assertThat(createValue()).isEqualTo(createValue()); | |
assertThat(createValue().hashCode()).isEqualTo(createValue().hashCode()); | |
} |
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
@ParameterizedTest | |
@MethodSource("somePeople") | |
void a_test_with_method_source(String name, int age, Month birthMonth) { | |
// ... | |
} | |
private static Stream<Arguments> somePeople() { | |
return Stream.of( | |
Arguments.of("Alice", 25, JUNE), | |
Arguments.of("Bob", 32, AUGUST) |
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
@ParameterizedTest | |
@ValueSource(strings = {"JANUARY", "FEBRUARY", "MARCH"}) | |
void a_test_with_explicit_conversion( | |
@ConvertWith(MonthToNumberConverter.class) int month) { | |
assertTrue(month <= 3); | |
} | |
class MonthToNumberConverter extends SimpleArgumentConverter { | |
@Override |
NewerOlder