1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.test; |
16 |
| |
17 |
| import org.easymock.AbstractMatcher; |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| public class AggregateArgumentsMatcher extends AbstractMatcher |
24 |
| { |
25 |
| private ArgumentMatcher[] _matchers; |
26 |
| |
27 |
| private ArgumentMatcher _defaultMatcher = new EqualsMatcher(); |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
7
| public AggregateArgumentsMatcher(ArgumentMatcher[] matchers)
|
36 |
| { |
37 |
7
| _matchers = matchers;
|
38 |
| } |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
1
| public AggregateArgumentsMatcher(ArgumentMatcher matcher)
|
44 |
| { |
45 |
1
| this(new ArgumentMatcher[]
|
46 |
| { matcher }); |
47 |
| } |
48 |
| |
49 |
8
| public boolean matches(Object[] expected, Object[] actual)
|
50 |
| { |
51 |
8
| for (int i = 0; i < expected.length; i++)
|
52 |
| { |
53 |
19
| if (!matches(i, expected[i], actual[i]))
|
54 |
2
| return false;
|
55 |
| } |
56 |
| |
57 |
6
| return true;
|
58 |
| } |
59 |
| |
60 |
19
| private boolean matches(int argumentIndex, Object expected, Object actual)
|
61 |
| { |
62 |
19
| if (expected == actual)
|
63 |
8
| return true;
|
64 |
| |
65 |
| |
66 |
| |
67 |
11
| if (expected == null || actual == null)
|
68 |
1
| return false;
|
69 |
| |
70 |
10
| ArgumentMatcher am = getArgumentMatcher(argumentIndex);
|
71 |
| |
72 |
10
| return am.compareArguments(expected, actual);
|
73 |
| } |
74 |
| |
75 |
10
| private ArgumentMatcher getArgumentMatcher(int argumentIndex)
|
76 |
| { |
77 |
10
| if (argumentIndex >= _matchers.length)
|
78 |
1
| return _defaultMatcher;
|
79 |
| |
80 |
9
| ArgumentMatcher result = _matchers[argumentIndex];
|
81 |
| |
82 |
9
| if (result == null)
|
83 |
4
| result = _defaultMatcher;
|
84 |
| |
85 |
9
| return result;
|
86 |
| } |
87 |
| } |