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 |
|
package info.magnolia.module.cache.cachepolicy.voters; |
35 |
|
|
36 |
|
import static org.junit.Assert.assertEquals; |
37 |
|
import static org.mockito.Mockito.*; |
38 |
|
|
39 |
|
import info.magnolia.module.cache.cachepolicy.instructor.CacheInstructor; |
40 |
|
import info.magnolia.module.cache.filter.CacheResponseWrapper; |
41 |
|
import info.magnolia.objectfactory.guice.GuiceUtils; |
42 |
|
import info.magnolia.voting.voters.VoterSet; |
43 |
|
|
44 |
|
import org.junit.Before; |
45 |
|
import org.junit.Test; |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.33 |
|
47 |
|
public class TtlVotingTest { |
48 |
|
|
49 |
|
private final CacheResponseWrapper cacheResponseWrapper = mock(CacheResponseWrapper.class); |
50 |
|
private final VoterSet voterSet = new VoterSet(); |
51 |
|
private final CacheInstructor cacheInstructor = new CacheInstructor(); |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
53 |
2 |
@Before... |
54 |
|
public void setUp() { |
55 |
2 |
voterSet.setVoting(new TtlVoting()); |
56 |
2 |
voterSet.addVoter(new ServerTtlVoter(GuiceUtils.providerForInstance(cacheInstructor))); |
57 |
2 |
voterSet.addVoter(new BrowserTtlVoter()); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
public void browserTtlWins() { |
62 |
|
|
63 |
1 |
when(cacheResponseWrapper.getTimeToLiveInSeconds()).thenReturn(123); |
64 |
|
|
65 |
|
|
66 |
1 |
int ttl = voterSet.vote(cacheResponseWrapper); |
67 |
|
|
68 |
|
|
69 |
1 |
assertEquals(123, ttl); |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
public void serverTtlWins() { |
74 |
|
|
75 |
1 |
cacheInstructor.setTtl(0); |
76 |
|
|
77 |
|
|
78 |
1 |
int ttl = voterSet.vote(cacheResponseWrapper); |
79 |
|
|
80 |
|
|
81 |
1 |
assertEquals(0, ttl); |
82 |
|
} |
83 |
|
} |