99import org .junit .jupiter .api .BeforeEach ;
1010import org .junit .jupiter .api .DisplayName ;
1111import org .junit .jupiter .params .ParameterizedTest ;
12- import org .junit .jupiter .params .provider .CsvSource ;
12+ import org .junit .jupiter .params .provider .NullSource ;
13+ import org .junit .jupiter .params .provider .ValueSource ;
1314
1415class AppConfigurationTest {
1516
@@ -21,26 +22,35 @@ void setUp() {
2122 validator = factory .getValidator ();
2223 }
2324
24- @ DisplayName ("Should return expected result " )
25+ @ DisplayName ("Should return violations when an invalid url is provided " )
2526 @ ParameterizedTest
26- @ CsvSource ("""
27- https://example.com, true,
28- https://example.ch, true,
29- null, false,
30- , false,
31- http://example.com, false,
32- https://.ch, false,
33- https://example.de, false,
34- https://e x am.ch, false
35- """ )
36- void shouldReturnExpected (String input , boolean expectedValid ) {
27+ @ ValueSource (strings = { "" , "http://example.com" })
28+ void shouldCreateViolations (String input ) {
3729 var config = new AppConfiguration (input );
3830 var violations = validator .validate (config );
3931
40- if (expectedValid ) {
41- assertTrue (violations .isEmpty (), "Expected no violations for: " + input );
42- } else {
43- assertFalse (violations .isEmpty (), "Expected violations for: " + input );
44- }
32+ assertFalse (violations .isEmpty (), "Expected violations for: " + input );
4533 }
34+
35+ @ DisplayName ("Should return violations when null is provided" )
36+ @ ParameterizedTest
37+ @ NullSource
38+ void shouldCreateViolationsWhenNullIsProvided (String input ) {
39+ var config = new AppConfiguration (input );
40+ var violations = validator .validate (config );
41+
42+ assertFalse (violations .isEmpty (), "Expected violations for: " + input );
43+ }
44+
45+ @ DisplayName ("Should not return any violations when a valid url is provided" )
46+ @ ParameterizedTest
47+ @ ValueSource (strings = { "https://example.com" , "https://example.ch" , "mailto:test@example.ch" , "tel:+12345678910" ,
48+ "sms:+12345678910" })
49+ void shouldNotCreateViolations (String input ) {
50+ var config = new AppConfiguration (input );
51+ var violations = validator .validate (config );
52+
53+ assertTrue (violations .isEmpty (), "Expected no violations for: " + input );
54+ }
55+
4656}
0 commit comments