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 com.google.common.base.Preconditions.checkState; 20 21 import com.google.caliper.api.ResultProcessor; 22 import com.google.caliper.model.Trial; 23 import com.google.common.collect.ImmutableList; 24 import com.google.common.collect.Lists; 25 26 import java.io.IOException; 27 import java.util.List; 28 29 import javax.inject.Inject; 30 31 /** 32 * A {@link ResultProcessor} that collects all trials in a static list for easy inspection by tests. 33 */ 34 public class InMemoryResultsUploader implements ResultProcessor { 35 static ImmutableList<Trial> trials() { 36 return ImmutableList.copyOf(trials); 37 } 38 39 private static List<Trial> trials; 40 private boolean isClosed; 41 42 @Inject public InMemoryResultsUploader() { 43 trials = Lists.newArrayList(); 44 } 45 46 @Override public void close() throws IOException { 47 checkState(!isClosed); 48 isClosed = true; 49 } 50 51 @Override public void processTrial(Trial trial) { 52 checkState(!isClosed); 53 trials.add(trial); 54 } 55 }