1 package com.atlassian.vcache.internal.core.service;
2
3 import com.atlassian.vcache.VCacheException;
4 import org.junit.Rule;
5 import org.junit.Test;
6 import org.junit.rules.ExpectedException;
7
8 import java.util.Collections;
9 import java.util.HashMap;
10 import java.util.HashSet;
11 import java.util.Map;
12 import java.util.Set;
13
14 import static com.atlassian.vcache.internal.core.service.FactoryUtils.verifyFactoryResult;
15
16 public class FactoryUtilsTest {
17 @Rule
18 public ExpectedException thrown = ExpectedException.none();
19
20 @Test
21 public void happy_days() {
22 verifyFactoryResult(
23 Collections.singletonMap("single", "value"), Collections.singleton("single")
24 );
25 }
26
27 @Test
28 public void size_mismatch() {
29 thrown.expect(VCacheException.class);
30 thrown.expectMessage("Factory returned 0 entries when 1 were expected. Expected keys [single] but got [].");
31
32 verifyFactoryResult(
33 Collections.emptyMap(), Collections.singleton("single")
34 );
35 }
36
37 @Test
38 public void key_mismatch() {
39 final Set<String> expected = new HashSet<>();
40 expected.add("one");
41 expected.add("two");
42
43 final Map<String, String> result = new HashMap<>();
44 result.put("one", "ignored");
45 result.put("2", "ignored");
46
47 thrown.expect(VCacheException.class);
48 thrown.expectMessage("Factory returned the keys [2, one] when expected [one, two].");
49
50 verifyFactoryResult(result, expected);
51 }
52
53 }