The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring
This commit is contained in:
parent
b689e22bcf
commit
f36e38d1f1
|
@ -8,4 +8,8 @@ public class Person {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +1,21 @@
|
|||
package com.baeldung.springjunitconfiguration;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringJUnitConfig(classes = TestConfig.class, loader = AnnotationConfigContextLoader.class)
|
||||
public class SpringJUnitConfigurationParameterizedTest {
|
||||
public class SpringJUnitConfigurationUnitTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = { "Dilbert", "Wally" })
|
||||
void people(String name, @Autowired List<Person> people) {
|
||||
void givenPeopleList_whenSetPeopleWithName_thenListContainsOnePerson(String name, @Autowired List<Person> people) {
|
||||
assertThat(people.stream()
|
||||
.map(Person::getName)
|
||||
.filter(name::equals)).hasSize(1);
|
Loading…
Reference in New Issue