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.assertEquals; 30 import static org.junit.Assert.assertFalse; 31 import static org.junit.Assert.assertNotSame; 32 import static org.junit.Assert.assertTrue; 33 34 import java.lang.reflect.Method; 35 36 import org.junit.Before; 37 import org.junit.Test; 38 import org.perfidix.annotation.Bench; 39 40 /** 41 * Test case for BenchmarkElements. 42 * 43 * @author Sebastian Graf, University of Konstanz 44 */ 45 public class BenchmarkElementTest { 46 47 private transient BenchmarkElement benchClass1; 48 private transient BenchmarkElement benchClass2; 49 50 /** 51 * Simple setUp 52 * 53 * @throws Exception 54 * of any kind 55 */ 56 @Before 57 public void setUp() throws Exception { 58 final Class<?> clazz = BenchClass.class; 59 final Method meth = clazz.getMethod("bench"); 60 final BenchmarkMethod benchMeth = new BenchmarkMethod(meth); 61 62 benchClass1 = new BenchmarkElement(benchMeth); 63 benchClass2 = new BenchmarkElement(benchMeth); 64 } 65 66 /** 67 * Test method for {@link org.perfidix.element.BenchmarkElement#getId()} . 68 */ 69 @Test 70 public void testID() { 71 assertNotSame("Id should be the same", benchClass1.getId(), benchClass2.getId()); 72 } 73 74 /** 75 * Test method for {@link org.perfidix.element.BenchmarkElement#equals(Object)} . 76 */ 77 @Test 78 public void testEquals() { 79 assertFalse("Bench classes should be the same", benchClass1.equals(benchClass2)); 80 assertTrue("Methods should be the same", benchClass1.getMeth().equals(benchClass2.getMeth())); 81 } 82 83 /** 84 * Test method for {@link org.perfidix.element.BenchmarkElement#hashCode()} . 85 */ 86 @Test 87 public void testHashCode() { 88 assertNotSame("HashCode of Class should not be the same", benchClass1.hashCode(), benchClass2 89 .hashCode()); 90 assertEquals("HashCode of Method should be the same", benchClass1.getMeth().hashCode(), benchClass2 91 .getMeth().hashCode()); 92 } 93 94 class BenchClass { 95 @Bench 96 public void bench() { 97 // Just a test for identifying classes and methods. 98 } 99 } 100 }