Line data Source code
1 : // Copyright (C) 2016 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.extensions.common.testing; 16 : 17 : import static com.google.common.truth.Truth.assertAbout; 18 : import static com.google.gerrit.truth.ListSubject.elements; 19 : 20 : import com.google.common.truth.FailureMetadata; 21 : import com.google.common.truth.MapSubject; 22 : import com.google.common.truth.StringSubject; 23 : import com.google.common.truth.Subject; 24 : import com.google.gerrit.extensions.common.FixSuggestionInfo; 25 : import com.google.gerrit.extensions.common.RobotCommentInfo; 26 : import com.google.gerrit.truth.ListSubject; 27 : import java.util.List; 28 : 29 : public class RobotCommentInfoSubject extends Subject { 30 : 31 : public static ListSubject<RobotCommentInfoSubject, RobotCommentInfo> assertThatList( 32 : List<RobotCommentInfo> robotCommentInfos) { 33 3 : return ListSubject.assertThat(robotCommentInfos, robotComments()); 34 : } 35 : 36 : public static RobotCommentInfoSubject assertThat(RobotCommentInfo robotCommentInfo) { 37 1 : return assertAbout(robotComments()).that(robotCommentInfo); 38 : } 39 : 40 : private static Factory<RobotCommentInfoSubject, RobotCommentInfo> robotComments() { 41 3 : return RobotCommentInfoSubject::new; 42 : } 43 : 44 : private final RobotCommentInfo robotCommentInfo; 45 : 46 : private RobotCommentInfoSubject( 47 : FailureMetadata failureMetadata, RobotCommentInfo robotCommentInfo) { 48 2 : super(failureMetadata, robotCommentInfo); 49 2 : this.robotCommentInfo = robotCommentInfo; 50 2 : } 51 : 52 : public ListSubject<FixSuggestionInfoSubject, FixSuggestionInfo> fixSuggestions() { 53 1 : return check("fixSuggestions") 54 1 : .about(elements()) 55 1 : .thatCustom(robotCommentInfo.fixSuggestions, FixSuggestionInfoSubject.fixSuggestions()); 56 : } 57 : 58 : public StringSubject path() { 59 1 : isNotNull(); 60 1 : return check("path").that(robotCommentInfo.path); 61 : } 62 : 63 : public StringSubject robotId() { 64 1 : isNotNull(); 65 1 : return check("robotId").that(robotCommentInfo.robotId); 66 : } 67 : 68 : public StringSubject robotRunId() { 69 0 : isNotNull(); 70 0 : return check("robotRunId").that(robotCommentInfo.robotRunId); 71 : } 72 : 73 : public StringSubject url() { 74 1 : isNotNull(); 75 1 : return check("url").that(robotCommentInfo.url); 76 : } 77 : 78 : public MapSubject properties() { 79 1 : isNotNull(); 80 1 : return check("property").that(robotCommentInfo.properties); 81 : } 82 : 83 : public FixSuggestionInfoSubject onlyFixSuggestion() { 84 1 : return fixSuggestions().onlyElement(); 85 : } 86 : }