diff options
Diffstat (limited to 'same/src/test')
-rw-r--r-- | same/src/test/java/com/orbekk/same/VariableUpdaterTaskTest.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/same/src/test/java/com/orbekk/same/VariableUpdaterTaskTest.java b/same/src/test/java/com/orbekk/same/VariableUpdaterTaskTest.java new file mode 100644 index 0000000..3ecf444 --- /dev/null +++ b/same/src/test/java/com/orbekk/same/VariableUpdaterTaskTest.java @@ -0,0 +1,62 @@ +package com.orbekk.same; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; + +public class VariableUpdaterTaskTest { + Variable<String> v; + VariableUpdaterTask<String> updater; + + @Before public void setUp() { + v = mock(Variable.class); + updater = new VariableUpdaterTask<String>(v); + } + + @Test + public void updatesValue() { + updater.set("FirstValue"); + updater.performWork(); + verify(v).set("FirstValue"); + } + + @Test + public void noUpdateIfNotSet() { + updater.set("FirstValue"); + updater.performWork(); + reset(v); + updater.performWork(); + verify(v, never()).set(anyString()); + } + + @Test + public void noUpdateIfNotReady() { + updater.set("FirstValue"); + updater.performWork(); + reset(v); + updater.set("SecondValue"); + updater.performWork(); + verify(v, never()).set(anyString()); + } + + @Test + public void updatesWhenReady() { + updater.set("Value1"); + updater.performWork(); + reset(v); + updater.valueChanged(null); + updater.set("Value2"); + updater.performWork(); + verify(v).set("Value2"); + } + + @Test + public void choosesLastUpdate() { + updater.set("FirstValue"); + updater.set("SecondValue"); + updater.performWork(); + verify(v).set("SecondValue"); + } +} |