1212 */
1313package io .kubernetes .client .util ;
1414
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 ;
1622
1723import com .google .common .io .Resources ;
1824import io .kubernetes .client .models .AppsV1beta1Deployment ;
2632import java .io .StringReader ;
2733import java .io .StringWriter ;
2834import 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 ;
3236import java .util .List ;
3337import org .junit .Test ;
3438
3539public 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+
3746 private static final String [] kinds =
3847 new String [] {
3948 "Pod" ,
@@ -134,16 +143,14 @@ public void testLoadAllFile() throws Exception {
134143 assertEquals ("Secret" , secret .getKind ());
135144 assertEquals ("secret" , secret .getMetadata ().getName ());
136145 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 ));
139147 } else {
140148 throw new Exception ("some thing wrong happened" );
141149 }
142150 }
143151 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 ));
147154 }
148155
149156 @ Test
@@ -202,7 +209,7 @@ public void testLoadBytes() {
202209 assertEquals (
203210 "Incorrect value loaded for Base64 encoded secret" ,
204211 "hello" ,
205- new String (secret .getData ().get ("hello" ), StandardCharsets . UTF_8 ));
212+ new String (secret .getData ().get ("hello" ), UTF_8 ));
206213
207214 } catch (Exception ex ) {
208215 assertNull ("Unexpected exception: " + ex .toString (), ex );
@@ -223,9 +230,7 @@ public void testDateTime() {
223230 assertEquals (
224231 "Incorrect value loaded for creationTimestamp" ,
225232 "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 ));
229234
230235 } catch (Exception ex ) {
231236 assertNull ("Unexpected exception: " + ex .toString (), ex );
0 commit comments