1
+ /*
2
+ * Copyright 2023 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ package br .org .soujava .pomeditor .api ;
19
+
20
+ import br .org .soujava .pomeditor .InvalidGroupIdArtifactIdArgs ;
21
+ import org .junit .jupiter .api .Assertions ;
22
+ import org .junit .jupiter .api .DisplayName ;
23
+ import org .junit .jupiter .params .ParameterizedTest ;
24
+ import org .junit .jupiter .params .provider .ArgumentsSource ;
25
+
26
+ import java .util .Arrays ;
27
+ import java .util .Objects ;
28
+ import java .util .stream .Collectors ;
29
+
30
+ class DependencyTest {
31
+
32
+ @ DisplayName ("should return error when" )
33
+ @ ParameterizedTest (name = "groupId={0}, artifactId={1}" )
34
+ @ ArgumentsSource (InvalidGroupIdArtifactIdArgs .class )
35
+ void shouldReturnErrors (final String groupId , final String artifactId ) {
36
+ Assertions .assertThrows (IllegalArgumentException .class , () -> {
37
+ var gav = Arrays .stream (new String []{groupId , artifactId })
38
+ .filter (Objects ::nonNull )
39
+ .collect (Collectors .joining (":" ));
40
+ Dependency .ofGav (gav ).build ();
41
+ });
42
+
43
+ Assertions .assertThrows (IllegalArgumentException .class , () -> {
44
+ Dependency .builder ()
45
+ .withGroupId (groupId )
46
+ .withArtifactId (artifactId ).build ();
47
+ });
48
+ }
49
+
50
+
51
+ @ DisplayName ("should return error when" )
52
+ @ ParameterizedTest (name = "groupId={0}, artifactId={1}" )
53
+ @ ArgumentsSource (InvalidGroupIdArtifactIdArgs .class )
54
+ void shouldReturnErrorsForInvalidRequiredParameters (final String groupId ,
55
+ final String artifactId ) {
56
+ Assertions .assertThrows (IllegalArgumentException .class , () -> {
57
+ var gav = Arrays .stream (new String []{groupId , artifactId })
58
+ .filter (Objects ::nonNull )
59
+ .collect (Collectors .joining (":" ));
60
+ Dependency .ofGav (gav ).build ();
61
+ });
62
+
63
+ Assertions .assertThrows (IllegalArgumentException .class , () -> {
64
+ Dependency .builder ()
65
+ .withGroupId (groupId )
66
+ .withArtifactId (artifactId ).build ();
67
+ });
68
+ }
69
+
70
+ }
0 commit comments