Home | History | Annotate | Download | only in runner
      1 /*
      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 
     17 package com.google.caliper.runner;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 
     21 import com.google.caliper.model.ArbitraryMeasurement;
     22 import com.google.caliper.model.Measurement;
     23 import com.google.caliper.model.Value;
     24 import com.google.common.collect.Iterables;
     25 
     26 import org.junit.Rule;
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 import org.junit.runners.JUnit4;
     30 
     31 /**
     32  * Integration tests for the {@link ArbitraryMeasurementInstrument}
     33  */
     34 @RunWith(JUnit4.class)
     35 public class ArbitraryMeasurmentInstrumentTest {
     36   @Rule public CaliperTestWatcher runner = new CaliperTestWatcher();
     37 
     38   @Test
     39 
     40   public void testSuccess() throws Exception {
     41     runner.forBenchmark(TestBenchmark.class)
     42         .instrument("arbitrary")
     43         .run();
     44     Measurement measurement = Iterables.getOnlyElement(
     45         Iterables.getOnlyElement(runner.trials()).measurements());
     46     Measurement expected = new Measurement.Builder()
     47         .description("fake measurment")
     48         .weight(1)
     49         .value(Value.create(1.0, "hz"))
     50         .build();
     51     assertEquals(expected, measurement);
     52   }
     53 
     54   public static class TestBenchmark {
     55     @ArbitraryMeasurement(units = "hz", description = "fake measurment")
     56     public double compressionSize() {
     57       return 1.0;
     58     }
     59   }
     60 }
     61