1 /**
2 * Copyright (c) 2012, University of Konstanz, Distributed Systems Group
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of Konstanz nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 * Testcase for shuffle method arrangement.
43 *
44 * @author Sebastian Graf, University of Konstanz
45 */
46 public class ShuffleMethodArrangementTest {
47
48 private transient List<BenchmarkElement> elemSet;
49
50 /**
51 * Before method to setUp Benchmarkables.
52 */
53 @Before
54 public void setUp() {
55 elemSet = new ArrayList<BenchmarkElement>();
56 final Class<?> testClazz = TestBenchClass.class;
57 for (final Method meth : testClazz.getDeclaredMethods()) {
58 if (BenchmarkMethod.isBenchmarkable(meth)) {
59 elemSet.add(new BenchmarkElement(new BenchmarkMethod(meth)));
60 }
61 }
62 }
63
64 /**
65 * Test method for {@link org.perfidix.element.ShuffleMethodArrangement} .
66 */
67 @Test
68 public void test() {
69 try {
70
71 final AbstractMethodArrangement arrangement =
72 AbstractMethodArrangement.getMethodArrangement(elemSet, KindOfArrangement.ShuffleArrangement);
73 final String[] expectedNames = {
74 "bench1", "bench2", "bench4"
75 };
76 final Iterator<BenchmarkElement> iterBench = arrangement.iterator();
77 final BenchmarkElement elem1 = iterBench.next();
78 final BenchmarkElement elem2 = iterBench.next();
79 final BenchmarkElement elem3 = iterBench.next();
80 if ((expectedNames[0].equals(elem1.getMeth().getMethodToBench().getName()))
81 && (expectedNames[1].equals(elem2.getMeth().getMethodToBench().getName()))
82 && (expectedNames[2].equals(elem3.getMeth().getMethodToBench().getName()))) {
83 fail("Something has to be arranged in a different way!");
84
85 }
86 assertFalse("No more elements should be left", iterBench.hasNext());
87
88 } catch (final Exception e) {
89 fail(e.toString());
90 }
91 }
92
93 class TestBenchClass {
94
95 @Bench
96 public void bench1() {
97 // Just a bench-sekeleton
98 }
99
100 @Bench
101 public void bench2() {
102 // Just a bench-sekeleton
103 }
104
105 public void bench3() {
106 // Just a bench-sekeleton
107 }
108
109 @Bench
110 public void bench4() {
111 // Just a bench-sekeleton
112 }
113
114 }
115
116 }