Line data Source code
1 : // Copyright (C) 2020 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 : package com.google.gerrit.extensions.restapi.testing; 15 : 16 : import static com.google.common.truth.Truth.assertAbout; 17 : 18 : import com.google.common.truth.ComparableSubject; 19 : import com.google.common.truth.FailureMetadata; 20 : import com.google.common.truth.StringSubject; 21 : import com.google.common.truth.Subject; 22 : import com.google.gerrit.entities.Account; 23 : import com.google.gerrit.entities.AttentionSetUpdate; 24 : 25 : /** {@link Subject} for doing assertions on {@link AttentionSetUpdate}s. */ 26 : public class AttentionSetUpdateSubject extends Subject { 27 : 28 : /** 29 : * Starts fluent chain to do assertions on a {@link AttentionSetUpdate}. 30 : * 31 : * @param attentionSetUpdate the {@link AttentionSetUpdate} on which assertions should be done 32 : * @return the created {@link AttentionSetUpdateSubject} 33 : */ 34 : public static AttentionSetUpdateSubject assertThat(AttentionSetUpdate attentionSetUpdate) { 35 4 : return assertAbout(attentionSetUpdates()).that(attentionSetUpdate); 36 : } 37 : 38 : private static Factory<AttentionSetUpdateSubject, AttentionSetUpdate> attentionSetUpdates() { 39 4 : return AttentionSetUpdateSubject::new; 40 : } 41 : 42 : private final AttentionSetUpdate attentionSetUpdate; 43 : 44 : private AttentionSetUpdateSubject( 45 : FailureMetadata metadata, AttentionSetUpdate attentionSetUpdate) { 46 4 : super(metadata, attentionSetUpdate); 47 4 : this.attentionSetUpdate = attentionSetUpdate; 48 4 : } 49 : 50 : /** 51 : * Returns a {@link ComparableSubject} for the account ID of attention set update. 52 : * 53 : * @return {@link ComparableSubject} for the account ID of attention set update 54 : */ 55 : public ComparableSubject<Account.Id> hasAccountIdThat() { 56 4 : return check("account()").that(attentionSetUpdate().account()); 57 : } 58 : 59 : /** 60 : * Returns a {@link StringSubject} for the reason of attention set update. 61 : * 62 : * @return {@link StringSubject} for the reason of attention set update 63 : */ 64 : public StringSubject hasReasonThat() { 65 4 : return check("reason()").that(attentionSetUpdate().reason()); 66 : } 67 : 68 : /** 69 : * Returns a {@link ComparableSubject} for the {@link 70 : * com.google.gerrit.entities.AttentionSetUpdate.Operation} of attention set update. 71 : * 72 : * @return {@link ComparableSubject} for the {@link 73 : * com.google.gerrit.entities.AttentionSetUpdate.Operation} of attention set update. 74 : */ 75 : public ComparableSubject<AttentionSetUpdate.Operation> hasOperationThat() { 76 4 : return check("operation()").that(attentionSetUpdate().operation()); 77 : } 78 : 79 : private AttentionSetUpdate attentionSetUpdate() { 80 4 : isNotNull(); 81 4 : return attentionSetUpdate; 82 : } 83 : }