File tree 1 file changed +25
-0
lines changed
core-java/src/test/java/com/baeldung/java/properties
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 7
7
import java .io .FileOutputStream ;
8
8
import java .io .FileWriter ;
9
9
import java .io .IOException ;
10
+ import java .util .Enumeration ;
10
11
import java .util .Properties ;
11
12
12
13
import org .junit .Test ;
@@ -143,4 +144,28 @@ public void givenPropertyValueAbsent_LoadsValuesFromDefaultProperties() throws I
143
144
assertEquals ("TestApp" , appName );
144
145
assertEquals ("www.google.com" , defaultSite );
145
146
}
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
+ }
146
171
}
You can’t perform that action at this time.
0 commit comments