blob: 075a6e2ea70f1aee27bf6f93ca82a6b308c222ee [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 com.google.common.base.Preconditions.checkState;
20
21import com.google.caliper.api.ResultProcessor;
22import com.google.caliper.model.Trial;
23import com.google.common.collect.ImmutableList;
24import com.google.common.collect.Lists;
25
26import java.io.IOException;
27import java.util.List;
28
29import javax.inject.Inject;
30
31/**
32 * A {@link ResultProcessor} that collects all trials in a static list for easy inspection by tests.
33 */
34public 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}