88import jakarta .validation .ValidatorFactory ;
99import org .junit .jupiter .api .BeforeEach ;
1010import org .junit .jupiter .api .DisplayName ;
11- import org .junit .jupiter .api .Test ;
11+ import org .junit .jupiter .params .ParameterizedTest ;
12+ import org .junit .jupiter .params .provider .CsvSource ;
1213
1314class AppConfigurationTest {
1415
@@ -21,62 +22,25 @@ void setUp() {
2122 }
2223
2324 @ DisplayName ("Should be valid when URL is a correct https link ending in com" )
24- @ Test
25- void shouldBeValidWhenUrlIsCorrectAndEndingInCom () {
26- var config = new AppConfiguration ("https://example.com" );
25+ @ 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 ) {
37+ var config = new AppConfiguration (input );
2738 var violations = validator .validate (config );
2839
29- assertTrue (violations .isEmpty (), "Expected no violations for valid URL" );
30- }
31-
32- @ DisplayName ("Should be valid when URL is a correct https link ending in ch" )
33- @ Test
34- void shouldBeValidWhenUrlIsCorrectAndEndingInCh () {
35- var config = new AppConfiguration ("https://example.ch" );
36- var violations = validator .validate (config );
37-
38- assertTrue (violations .isEmpty (), "Expected no violations for valid URL" );
39- }
40-
41- @ DisplayName ("Should have violations when URL is null" )
42- @ Test
43- void shouldHaveViolationsWhenUrlIsNull () {
44- var config = new AppConfiguration (null );
45-
46- var violations = validator .validate (config );
47-
48- assertFalse (violations .isEmpty (), "Expected violations for invalid URL" );
49- }
50-
51- @ DisplayName ("Should have violations when URL is blank" )
52- @ Test
53- void shouldHaveViolationsWhenUrlIsBlank () {
54- var config = new AppConfiguration ("" );
55- var violations = validator .validate (config );
56- assertFalse (violations .isEmpty (), "Expected violations for blank URL" );
57- }
58-
59- @ DisplayName ("Should have violations when URL does not start with https://" )
60- @ Test
61- void shouldHaveViolationsWhenUrlDoesNotStartWithHttps () {
62- var config = new AppConfiguration ("http://example.com" );
63- var violations = validator .validate (config );
64- assertFalse (violations .isEmpty (), "Expected violations for URL not starting with https://" );
65- }
66-
67- @ DisplayName ("Should have violations when URL is shorter than 12 chars" )
68- @ Test
69- void shouldHaveViolationsWhenUrlIsShorterThan12Chars () {
70- var config = new AppConfiguration ("https://.ch" );
71- var violations = validator .validate (config );
72- assertFalse (violations .isEmpty (), "Expected violations for URL shorter than 12 chars" );
73- }
74-
75- @ DisplayName ("Should have violations when URL does not contain .ch or .com" )
76- @ Test
77- void shouldHaveViolationsWhenUrlDoesNotContainChOrCom () {
78- var config = new AppConfiguration ("https://example.de" );
79- var violations = validator .validate (config );
80- assertFalse (violations .isEmpty (), "Expected violations for URL not containing ch or com" );
40+ if (expectedValid ) {
41+ assertTrue (violations .isEmpty (), "Expected no violations for: " + input );
42+ } else {
43+ assertFalse (violations .isEmpty (), "Expected violations for: " + input );
44+ }
8145 }
8246}
0 commit comments