|
| 1 | +/* |
| 2 | + * Copyright 2018 Google LLC. |
| 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.cloud.tools.opensource.cloudbomdashboard; |
| 18 | + |
| 19 | +import java.util.HashMap; |
| 20 | +import java.util.Map; |
| 21 | + |
| 22 | +import javax.annotation.Nullable; |
| 23 | + |
| 24 | +import org.eclipse.aether.artifact.Artifact; |
| 25 | + |
| 26 | +import com.google.cloud.tools.opensource.dependencies.Artifacts; |
| 27 | + |
| 28 | +/** |
| 29 | + * Collection of test results for a single artifact. |
| 30 | + */ |
| 31 | +public final class ArtifactResults { |
| 32 | + |
| 33 | + private final Map<String, Integer> results = new HashMap<>(); |
| 34 | + private final Artifact artifact; |
| 35 | + private String exceptionMessage; |
| 36 | + |
| 37 | + public ArtifactResults(Artifact artifact) { |
| 38 | + this.artifact = artifact; |
| 39 | + } |
| 40 | + |
| 41 | + public void setExceptionMessage(String exceptionMessage) { |
| 42 | + this.exceptionMessage = exceptionMessage; |
| 43 | + } |
| 44 | + |
| 45 | + void addResult(String testName, int failures) { |
| 46 | + results.put(testName, failures); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @return true for pass, false for fail, null for unknown test |
| 51 | + */ |
| 52 | + @Nullable |
| 53 | + public Boolean getResult(String testName) { |
| 54 | + Integer failures = results.get(testName); |
| 55 | + if (failures != null) { |
| 56 | + return failures == 0; |
| 57 | + } |
| 58 | + return null; |
| 59 | + } |
| 60 | + |
| 61 | + public String getCoordinates() { |
| 62 | + return Artifacts.toCoordinates(artifact); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @return message of exception occurred when running test, null for no exception |
| 67 | + */ |
| 68 | + @Nullable |
| 69 | + public String getExceptionMessage() { |
| 70 | + return exceptionMessage; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * |
| 75 | + * @return number of times the specified test failed. Returns 0 |
| 76 | + * if the test was not run. |
| 77 | + */ |
| 78 | + public int getFailureCount(String testName) { |
| 79 | + Integer failures = results.get(testName); |
| 80 | + if (failures == null) { |
| 81 | + return 0; |
| 82 | + } |
| 83 | + return failures; |
| 84 | + } |
| 85 | +} |
0 commit comments