1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.testutils.mockers;
|
---|
3 |
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.Collections;
|
---|
6 | import java.util.HashMap;
|
---|
7 | import java.util.List;
|
---|
8 | import java.util.Map;
|
---|
9 |
|
---|
10 | import mockit.MockUp;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Abstract class implementing the few common features of the dialog-mockers which are readily factorable.
|
---|
14 | * @param <T> type
|
---|
15 | */
|
---|
16 | abstract class BaseDialogMockUp<T> extends MockUp<T> {
|
---|
17 | private final List<Object[]> invocationLog;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * @return an unmodifiable view of the internal invocation log. Each entry is an array of Objects to
|
---|
21 | * allow for more advanced implementations to be able to express their invocations in their own
|
---|
22 | * ways. Typically the invocation's "result value" is used as the first element of the array.
|
---|
23 | */
|
---|
24 | public List<Object[]> getInvocationLog() {
|
---|
25 | return this.invocationLog;
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Empties the invocation log.
|
---|
30 | */
|
---|
31 | public void resetInvocationLog() {
|
---|
32 | this.invocationLogInternal.clear();
|
---|
33 | }
|
---|
34 |
|
---|
35 | private final List<Object[]> invocationLogInternal = new ArrayList<>(4);
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * @return the actual (writable) invocation log
|
---|
39 | */
|
---|
40 | protected List<Object[]> getInvocationLogInternal() {
|
---|
41 | return this.invocationLogInternal;
|
---|
42 | }
|
---|
43 |
|
---|
44 | private final Map<String, Object> mockResultMap;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * @return mapping to {@link Object}s so response button can be specified by String (label) or Integer
|
---|
48 | * - sorry, no type safety as java doesn't support union types
|
---|
49 | */
|
---|
50 | public Map<String, Object> getMockResultMap() {
|
---|
51 | return this.mockResultMap;
|
---|
52 | }
|
---|
53 |
|
---|
54 | BaseDialogMockUp(final Map<String, Object> mockResultMap) {
|
---|
55 | this.mockResultMap = mockResultMap != null ? mockResultMap : new HashMap<>(4);
|
---|
56 | this.invocationLog = Collections.unmodifiableList(this.invocationLogInternal);
|
---|
57 | }
|
---|
58 | }
|
---|