Skip to content

Commit 5aff058

Browse files
authored
Merge pull request eugenp#5875 from amit2103/BAEL-9643
[BAEL-9643] - Added missing code in the properties article
2 parents f5def52 + 7073c4a commit 5aff058

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

core-java/src/test/java/com/baeldung/java/properties/PropertiesUnitTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.FileOutputStream;
88
import java.io.FileWriter;
99
import java.io.IOException;
10+
import java.util.Enumeration;
1011
import java.util.Properties;
1112

1213
import 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
}

0 commit comments

Comments
 (0)