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;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,18 +1,21 @@
|
|||||||
package com.baeldung.springjunitconfiguration;
|
package com.baeldung.springjunitconfiguration;
|
||||||
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@SpringJUnitConfig(classes = TestConfig.class, loader = AnnotationConfigContextLoader.class)
|
@SpringJUnitConfig(classes = TestConfig.class, loader = AnnotationConfigContextLoader.class)
|
||||||
public class SpringJUnitConfigurationParameterizedTest {
|
public class SpringJUnitConfigurationUnitTest {
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(strings = { "Dilbert", "Wally" })
|
@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()
|
assertThat(people.stream()
|
||||||
.map(Person::getName)
|
.map(Person::getName)
|
||||||
.filter(name::equals)).hasSize(1);
|
.filter(name::equals)).hasSize(1);
|
Loading…
x
Reference in New Issue
Block a user