The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring

This commit is contained in:
michaelin007 2023-12-21 13:37:06 +00:00
parent b689e22bcf
commit f36e38d1f1
2 changed files with 9 additions and 2 deletions

View File

@ -8,4 +8,8 @@ public class Person {
this.name = name;
}
public String getName() {
return this.name;
}
}

View File

@ -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);