Line data Source code
1 : // Copyright (C) 2017 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.extensions.common.testing.CommitInfoSubject.commits; 19 : import static com.google.gerrit.truth.MapSubject.mapEntries; 20 : 21 : import com.google.common.truth.FailureMetadata; 22 : import com.google.common.truth.StringSubject; 23 : import com.google.common.truth.Subject; 24 : import com.google.gerrit.extensions.common.EditInfo; 25 : import com.google.gerrit.truth.MapSubject; 26 : import com.google.gerrit.truth.OptionalSubject; 27 : import java.util.Optional; 28 : 29 : public class EditInfoSubject extends Subject { 30 : 31 : public static EditInfoSubject assertThat(EditInfo editInfo) { 32 3 : return assertAbout(edits()).that(editInfo); 33 : } 34 : 35 : private static Subject.Factory<EditInfoSubject, EditInfo> edits() { 36 7 : return EditInfoSubject::new; 37 : } 38 : 39 : public static OptionalSubject<EditInfoSubject, EditInfo> assertThat( 40 : Optional<EditInfo> editInfoOptional) { 41 7 : return OptionalSubject.assertThat(editInfoOptional, edits()); 42 : } 43 : 44 : private final EditInfo editInfo; 45 : 46 : private EditInfoSubject(FailureMetadata failureMetadata, EditInfo editInfo) { 47 3 : super(failureMetadata, editInfo); 48 3 : this.editInfo = editInfo; 49 3 : } 50 : 51 : public CommitInfoSubject commit() { 52 3 : isNotNull(); 53 3 : return check("commit").about(commits()).that(editInfo.commit); 54 : } 55 : 56 : public StringSubject baseRevision() { 57 3 : isNotNull(); 58 3 : return check("baseRevision").that(editInfo.baseRevision); 59 : } 60 : 61 : public MapSubject files() { 62 1 : isNotNull(); 63 1 : return check("files").about(mapEntries()).that(editInfo.files); 64 : } 65 : }