tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject incubator-tamaya-extensions git commit: [TAMAYA-243] Wrote some unit tests to ensure the correct behavior after fixing a bug.
Date Sun, 26 Feb 2017 10:51:50 GMT
Repository: incubator-tamaya-extensions
Updated Branches:
  refs/heads/master 507e21ed8 -> 946584592


[TAMAYA-243] Wrote some unit tests to ensure the correct behavior after fixing a bug.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/94658459
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/94658459
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/94658459

Branch: refs/heads/master
Commit: 94658459209eeee4f1406c17b6b3789b3eb31bb6
Parents: 507e21e
Author: Oliver B. Fischer <plexus@apache.org>
Authored: Sun Feb 26 11:51:16 2017 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Sun Feb 26 11:51:16 2017 +0100

----------------------------------------------------------------------
 .../internal/DefaultConfigChangeObserver.java   | 16 +++++++++---
 .../DefaultConfigChangeObserverTest.java        | 27 ++++++++++++++++++++
 2 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/94658459/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
index e87a748..9d4169c 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
@@ -64,22 +64,30 @@ public class DefaultConfigChangeObserver {
         FrozenConfiguration frozenConfig = FrozenConfiguration.of(ConfigurationProvider.getConfiguration());
         ConfigurationChange changes;
 
-        if (lastConfig == null) {
+        if (getLastConfig() == null) {
             changes = ConfigurationChangeBuilder.of().putAll(frozenConfig.getProperties())
                                                 .build();
         } else {
-            changes = ConfigurationChangeBuilder.of(lastConfig).addChanges(frozenConfig)
+            changes = ConfigurationChangeBuilder.of(getLastConfig()).addChanges(frozenConfig)
                                                 .build();
         }
 
-        lastConfig = frozenConfig;
-        
+        setLastConfig(frozenConfig);
+
         if(!changes.isEmpty()) {
             LOG.info("Identified configuration changes, publishing changes:\n" + changes);
             ConfigEventManager.fireEvent(changes);
         }
     }
 
+    protected FrozenConfiguration getLastConfig() {
+        return lastConfig;
+    }
+
+    protected void setLastConfig(FrozenConfiguration newConfiguration) {
+        lastConfig = newConfiguration;
+    }
+
     public long getCheckPeriod() {
         return checkPeriod;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/94658459/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java
b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java
index 6d62bd1..e0fa52b 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.tamaya.events.internal;
 
+import org.apache.tamaya.events.FrozenConfiguration;
 import org.junit.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -47,4 +48,30 @@ public class DefaultConfigChangeObserverTest {
         assertThat(sut.isMonitoring()).isFalse();
     }
 
+    @Test
+    public void lastConfigIsSetByTheFirstCheckForChangesInTheConfiguration() {
+        DefaultConfigChangeObserver observer = new DefaultConfigChangeObserver();
+
+        assertThat(observer.getLastConfig()).describedAs("There must be no last configuration
after creation.")
+                                            .isNull();
+
+        observer.checkConfigurationUpdate();
+
+        assertThat(observer.getLastConfig()).describedAs("After the firt check last configuration
must be set.")
+                                            .isNotNull();
+    }
+
+    @Test
+    public void lastConfigIsUpdatedByASubSequentCheckForChangesInTheConfigration() {
+        DefaultConfigChangeObserver observer = new DefaultConfigChangeObserver();
+
+        observer.checkConfigurationUpdate();
+
+        FrozenConfiguration config1 = observer.getLastConfig();
+        observer.checkConfigurationUpdate();
+        FrozenConfiguration config2 = observer.getLastConfig();
+
+        assertThat(config1).describedAs("After the firt check last configuration must be
set.")
+                                            .isNotEqualTo(config2);
+    }
 }
\ No newline at end of file


Mime
View raw message