18
18
19
19
package org .apache .hadoop .fs .gs ;
20
20
21
- import org .junit .Test ;
21
+ import org .junit .jupiter . api . Test ;
22
22
import static org .junit .jupiter .api .Assertions .assertNull ;
23
23
import static org .junit .jupiter .api .Assertions .assertEquals ;
24
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
24
25
import static org .junit .jupiter .api .Assertions .assertTrue ;
25
26
import static org .junit .jupiter .api .Assertions .assertFalse ;
26
27
@@ -42,29 +43,39 @@ public void testValidateBucketNameEndsWithSlash() {
42
43
assertEquals ("another-bucket" , StringPaths .validateBucketName ("another-bucket/" ));
43
44
}
44
45
45
- @ Test ( expected = IllegalArgumentException . class )
46
+ @ Test
46
47
public void testValidateBucketNameEmpty () {
47
- StringPaths .validateBucketName ("" );
48
+ assertThrows (IllegalArgumentException .class , () -> {
49
+ StringPaths .validateBucketName ("" );
50
+ });
48
51
}
49
52
50
- @ Test ( expected = IllegalArgumentException . class )
53
+ @ Test
51
54
public void testValidateBucketNameNull () {
52
- StringPaths .validateBucketName (null );
55
+ assertThrows (IllegalArgumentException .class , () -> {
56
+ StringPaths .validateBucketName (null );
57
+ });
53
58
}
54
59
55
- @ Test ( expected = IllegalArgumentException . class )
60
+ @ Test
56
61
public void testValidateBucketNameInvalidChars () {
57
- StringPaths .validateBucketName ("my bucket" ); // Space
62
+ assertThrows (IllegalArgumentException .class , () -> {
63
+ StringPaths .validateBucketName ("my bucket" ); // Space
64
+ });
58
65
}
59
66
60
- @ Test ( expected = IllegalArgumentException . class )
67
+ @ Test
61
68
public void testValidateBucketNameInvalidChars2 () {
62
- StringPaths .validateBucketName ("my@bucket" ); // @ symbol
69
+ assertThrows (IllegalArgumentException .class , () -> {
70
+ StringPaths .validateBucketName ("my@bucket" ); // @ symbol
71
+ });
63
72
}
64
73
65
- @ Test ( expected = IllegalArgumentException . class )
74
+ @ Test
66
75
public void testValidateBucketNameUpperCase () {
67
- StringPaths .validateBucketName ("MyBucket" ); // Uppercase
76
+ assertThrows (IllegalArgumentException .class , () -> {
77
+ StringPaths .validateBucketName ("MyBucket" ); // Uppercase
78
+ });
68
79
}
69
80
70
81
@ Test
@@ -84,14 +95,18 @@ public void testValidateObjectNameLeadingSlash() {
84
95
assertEquals ("object" , StringPaths .validateObjectName ("/object" , false ));
85
96
}
86
97
87
- @ Test ( expected = IllegalArgumentException . class )
98
+ @ Test
88
99
public void testValidateObjectNameEmptyNotAllowed () {
89
- StringPaths .validateObjectName ("" , false );
100
+ assertThrows (IllegalArgumentException .class , () -> {
101
+ StringPaths .validateObjectName ("" , false );
102
+ });
90
103
}
91
104
92
- @ Test ( expected = IllegalArgumentException . class )
105
+ @ Test
93
106
public void testValidateObjectNameNullNotAllowed () {
94
- StringPaths .validateObjectName (null , false );
107
+ assertThrows (IllegalArgumentException .class , () -> {
108
+ StringPaths .validateObjectName (null , false );
109
+ });
95
110
}
96
111
97
112
@ Test
@@ -101,19 +116,25 @@ public void testValidateObjectNameEmptyAllowed() {
101
116
assertEquals ("" , StringPaths .validateObjectName ("/" , true )); // Single slash becomes empty
102
117
}
103
118
104
- @ Test ( expected = IllegalArgumentException . class )
119
+ @ Test
105
120
public void testValidateObjectNameConsecutiveSlashes () {
106
- StringPaths .validateObjectName ("path//to/object" , false );
121
+ assertThrows (IllegalArgumentException .class , () -> {
122
+ StringPaths .validateObjectName ("path//to/object" , false );
123
+ });
107
124
}
108
125
109
- @ Test ( expected = IllegalArgumentException . class )
126
+ @ Test
110
127
public void testValidateObjectNameConsecutiveSlashesAtStart () {
111
- StringPaths .validateObjectName ("//path/to/object" , false );
128
+ assertThrows (IllegalArgumentException .class , () -> {
129
+ StringPaths .validateObjectName ("//path/to/object" , false );
130
+ });
112
131
}
113
132
114
- @ Test ( expected = IllegalArgumentException . class )
133
+ @ Test
115
134
public void testValidateObjectNameConsecutiveSlashesAtEnd () {
116
- StringPaths .validateObjectName ("path/to/object//" , false );
135
+ assertThrows (IllegalArgumentException .class , () -> {
136
+ StringPaths .validateObjectName ("path/to/object//" , false );
137
+ });
117
138
}
118
139
119
140
@ Test
@@ -124,9 +145,11 @@ public void testFromComponentsValid() {
124
145
assertEquals ("gs://my-bucket/" , StringPaths .fromComponents ("my-bucket" , "" ));
125
146
}
126
147
127
- @ Test ( expected = IllegalArgumentException . class )
148
+ @ Test
128
149
public void testFromComponentsNullBucketNonNullObject () {
129
- StringPaths .fromComponents (null , "path/to/object" );
150
+ assertThrows (IllegalArgumentException .class , () -> {
151
+ StringPaths .fromComponents (null , "path/to/object" );
152
+ });
130
153
}
131
154
132
155
@ Test
@@ -163,4 +186,4 @@ public void testToDirectoryPath() {
163
186
assertEquals ("" , StringPaths .toDirectoryPath ("" ));
164
187
assertNull (StringPaths .toDirectoryPath (null ));
165
188
}
166
- }
189
+ }
0 commit comments