-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08abe5c
commit 4bba78f
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/test/java/com/fewlaps/quitnowcache/GetOrDefaultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.fewlaps.quitnowcache; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class GetOrDefaultTest extends BaseTest { | ||
|
||
QNCache<String> cache; | ||
|
||
@Before | ||
public void init() { | ||
cache = new QNCacheBuilder().createQNCache(); | ||
} | ||
|
||
@Test | ||
public void valueIsReturnedIfItsPresent() { | ||
cache.set(A_KEY, A_VALUE, ONE_SECOND); | ||
|
||
String result = cache.getOrDefault(A_KEY, "nothing"); | ||
|
||
assertEquals(A_VALUE, result); | ||
} | ||
|
||
@Test | ||
public void defaultIsReturnedIfValueIsNotPresent() { | ||
cache.remove(A_KEY); | ||
|
||
String result = cache.getOrDefault(A_KEY, "nothing"); | ||
|
||
assertEquals("nothing", result); | ||
} | ||
} |