1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package com.bumptech.glide.load.model;
import com.google.common.testing.EqualsTester;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import static org.junit.Assert.assertEquals;
@RunWith(JUnit4.class)
public class ModelCacheTest {
private ModelCache<Object, Object> cache;
@Before
public void setUp() {
cache = new ModelCache<Object, Object>(10);
}
@Test
public void testModelKeyEquivalence() {
new EqualsTester()
.addEqualityGroup(ModelCache.ModelKey.get(14f, 100, 200), ModelCache.ModelKey.get(14f, 100, 200))
.addEqualityGroup(ModelCache.ModelKey.get(13f, 100, 200))
.addEqualityGroup(ModelCache.ModelKey.get(14f, 200, 200))
.addEqualityGroup(ModelCache.ModelKey.get(14f, 100, 300))
.testEquals();
}
@Test
public void testCanSetAndGetModel() {
Object model = new Object();
int width = 10;
int height = 20;
Object result = new Object();
cache.put(model, width, height, result);
assertEquals(result, cache.get(model, width, height));
}
@Test
public void testCanSetAndGetMultipleResultsWithDifferentDimensionsForSameObject() {
Object model = new Object();
int firstWidth = 10, firstHeight = 20;
Object firstResult = new Object();
int secondWidth = 30, secondHeight = 40;
Object secondResult = new Object();
cache.put(model, firstWidth, firstHeight, firstResult);
cache.put(model, secondWidth, secondHeight, secondResult);
assertEquals(firstResult, cache.get(model, firstWidth, firstHeight));
assertEquals(secondResult, cache.get(model, secondWidth, secondHeight));
}
}
|