blob: dcc61131abb379ffb3d6083c7354feb73e322da5 [file] [log] [blame]
Paul Duffine2363012015-11-30 16:20:41 +00001/*
2 * Copyright (C) 2013 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.caliper.runner;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.fail;
21
22import com.google.caliper.AfterExperiment;
23import com.google.caliper.BeforeExperiment;
24import com.google.common.collect.ImmutableSet;
25
26import org.junit.Test;
27import org.junit.runner.RunWith;
28import org.junit.runners.JUnit4;
29
30/**
31 * Tests {@link BenchmarkClass}.
32 */
33@RunWith(JUnit4.class)
34public class BenchmarkClassTest {
35 @Test public void beforeMeasurementMethods_AnnotatedBenchmark() throws Exception {
36 assertEquals(
37 ImmutableSet.of(
38 MyBenchmark.class.getDeclaredMethod("before1"),
39 MyBenchmark.class.getDeclaredMethod("before2")),
40 BenchmarkClass.forClass(MyBenchmark.class).beforeExperimentMethods());
41 }
42
43 @Test public void afterMeasurementMethods_AnnotatedBenchmark() throws Exception {
44 assertEquals(
45 ImmutableSet.of(
46 MyBenchmark.class.getDeclaredMethod("after1"),
47 MyBenchmark.class.getDeclaredMethod("after2")),
48 BenchmarkClass.forClass(MyBenchmark.class).afterExperimentMethods());
49 }
50
51 @Test public void forClass_inheritenceThrows() throws Exception {
52 try {
53 BenchmarkClass.forClass(MalformedBenhcmark.class);
54 fail();
55 } catch (InvalidBenchmarkException expected) {}
56 }
57
58 static class MyBenchmark {
59 @BeforeExperiment void before1() {}
60 @BeforeExperiment void before2() {}
61 @AfterExperiment void after1() {}
62 @AfterExperiment void after2() {}
63 }
64
65 static class MalformedBenhcmark extends MyBenchmark {}
66}