1010import java .util .AbstractMap ;
1111import java .util .Collections ;
1212import java .util .Iterator ;
13+ import java .util .NoSuchElementException ;
1314import org .junit .jupiter .api .Test ;
1415
1516public class TestProperties {
@@ -197,6 +198,24 @@ void testGetRaw() throws IOException, URISyntaxException {
197198 assertThat (p .getRaw ("key.4" )).isEqualTo ("\\ u1234\u1234 " );
198199 }
199200
201+ @ Test
202+ void testGetNonExistent () throws IOException , URISyntaxException {
203+ Properties p = Properties .loadProperties (getResource ("/test.properties" ));
204+ assertThat (p .get ("wrong" )).isNull ();
205+ }
206+
207+ @ Test
208+ void testGetPropertyNonExistent () throws IOException , URISyntaxException {
209+ Properties p = Properties .loadProperties (getResource ("/test.properties" ));
210+ assertThat (p .getProperty ("wrong" )).isNull ();
211+ }
212+
213+ @ Test
214+ void testGetPropertyDefault () throws IOException , URISyntaxException {
215+ Properties p = Properties .loadProperties (getResource ("/test.properties" ));
216+ assertThat (p .getProperty ("wrong" , "right" )).isEqualTo ("right" );
217+ }
218+
200219 @ Test
201220 void testGetComment () throws IOException , URISyntaxException {
202221 Properties p = Properties .loadProperties (getResource ("/test.properties" ));
@@ -206,13 +225,20 @@ void testGetComment() throws IOException, URISyntaxException {
206225 .containsExactly ("# another comment" , "! and a comment" , "! block" );
207226 }
208227
228+ @ Test
229+ void testGetCommentNonExistent () throws IOException , URISyntaxException {
230+ Properties p = Properties .loadProperties (getResource ("/test.properties" ));
231+ assertThat (p .getComment ("wrong" )).isEmpty ();
232+ }
233+
209234 @ Test
210235 void testCommentFirstLine () throws IOException , URISyntaxException {
211236 Properties p = Properties .loadProperties (getResource ("/test-commentfirstline.properties" ));
212237 assertThat (p .getComment ("one" )).containsExactly ("#comment1" , "# comment2" );
213238 StringWriter sw = new StringWriter ();
214239 p .store (sw );
215- assertThat (sw .toString ()).isEqualTo (readAll (getResource ("/test-commentfirstline.properties" )));
240+ assertThat (sw .toString ())
241+ .isEqualTo (readAll (getResource ("/test-commentfirstline.properties" )));
216242 }
217243
218244 @ Test
@@ -229,6 +255,16 @@ void testSetComment() throws IOException, URISyntaxException {
229255 assertThat (sw .toString ()).isEqualTo (readAll (getResource ("/test-comment.properties" )));
230256 }
231257
258+ @ Test
259+ void testSetCommentNonExistent () throws IOException , URISyntaxException {
260+ Properties p = Properties .loadProperties (getResource ("/test.properties" ));
261+ assertThatThrownBy (
262+ () -> {
263+ p .setComment ("wrong" , "dummy" );
264+ })
265+ .isInstanceOf (NoSuchElementException .class );
266+ }
267+
232268 @ Test
233269 void testPut () throws IOException , URISyntaxException {
234270 Properties p = new Properties ();
@@ -499,6 +535,12 @@ void testRemoveAll() throws IOException, URISyntaxException {
499535 assertThat (sw .toString ()).isEqualTo (readAll (getResource ("/test-removeall.properties" )));
500536 }
501537
538+ @ Test
539+ void testRemoveNonExistent () throws IOException , URISyntaxException {
540+ Properties p = Properties .loadProperties (getResource ("/test.properties" ));
541+ assertThat (p .remove ("wrong" )).isNull ();
542+ }
543+
502544 @ Test
503545 void testRemoveMiddleIterator () throws IOException , URISyntaxException {
504546 Properties p = Properties .loadProperties (getResource ("/test.properties" ));
0 commit comments