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.server.group.testing; 16 : 17 : import static com.google.common.truth.Truth.assertAbout; 18 : 19 : import com.google.common.truth.BooleanSubject; 20 : import com.google.common.truth.ComparableSubject; 21 : import com.google.common.truth.FailureMetadata; 22 : import com.google.common.truth.IterableSubject; 23 : import com.google.common.truth.StringSubject; 24 : import com.google.common.truth.Subject; 25 : import com.google.gerrit.entities.AccountGroup; 26 : import com.google.gerrit.entities.InternalGroup; 27 : import java.time.Instant; 28 : import org.eclipse.jgit.lib.ObjectId; 29 : 30 : public class InternalGroupSubject extends Subject { 31 : 32 : public static InternalGroupSubject assertThat(InternalGroup group) { 33 0 : return assertAbout(internalGroups()).that(group); 34 : } 35 : 36 : public static Subject.Factory<InternalGroupSubject, InternalGroup> internalGroups() { 37 2 : return InternalGroupSubject::new; 38 : } 39 : 40 : private final InternalGroup group; 41 : 42 : private InternalGroupSubject(FailureMetadata metadata, InternalGroup group) { 43 2 : super(metadata, group); 44 2 : this.group = group; 45 2 : } 46 : 47 : public ComparableSubject<AccountGroup.UUID> groupUuid() { 48 2 : isNotNull(); 49 2 : return check("getGroupUUID()").that(group.getGroupUUID()); 50 : } 51 : 52 : public ComparableSubject<AccountGroup.NameKey> nameKey() { 53 1 : isNotNull(); 54 1 : return check("getNameKey()").that(group.getNameKey()); 55 : } 56 : 57 : public StringSubject name() { 58 1 : isNotNull(); 59 1 : return check("getName()").that(group.getName()); 60 : } 61 : 62 : public Subject id() { 63 1 : isNotNull(); 64 1 : return check("getId()").that(group.getId()); 65 : } 66 : 67 : public StringSubject description() { 68 2 : isNotNull(); 69 2 : return check("getDescription()").that(group.getDescription()); 70 : } 71 : 72 : public ComparableSubject<AccountGroup.UUID> ownerGroupUuid() { 73 1 : isNotNull(); 74 1 : return check("getOwnerGroupUUID()").that(group.getOwnerGroupUUID()); 75 : } 76 : 77 : public BooleanSubject visibleToAll() { 78 1 : isNotNull(); 79 1 : return check("isVisibleToAll()").that(group.isVisibleToAll()); 80 : } 81 : 82 : public ComparableSubject<Instant> createdOn() { 83 1 : isNotNull(); 84 1 : return check("getCreatedOn()").that(group.getCreatedOn()); 85 : } 86 : 87 : public IterableSubject members() { 88 1 : isNotNull(); 89 1 : return check("getMembers()").that(group.getMembers()); 90 : } 91 : 92 : public IterableSubject subgroups() { 93 1 : isNotNull(); 94 1 : return check("getSubgroups()").that(group.getSubgroups()); 95 : } 96 : 97 : public ComparableSubject<ObjectId> refState() { 98 1 : isNotNull(); 99 1 : return check("getRefState()").that(group.getRefState()); 100 : } 101 : }