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 package org.perfidix.element;
28
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.fail;
31
32 import java.lang.reflect.Method;
33 import java.util.ArrayList;
34 import java.util.Iterator;
35 import java.util.List;
36
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.perfidix.annotation.Bench;
40
41
42
43
44
45
46 public class SequentialMethodArrangementTest {
47
48 private transient List<BenchmarkElement> elemSet;
49
50 private final static String BENCH1NAME = "bench1";
51 private final static String BENCH2NAME = "bench2";
52 private final static String BENCH4NAME = "bench4";
53
54
55
56
57
58
59
60 @Before
61 public void setUp() throws Exception {
62 elemSet = new ArrayList<BenchmarkElement>();
63 final Class<?> testClazz = TestBenchClass.class;
64 for (final Method meth : testClazz.getDeclaredMethods()) {
65 if (BenchmarkMethod.isBenchmarkable(meth)) {
66 elemSet.add(new BenchmarkElement(new BenchmarkMethod(meth)));
67 }
68 }
69 Method meth = testClazz.getMethod(BENCH2NAME);
70 elemSet.add(new BenchmarkElement(new BenchmarkMethod(meth)));
71 meth = testClazz.getMethod(BENCH2NAME);
72 elemSet.add(new BenchmarkElement(new BenchmarkMethod(meth)));
73 meth = testClazz.getMethod(BENCH4NAME);
74 elemSet.add(new BenchmarkElement(new BenchmarkMethod(meth)));
75 }
76
77
78
79
80 @Test
81 public void test() {
82 try {
83
84 final AbstractMethodArrangement arrangement =
85 AbstractMethodArrangement.getMethodArrangement(elemSet,
86 KindOfArrangement.SequentialMethodArrangement);
87 final String[] expectedNames = {
88 BENCH2NAME, BENCH2NAME, BENCH2NAME, BENCH4NAME, BENCH4NAME, BENCH1NAME
89 };
90 final Iterator<BenchmarkElement> iterBench = arrangement.iterator();
91 final BenchmarkElement elem1 = iterBench.next();
92 final BenchmarkElement elem2 = iterBench.next();
93 final BenchmarkElement elem3 = iterBench.next();
94 final BenchmarkElement elem4 = iterBench.next();
95 final BenchmarkElement elem5 = iterBench.next();
96 final BenchmarkElement elem6 = iterBench.next();
97 if ((expectedNames[0].equals(elem1.getMeth().getMethodToBench().getName()))
98 && (expectedNames[1].equals(elem2.getMeth().getMethodToBench().getName()))
99 && (expectedNames[2].equals(elem3.getMeth().getMethodToBench().getName()))
100 && (expectedNames[3].equals(elem4.getMeth().getMethodToBench().getName()))
101 && (expectedNames[4].equals(elem5.getMeth().getMethodToBench().getName()))
102 && (expectedNames[5].equals(elem6.getMeth().getMethodToBench().getName()))) {
103 fail("Something has to be arranged in a different way!");
104 }
105
106 assertFalse("No more elements should be there", iterBench.hasNext());
107
108 } catch (final Exception e) {
109 fail(e.toString());
110 }
111 }
112
113 class TestBenchClass {
114
115 @Bench
116 public void bench1() {
117
118 }
119
120 @Bench
121 public void bench2() {
122
123 }
124
125 public void bench3() {
126
127 }
128
129 @Bench
130 public void bench4() {
131
132 }
133
134 }
135
136 }