Skip to content

Commit

Permalink
Fix integration test for ExpiringCacheAsync (#968)
Browse files Browse the repository at this point in the history
Fixes #967

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored and wborn committed Aug 10, 2019
1 parent 9d2f099 commit e05819f
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -19,14 +19,15 @@
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;

import org.eclipse.smarthome.test.java.JavaTest;
import org.junit.Test;

/**
* Tests cases for {@link ExpiringAsyncCache}.
*
* @author David Graeff - Initial contribution
*/
public class ExpiringCacheAsyncTest {
public class ExpiringCacheAsyncTest extends JavaTest {
double theValue = 0;

@Test(expected = IllegalArgumentException.class)
Expand All @@ -49,19 +50,19 @@ public void testFetchValue() throws InterruptedException, ExecutionException {

// We expect an immediate result with the value 10.0
assertEquals(10.0, t.getValue(s).get(), 0.0);
verify(s, times(1)).get();
// The value should be valid
assertFalse(t.isExpired());

// We expect an immediate result with the value 10.0, but not additional call to the supplier
assertEquals(10.0, t.getValue(s).get(), 0.0);
verify(s, times(1)).get();

// Wait
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
return;
}
// Wait for expiration
waitForAssert(() -> {
assertTrue(t.isExpired());
});

// We expect an immediate result with the value 10.0, and an additional call to the supplier
assertEquals(10.0, t.getValue(s).get(), 0.0);
verify(s, times(2)).get();
Expand Down

0 comments on commit e05819f

Please sign in to comment.