Add tests for GroupConfig
Change-Id: Id3810e02fa2dc545d0e8f3a3a5fda107d43f1bab
This commit is contained in:
@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkState;
|
|||||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||||
import static java.util.stream.Collectors.joining;
|
import static java.util.stream.Collectors.joining;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
@@ -60,15 +61,14 @@ import org.eclipse.jgit.revwalk.RevSort;
|
|||||||
* <p>TODO(aliceks): expand docs.
|
* <p>TODO(aliceks): expand docs.
|
||||||
*/
|
*/
|
||||||
public class GroupConfig extends VersionedMetaData {
|
public class GroupConfig extends VersionedMetaData {
|
||||||
public static final String GROUP_CONFIG_FILE = "group.config";
|
|
||||||
|
|
||||||
static final FooterKey FOOTER_ADD_MEMBER = new FooterKey("Add");
|
static final FooterKey FOOTER_ADD_MEMBER = new FooterKey("Add");
|
||||||
static final FooterKey FOOTER_REMOVE_MEMBER = new FooterKey("Remove");
|
static final FooterKey FOOTER_REMOVE_MEMBER = new FooterKey("Remove");
|
||||||
static final FooterKey FOOTER_ADD_GROUP = new FooterKey("Add-group");
|
static final FooterKey FOOTER_ADD_GROUP = new FooterKey("Add-group");
|
||||||
static final FooterKey FOOTER_REMOVE_GROUP = new FooterKey("Remove-group");
|
static final FooterKey FOOTER_REMOVE_GROUP = new FooterKey("Remove-group");
|
||||||
|
|
||||||
private static final String MEMBERS_FILE = "members";
|
@VisibleForTesting public static final String GROUP_CONFIG_FILE = "group.config";
|
||||||
private static final String SUBGROUPS_FILE = "subgroups";
|
@VisibleForTesting static final String MEMBERS_FILE = "members";
|
||||||
|
@VisibleForTesting static final String SUBGROUPS_FILE = "subgroups";
|
||||||
private static final Pattern LINE_SEPARATOR_PATTERN = Pattern.compile("\\R");
|
private static final Pattern LINE_SEPARATOR_PATTERN = Pattern.compile("\\R");
|
||||||
|
|
||||||
private final AccountGroup.UUID groupUuid;
|
private final AccountGroup.UUID groupUuid;
|
||||||
|
|||||||
13
java/com/google/gerrit/server/group/testing/BUILD
Normal file
13
java/com/google/gerrit/server/group/testing/BUILD
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
|
java_library(
|
||||||
|
name = "testing",
|
||||||
|
testonly = 1,
|
||||||
|
srcs = glob(["*.java"]),
|
||||||
|
deps = [
|
||||||
|
"//java/com/google/gerrit/reviewdb:server",
|
||||||
|
"//java/com/google/gerrit/server",
|
||||||
|
"//lib:truth",
|
||||||
|
"//lib/jgit/org.eclipse.jgit:jgit",
|
||||||
|
],
|
||||||
|
)
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
// Copyright (C) 2017 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.server.group.testing;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertAbout;
|
||||||
|
|
||||||
|
import com.google.common.truth.BooleanSubject;
|
||||||
|
import com.google.common.truth.ComparableSubject;
|
||||||
|
import com.google.common.truth.DefaultSubject;
|
||||||
|
import com.google.common.truth.FailureMetadata;
|
||||||
|
import com.google.common.truth.IterableSubject;
|
||||||
|
import com.google.common.truth.StringSubject;
|
||||||
|
import com.google.common.truth.Subject;
|
||||||
|
import com.google.common.truth.Truth;
|
||||||
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
|
import com.google.gerrit.server.group.InternalGroup;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
|
||||||
|
public class InternalGroupSubject extends Subject<InternalGroupSubject, InternalGroup> {
|
||||||
|
|
||||||
|
public static InternalGroupSubject assertThat(InternalGroup group) {
|
||||||
|
return assertAbout(InternalGroupSubject::new).that(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InternalGroupSubject(FailureMetadata metadata, InternalGroup actual) {
|
||||||
|
super(metadata, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComparableSubject<?, AccountGroup.UUID> groupUuid() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getGroupUUID()).named("groupUuid");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComparableSubject<?, AccountGroup.NameKey> nameKey() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getNameKey()).named("nameKey");
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringSubject name() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getName()).named("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultSubject id() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getId()).named("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringSubject description() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getDescription()).named("description");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComparableSubject<?, AccountGroup.UUID> ownerGroupUuid() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getOwnerGroupUUID()).named("ownerGroupUuid");
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanSubject visibleToAll() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.isVisibleToAll()).named("visibleToAll");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComparableSubject<?, Timestamp> createdOn() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getCreatedOn()).named("createdOn");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IterableSubject members() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getMembers()).named("members");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IterableSubject subgroups() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getSubgroups()).named("subgroups");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComparableSubject<?, ObjectId> refState() {
|
||||||
|
isNotNull();
|
||||||
|
InternalGroup group = actual();
|
||||||
|
return Truth.assertThat(group.getRefState()).named("refState");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ junit_tests(
|
|||||||
"//java/com/google/gerrit/reviewdb:server",
|
"//java/com/google/gerrit/reviewdb:server",
|
||||||
"//java/com/google/gerrit/server",
|
"//java/com/google/gerrit/server",
|
||||||
"//java/com/google/gerrit/server/group/db/testing",
|
"//java/com/google/gerrit/server/group/db/testing",
|
||||||
|
"//java/com/google/gerrit/server/group/testing",
|
||||||
"//java/com/google/gerrit/testing:gerrit-test-util",
|
"//java/com/google/gerrit/testing:gerrit-test-util",
|
||||||
"//java/com/google/gerrit/truth",
|
"//java/com/google/gerrit/truth",
|
||||||
"//lib:gwtorm",
|
"//lib:gwtorm",
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user