package org.synyx.urlaubsverwaltung.calendar;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Set;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;

class CalendarPropertiesTest {

    private Validator validator;

    @BeforeEach
    void setUp() {
        validator = Validation.buildDefaultValidatorFactory().getValidator();
    }

    @Test
    void organizerIsAnEmail() {
        final CalendarProperties calendarProperties = new CalendarProperties();
        calendarProperties.setOrganizer("email@example.org");
        final Set<ConstraintViolation<CalendarProperties>> violations = validator.validate(calendarProperties);

        assertThat(violations.size()).isZero();
    }

    static Stream<String> organizerStrings() {
        return Stream.of("", "NotAnEmail", null);
    }

    @ParameterizedTest
    @MethodSource("organizerStrings")
    void organizerIsWrong(String input) {
        final CalendarProperties calendarProperties = new CalendarProperties();
        calendarProperties.setOrganizer(input);
        final Set<ConstraintViolation<CalendarProperties>> violations = validator.validate(calendarProperties);

        assertThat(violations.size()).isOne();
    }
}

@@ -171,63 +171,8 @@
 st;%0A
-import org.junit.jupiter.params.provider.MethodSource;%0A
 impo
@@ -416,40 +416,8 @@
 Set;
-%0Aimport java.util.stream.Stream;
 %0A%0Aim
@@ -1019,168 +1019,94 @@
     
-static Stream%3CString%3E organizerStrings() %7B%0A        return Stream.of(%22%22, %22NotAnEmail%22, null);%0A    %7D%0A%0A    @ParameterizedTest%0A    @MethodSource(%22organizerStrings%22)
+@ParameterizedTest%0A    @ValueSource(strings = %7B%22%22, %22 %22, %22NotAnEmail%22%7D)%0A    @NullSource
 %0A   

Improve parameterized test with sources