12
12
*/
13
13
package io .kubernetes .client .util ;
14
14
15
- import static org .junit .Assert .*;
15
+ import static java .nio .charset .StandardCharsets .UTF_8 ;
16
+ import static org .hamcrest .CoreMatchers .equalTo ;
17
+ import static org .junit .Assert .assertEquals ;
18
+ import static org .junit .Assert .assertFalse ;
19
+ import static org .junit .Assert .assertNull ;
20
+ import static org .junit .Assert .assertThat ;
21
+ import static org .junit .Assert .assertTrue ;
16
22
17
23
import com .google .common .io .Resources ;
18
24
import io .kubernetes .client .models .AppsV1beta1Deployment ;
26
32
import java .io .StringReader ;
27
33
import java .io .StringWriter ;
28
34
import java .lang .reflect .Method ;
29
- import java .nio .charset .StandardCharsets ;
30
- import java .nio .file .Files ;
31
- import java .nio .file .Paths ;
35
+ import java .net .URL ;
32
36
import java .util .List ;
33
37
import org .junit .Test ;
34
38
35
39
public class YamlTest {
36
- private static final String TEST_YAML_FILE_PATH = Resources .getResource ("test.yaml" ).getPath ();
40
+
41
+ private static final URL TEST_YAML_FILE = Resources .getResource ("test.yaml" );
42
+ private static final String TEST_YAML_FILE_PATH = TEST_YAML_FILE .getPath ();
43
+
44
+ private static final URL EXPECTED_YAML_FILE = Resources .getResource ("expected.yaml" );
45
+
37
46
private static final String [] kinds =
38
47
new String [] {
39
48
"Pod" ,
@@ -134,16 +143,14 @@ public void testLoadAllFile() throws Exception {
134
143
assertEquals ("Secret" , secret .getKind ());
135
144
assertEquals ("secret" , secret .getMetadata ().getName ());
136
145
assertEquals ("Opaque" , secret .getType ());
137
- assertEquals (
138
- "hello" , new String (secret .getData ().get ("secret-data" ), StandardCharsets .UTF_8 ));
146
+ assertEquals ("hello" , new String (secret .getData ().get ("secret-data" ), UTF_8 ));
139
147
} else {
140
148
throw new Exception ("some thing wrong happened" );
141
149
}
142
150
}
143
151
String result = Yaml .dumpAll (list .iterator ());
144
- String expected =
145
- new String (Files .readAllBytes (Paths .get (TEST_YAML_FILE_PATH )), StandardCharsets .UTF_8 );
146
- assertEquals (expected , result );
152
+ String expected = Resources .toString (EXPECTED_YAML_FILE , UTF_8 );
153
+ assertThat (result , equalTo (expected ));
147
154
}
148
155
149
156
@ Test
@@ -202,7 +209,7 @@ public void testLoadBytes() {
202
209
assertEquals (
203
210
"Incorrect value loaded for Base64 encoded secret" ,
204
211
"hello" ,
205
- new String (secret .getData ().get ("hello" ), StandardCharsets . UTF_8 ));
212
+ new String (secret .getData ().get ("hello" ), UTF_8 ));
206
213
207
214
} catch (Exception ex ) {
208
215
assertNull ("Unexpected exception: " + ex .toString (), ex );
@@ -223,9 +230,7 @@ public void testDateTime() {
223
230
assertEquals (
224
231
"Incorrect value loaded for creationTimestamp" ,
225
232
"2018-09-06T15:12:24.000Z" ,
226
- new String (
227
- pod .getMetadata ().getCreationTimestamp ().toString ().getBytes (),
228
- StandardCharsets .UTF_8 ));
233
+ new String (pod .getMetadata ().getCreationTimestamp ().toString ().getBytes (), UTF_8 ));
229
234
230
235
} catch (Exception ex ) {
231
236
assertNull ("Unexpected exception: " + ex .toString (), ex );
0 commit comments