Skip to content

Commit 2d9e44d

Browse files
Merge pull request #21 from BorderTech/fix-qa
Fix qa
2 parents eda1871 + eaeedef commit 2d9e44d

File tree

7 files changed

+107
-8
lines changed

7 files changed

+107
-8
lines changed

src/main/java/com/github/bordertech/config/Config.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ public static void notifyListeners() {
160160
// If we get here, then there is at least one listener who wants to be notified when a refresh occurs. The first
161161
// step in this notification process is to create the PropertyChangeEvent object that will be sent to each of
162162
// the registered PropertyChangeListeners.
163-
//
164-
// PropertyChangeEvent event = new PropertyChangeEvent(this, "propertiesRefresh", null, null);
163+
// <code>PropertyChangeEvent event = new PropertyChangeEvent(this, "propertiesRefresh", null, null);</code>
165164
//
166165
// Finally, iterate through the complete set of PropertyChangeListeners and notify them that a change has
167166
// occurred.

src/main/java/com/github/bordertech/config/DefaultConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
import java.nio.charset.StandardCharsets;
1515
import java.security.CodeSource;
1616
import java.security.ProtectionDomain;
17+
import java.util.ArrayDeque;
1718
import java.util.ArrayList;
1819
import java.util.Arrays;
1920
import java.util.Collections;
21+
import java.util.Deque;
2022
import java.util.Enumeration;
2123
import java.util.HashMap;
2224
import java.util.HashSet;
@@ -26,7 +28,6 @@
2628
import java.util.Objects;
2729
import java.util.Properties;
2830
import java.util.Set;
29-
import java.util.Stack;
3031
import java.util.StringTokenizer;
3132
import java.util.TreeSet;
3233
import org.apache.commons.configuration.Configuration;
@@ -141,7 +142,7 @@ public class DefaultConfiguration implements Configuration {
141142
/**
142143
* The resource being loaded. This is used for the relative form of resource loading.
143144
*/
144-
private final Stack<String> resources = new Stack<>();
145+
private final Deque<String> resources = new ArrayDeque<>();
145146

146147
/**
147148
* A generic object that allows us to synchronized refreshes. Required so that gets and refreshes are threadsafe

src/main/java/com/github/bordertech/config/Touchfile.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Touchfile {
1515
/**
1616
* The touch file.
1717
*/
18-
private final File touchfile;
18+
private final File file;
1919

2020
/**
2121
* Check interval in milli seconds.
@@ -41,10 +41,10 @@ public Touchfile(final String filename, final long checkInterval) {
4141
throw new IllegalArgumentException("A touch filename must be provided.");
4242
}
4343
this.filename = filename;
44-
this.touchfile = new File(filename);
44+
this.file = new File(filename);
4545
this.checkInterval = checkInterval < 0 ? 0 : checkInterval;
4646
this.lastChecked = System.currentTimeMillis();
47-
this.lastModified = touchfile.lastModified();
47+
this.lastModified = file.lastModified();
4848
}
4949

5050
/**
@@ -61,7 +61,7 @@ public boolean hasChanged() {
6161
lastChecked = now;
6262

6363
// Has the file changed?
64-
long modified = touchfile.lastModified();
64+
long modified = file.lastModified();
6565
if (lastModified == modified) {
6666
// No Change
6767
return false;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.github.bordertech.config;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.PrintStream;
5+
import org.junit.After;
6+
import org.junit.Assert;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
/**
11+
* DefaultConfigurationDumpTest - JUnit tests for {@link DefaultConfiguration}.
12+
*/
13+
public class DefaultConfigurationDumpTest {
14+
15+
private PrintStream original;
16+
private ByteArrayOutputStream systemErr;
17+
18+
private static final String LOG_START = "Properties loaded start";
19+
private static final String LOG_END = "Properties loaded end";
20+
private static final String LOG_PARAM = "simple.param1";
21+
22+
@Before
23+
public void redirectSystemOutStream() {
24+
original = System.err;
25+
systemErr = new ByteArrayOutputStream();
26+
System.setErr(new PrintStream(systemErr));
27+
}
28+
29+
@After
30+
public void restoreSystemOutStream() {
31+
System.setErr(original);
32+
}
33+
34+
@Test
35+
public void dumpParametersEnabled() {
36+
DefaultConfiguration config = new DefaultConfiguration(
37+
"com/github/bordertech/config/DefaultConfigurationTestDumpEnabled.properties");
38+
// Check dump enabled
39+
Assert.assertTrue(config.getBoolean(DefaultConfiguration.DUMP));
40+
String log = systemErr.toString();
41+
Assert.assertTrue("Output should contain dump start load", log.contains(LOG_START));
42+
Assert.assertTrue("Output should contain dump start end", log.contains(LOG_END));
43+
Assert.assertTrue("Output should contain property", log.contains(LOG_PARAM));
44+
}
45+
46+
@Test
47+
public void dumpParametersDisabled() {
48+
DefaultConfiguration config = new DefaultConfiguration(
49+
"com/github/bordertech/config/DefaultConfigurationTestDumpDisabled.properties");
50+
// Check dump disabled
51+
Assert.assertFalse(config.getBoolean(DefaultConfiguration.DUMP));
52+
String log = systemErr.toString();
53+
Assert.assertFalse("Output should not contain dump start load", log.contains(LOG_START));
54+
Assert.assertFalse("Output should not contain dump start end", log.contains(LOG_END));
55+
Assert.assertFalse("Output should not contain property", log.contains(LOG_PARAM));
56+
}
57+
58+
}

src/test/java/com/github/bordertech/config/DefaultConfigurationTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@ public void testGetProperties() {
347347
assertPropertyEquals("key3", "value3", props);
348348
}
349349

350+
@Test
351+
public void testRefresh() {
352+
String orig = "simplePropertyValue";
353+
String newValue = "newvalue";
354+
assertPropertyEquals(STRING_PROPERTY_KEY, orig);
355+
config.setProperty(STRING_PROPERTY_KEY, newValue);
356+
assertPropertyEquals(STRING_PROPERTY_KEY, newValue);
357+
config.refresh();
358+
assertPropertyEquals(STRING_PROPERTY_KEY, orig);
359+
}
360+
350361
/**
351362
* Asserts that the configuration contains the given key/value.
352363
*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
############################################################################
2+
# This property file is for the DefaultConfiguration_Test jUnit test
3+
# It must not be included or be included by property file that is not
4+
# directly related to the test.
5+
############################################################################
6+
7+
# -------------------------------------------------------------------------------------------------
8+
# Simple property tests
9+
# -------------------------------------------------------------------------------------------------
10+
simple.param1=A
11+
simple.param2=B
12+
simple.param3=C
13+
14+
## Do not dump parameters
15+
bordertech.config.parameters.dump.console=false
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
############################################################################
2+
# This property file is for the DefaultConfiguration_Test jUnit test
3+
# It must not be included or be included by property file that is not
4+
# directly related to the test.
5+
############################################################################
6+
7+
# -------------------------------------------------------------------------------------------------
8+
# Simple property tests
9+
# -------------------------------------------------------------------------------------------------
10+
simple.param1=A
11+
simple.param2=B
12+
simple.param3=C
13+
14+
## Dump parameters
15+
bordertech.config.parameters.dump.console=true

0 commit comments

Comments
 (0)