2020
2121import java .io .ByteArrayInputStream ;
2222import java .io .File ;
23- import java .io .FileOutputStream ;
2423import java .io .IOException ;
2524import java .io .InputStream ;
2625import java .io .OutputStream ;
3029import java .lang .annotation .RetentionPolicy ;
3130import java .lang .annotation .Target ;
3231import java .net .URL ;
32+ import java .nio .file .Files ;
3333import java .util .Properties ;
3434
3535import org .junit .jupiter .api .Test ;
3636import org .junit .jupiter .api .io .TempDir ;
3737
38- import static org . hamcrest . CoreMatchers . is ;
39- import static org .hamcrest . CoreMatchers . nullValue ;
40- import static org .hamcrest . MatcherAssert . assertThat ;
38+ import static java . nio . charset . StandardCharsets . ISO_8859_1 ;
39+ import static org .junit . jupiter . api . Assertions . assertEquals ;
40+ import static org .junit . jupiter . api . Assertions . assertNull ;
4141
4242public class PropertyUtilsTest {
4343
@@ -51,72 +51,72 @@ public class PropertyUtilsTest {
5151 @ Test
5252 @ SuppressWarnings ("deprecation" )
5353 // @ReproducesPlexusBug( "Should return null on error like url and file do" )
54- public void loadNullInputStream () throws Exception {
55- assertThat ( PropertyUtils .loadProperties ((InputStream ) null ), is ( new Properties () ));
54+ public void loadNullInputStream () {
55+ assertEquals ( new Properties (), PropertyUtils .loadProperties ((InputStream ) null ));
5656 }
5757
5858 @ Test
59- public void loadOptionalNullInputStream () throws Exception {
60- assertThat ( PropertyUtils .loadOptionalProperties ((InputStream ) null ), is ( new Properties () ));
59+ public void loadOptionalNullInputStream () {
60+ assertEquals ( new Properties (), PropertyUtils .loadOptionalProperties ((InputStream ) null ));
6161 }
6262
6363 @ Test
6464 public void loadOptionalPropertiesIoException () throws Exception {
6565 URL url = new URL ("https://nonesuch12344.foo.bar.com" );
66- assertThat ( PropertyUtils . loadOptionalProperties ( url ), is ( new Properties ()));
66+ assertEquals ( new Properties (), PropertyUtils . loadOptionalProperties ( url ));
6767 }
6868
6969 @ Test
70- @ SuppressWarnings ("deprecation" )
71- public void loadNullURL () throws Exception {
72- assertThat (PropertyUtils .loadProperties ((URL ) null ), nullValue ( Properties . class ));
70+ @ SuppressWarnings ({ "deprecation" , "DataFlowIssue" } )
71+ public void loadNullURL () {
72+ assertNull (PropertyUtils .loadProperties ((URL ) null ));
7373 }
7474
7575 @ Test
76- public void loadOptionalNullURL () throws Exception {
77- assertThat ( PropertyUtils .loadOptionalProperties ((URL ) null ), is ( new Properties () ));
76+ public void loadOptionalNullURL () {
77+ assertEquals ( new Properties (), PropertyUtils .loadOptionalProperties ((URL ) null ));
7878 }
7979
8080 @ Test
81- @ SuppressWarnings ("deprecation" )
82- public void loadNullFile () throws Exception {
83- assertThat (PropertyUtils .loadProperties ((File ) null ), nullValue ( Properties . class ));
81+ @ SuppressWarnings ({ "deprecation" , "DataFlowIssue" } )
82+ public void loadNullFile () {
83+ assertNull (PropertyUtils .loadProperties ((File ) null ));
8484 }
8585
8686 @ Test
87- public void loadOptionalNullFile () throws Exception {
88- assertThat ( PropertyUtils .loadOptionalProperties ((File ) null ), is ( new Properties () ));
87+ public void loadOptionalNullFile () {
88+ assertEquals ( new Properties (), PropertyUtils .loadOptionalProperties ((File ) null ));
8989 }
9090
9191 @ Test
9292 @ SuppressWarnings ("deprecation" )
93- public void loadEmptyInputStream () throws Exception {
94- assertThat ( PropertyUtils .loadProperties (new ByteArrayInputStream (new byte [0 ])), is ( new Properties ( )));
93+ public void loadEmptyInputStream () {
94+ assertEquals ( new Properties (), PropertyUtils .loadProperties (new ByteArrayInputStream (new byte [0 ])));
9595
96- assertThat ( PropertyUtils .loadOptionalProperties (new ByteArrayInputStream (new byte [0 ])), is ( new Properties ( )));
96+ assertEquals ( new Properties (), PropertyUtils .loadOptionalProperties (new ByteArrayInputStream (new byte [0 ])));
9797 }
9898
9999 @ Test
100100 @ NeedsTemporaryFolder
101101 @ SuppressWarnings ("deprecation" )
102102 public void loadEmptyFile () throws Exception {
103- assertThat ( PropertyUtils .loadProperties (newFile (tempFolder , "empty" )), is ( new Properties ( )));
104- assertThat ( PropertyUtils .loadOptionalProperties (newFile (tempFolder , "optional" )), is ( new Properties ( )));
103+ assertEquals ( new Properties (), PropertyUtils .loadProperties (newFile (tempFolder , "empty" )));
104+ assertEquals ( new Properties (), PropertyUtils .loadOptionalProperties (newFile (tempFolder , "optional" )));
105105 }
106106
107107 @ Test
108108 @ NeedsTemporaryFolder
109109 @ SuppressWarnings ("deprecation" )
110110 public void loadEmptyURL () throws Exception {
111- assertThat (
111+ assertEquals (
112+ new Properties (),
112113 PropertyUtils .loadProperties (
113- newFile (tempFolder , "empty" ).toURI ().toURL ()),
114- is (new Properties ()));
114+ newFile (tempFolder , "empty" ).toURI ().toURL ()));
115115
116- assertThat (
116+ assertEquals (
117+ new Properties (),
117118 PropertyUtils .loadOptionalProperties (
118- newFile (tempFolder , "optional" ).toURI ().toURL ()),
119- is (new Properties ()));
119+ newFile (tempFolder , "optional" ).toURI ().toURL ()));
120120 }
121121
122122 @ Test
@@ -125,11 +125,9 @@ public void loadValidInputStream() throws UnsupportedEncodingException {
125125 Properties value = new Properties ();
126126 value .setProperty ("a" , "b" );
127127
128- assertThat ( PropertyUtils .loadProperties (new ByteArrayInputStream ("a=b" .getBytes ("ISO-8859-1" ))), is ( value ));
128+ assertEquals ( value , PropertyUtils .loadProperties (new ByteArrayInputStream ("a=b" .getBytes (ISO_8859_1 )) ));
129129
130- assertThat (
131- PropertyUtils .loadOptionalProperties (new ByteArrayInputStream ("a=b" .getBytes ("ISO-8859-1" ))),
132- is (value ));
130+ assertEquals (value , PropertyUtils .loadOptionalProperties (new ByteArrayInputStream ("a=b" .getBytes (ISO_8859_1 ))));
133131 }
134132
135133 @ Test
@@ -139,10 +137,10 @@ public void loadValidFile() throws IOException {
139137 File valid = newFile (tempFolder , "valid" );
140138 Properties value = new Properties ();
141139 value .setProperty ("a" , "b" );
142- try (OutputStream out = new FileOutputStream (valid )) {
140+ try (OutputStream out = Files . newOutputStream (valid . toPath () )) {
143141 value .store (out , "a test" );
144- assertThat ( PropertyUtils .loadProperties (valid ), is ( value ));
145- assertThat ( PropertyUtils .loadOptionalProperties (valid ), is ( value ));
142+ assertEquals ( value , PropertyUtils .loadProperties (valid ));
143+ assertEquals ( value , PropertyUtils .loadOptionalProperties (valid ));
146144 }
147145 }
148146
@@ -153,10 +151,11 @@ public void loadValidURL() throws IOException {
153151 File valid = newFile (tempFolder , "valid" );
154152 Properties value = new Properties ();
155153 value .setProperty ("a" , "b" );
156- try (OutputStream out = new FileOutputStream (valid )) {
154+ try (OutputStream out = Files . newOutputStream (valid . toPath () )) {
157155 value .store (out , "a test" );
158- assertThat (PropertyUtils .loadProperties (valid .toURI ().toURL ()), is (value ));
159- assertThat (PropertyUtils .loadOptionalProperties (valid .toURI ().toURL ()), is (value ));
156+ assertEquals (value , PropertyUtils .loadProperties (valid .toURI ().toURL ()));
157+ assertEquals (
158+ value , PropertyUtils .loadOptionalProperties (valid .toURI ().toURL ()));
160159 }
161160 }
162161
0 commit comments