Skip to content

Commit ac425df

Browse files
author
Tanooj Luthra
committed
Fixed duplicate event issues, and added additional test
1 parent 92a89a3 commit ac425df

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/main/java/com/box/sdk/LRUCache.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public LRUCache() {
1414

1515
boolean add(E item) {
1616
boolean newItem = !this.linkedHashSet.remove(item);
17-
if (newItem) {
18-
this.linkedHashSet.add(item);
19-
}
17+
this.linkedHashSet.add(item);
2018

2119
if (this.linkedHashSet.size() >= MAX_SIZE) {
2220
Iterator<E> it = this.linkedHashSet.iterator();

src/test/java/com/box/sdk/LRUCacheTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public void addReturnsFalseForExistingItem() {
2626
assertThat(added, is(false));
2727
}
2828

29+
@Category(UnitTest.class)
30+
public void addReturnsFalseForExistingItemMultipleTimes() {
31+
LRUCache<Integer> lru = new LRUCache<Integer>();
32+
lru.add(1);
33+
lru.add(1);
34+
boolean added = lru.add(1);
35+
36+
assertThat(added, is(false));
37+
}
38+
2939
@Test
3040
@Category(UnitTest.class)
3141
public void addRemovesOldestItemWhenMaxSizeIsReached() {

0 commit comments

Comments
 (0)