File tree Expand file tree Collapse file tree
core-java/src/test/java/com/baeldung/java/properties Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77import java .io .FileOutputStream ;
88import java .io .FileWriter ;
99import java .io .IOException ;
10+ import java .util .Enumeration ;
1011import java .util .Properties ;
1112
1213import org .junit .Test ;
@@ -143,4 +144,28 @@ public void givenPropertyValueAbsent_LoadsValuesFromDefaultProperties() throws I
143144 assertEquals ("TestApp" , appName );
144145 assertEquals ("www.google.com" , defaultSite );
145146 }
147+
148+ @ Test
149+ public void givenPropertiesSize_whenPropertyFileLoaded_thenCorrect () throws IOException {
150+
151+ String rootPath = Thread .currentThread ().getContextClassLoader ().getResource ("" ).getPath ();
152+ String appPropsPath = rootPath + "app.properties" ;
153+ Properties appProps = new Properties ();
154+ appProps .load (new FileInputStream (appPropsPath ));
155+
156+ appProps .list (System .out ); // list all key-value pairs
157+
158+ Enumeration <Object > valueEnumeration = appProps .elements ();
159+ while (valueEnumeration .hasMoreElements ()) {
160+ System .out .println (valueEnumeration .nextElement ());
161+ }
162+
163+ Enumeration <Object > keyEnumeration = appProps .keys ();
164+ while (keyEnumeration .hasMoreElements ()) {
165+ System .out .println (keyEnumeration .nextElement ());
166+ }
167+
168+ int size = appProps .size ();
169+ assertEquals (3 , size );
170+ }
146171}
You can’t perform that action at this time.
0 commit comments