Dissolve gerrit-test-util top-level directory

Change-Id: I3be9943f8eb9c0b125bea49660b38eea467f0240
This commit is contained in:
David Ostrovsky
2017-08-16 22:57:54 +02:00
committed by Dave Borowitz
parent 8753cc2c3d
commit 594d1854cc
20 changed files with 17 additions and 6 deletions

View File

@@ -0,0 +1,11 @@
java_library(
name = "extensions",
testonly = 1,
srcs = glob(["**/*.java"]),
visibility = ["//visibility:public"],
deps = [
"//gerrit-extension-api:api",
"//java/com/google/gerrit/truth",
"//lib:truth",
],
)

View File

@@ -0,0 +1,63 @@
// Copyright (C) 2016 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.extensions.client;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.IntegerSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
public class RangeSubject extends Subject<RangeSubject, Comment.Range> {
public static RangeSubject assertThat(Comment.Range range) {
return assertAbout(RangeSubject::new).that(range);
}
private RangeSubject(FailureMetadata failureMetadata, Comment.Range range) {
super(failureMetadata, range);
}
public IntegerSubject startLine() {
return Truth.assertThat(actual().startLine).named("startLine");
}
public IntegerSubject startCharacter() {
return Truth.assertThat(actual().startCharacter).named("startCharacter");
}
public IntegerSubject endLine() {
return Truth.assertThat(actual().endLine).named("endLine");
}
public IntegerSubject endCharacter() {
return Truth.assertThat(actual().endCharacter).named("endCharacter");
}
public void isValid() {
isNotNull();
if (!actual().isValid()) {
fail("is valid");
}
}
public void isInvalid() {
isNotNull();
if (actual().isValid()) {
fail("is invalid");
}
}
}

View File

@@ -0,0 +1,53 @@
// 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import com.google.gerrit.truth.ListSubject;
public class CommitInfoSubject extends Subject<CommitInfoSubject, CommitInfo> {
public static CommitInfoSubject assertThat(CommitInfo commitInfo) {
return assertAbout(CommitInfoSubject::new).that(commitInfo);
}
private CommitInfoSubject(FailureMetadata failureMetadata, CommitInfo commitInfo) {
super(failureMetadata, commitInfo);
}
public StringSubject commit() {
isNotNull();
CommitInfo commitInfo = actual();
return Truth.assertThat(commitInfo.commit).named("commit");
}
public ListSubject<CommitInfoSubject, CommitInfo> parents() {
isNotNull();
CommitInfo commitInfo = actual();
return ListSubject.assertThat(commitInfo.parents, CommitInfoSubject::assertThat)
.named("parents");
}
public GitPersonSubject committer() {
isNotNull();
CommitInfo commitInfo = actual();
return GitPersonSubject.assertThat(commitInfo.committer).named("committer");
}
}

View File

@@ -0,0 +1,71 @@
// 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import com.google.gerrit.extensions.common.DiffInfo.ContentEntry;
import com.google.gerrit.truth.ListSubject;
public class ContentEntrySubject extends Subject<ContentEntrySubject, ContentEntry> {
public static ContentEntrySubject assertThat(ContentEntry contentEntry) {
return assertAbout(ContentEntrySubject::new).that(contentEntry);
}
private ContentEntrySubject(FailureMetadata failureMetadata, ContentEntry contentEntry) {
super(failureMetadata, contentEntry);
}
public void isDueToRebase() {
isNotNull();
ContentEntry contentEntry = actual();
Truth.assertWithMessage("Entry should be marked 'dueToRebase'")
.that(contentEntry.dueToRebase)
.named("dueToRebase")
.isTrue();
}
public void isNotDueToRebase() {
isNotNull();
ContentEntry contentEntry = actual();
Truth.assertWithMessage("Entry should not be marked 'dueToRebase'")
.that(contentEntry.dueToRebase)
.named("dueToRebase")
.isNull();
}
public ListSubject<StringSubject, String> commonLines() {
isNotNull();
ContentEntry contentEntry = actual();
return ListSubject.assertThat(contentEntry.ab, Truth::assertThat).named("common lines");
}
public ListSubject<StringSubject, String> linesOfA() {
isNotNull();
ContentEntry contentEntry = actual();
return ListSubject.assertThat(contentEntry.a, Truth::assertThat).named("lines of 'a'");
}
public ListSubject<StringSubject, String> linesOfB() {
isNotNull();
ContentEntry contentEntry = actual();
return ListSubject.assertThat(contentEntry.b, Truth::assertThat).named("lines of 'b'");
}
}

View File

@@ -0,0 +1,48 @@
// 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.ComparableSubject;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import com.google.gerrit.extensions.common.DiffInfo.ContentEntry;
import com.google.gerrit.truth.ListSubject;
public class DiffInfoSubject extends Subject<DiffInfoSubject, DiffInfo> {
public static DiffInfoSubject assertThat(DiffInfo diffInfo) {
return assertAbout(DiffInfoSubject::new).that(diffInfo);
}
private DiffInfoSubject(FailureMetadata failureMetadata, DiffInfo diffInfo) {
super(failureMetadata, diffInfo);
}
public ListSubject<ContentEntrySubject, ContentEntry> content() {
isNotNull();
DiffInfo diffInfo = actual();
return ListSubject.assertThat(diffInfo.content, ContentEntrySubject::assertThat)
.named("content");
}
public ComparableSubject<?, ChangeType> changeType() {
isNotNull();
DiffInfo diffInfo = actual();
return Truth.assertThat(diffInfo.changeType).named("changeType");
}
}

View File

@@ -0,0 +1,52 @@
// 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import com.google.gerrit.truth.OptionalSubject;
import java.util.Optional;
public class EditInfoSubject extends Subject<EditInfoSubject, EditInfo> {
public static EditInfoSubject assertThat(EditInfo editInfo) {
return assertAbout(EditInfoSubject::new).that(editInfo);
}
public static OptionalSubject<EditInfoSubject, EditInfo> assertThat(
Optional<EditInfo> editInfoOptional) {
return OptionalSubject.assertThat(editInfoOptional, EditInfoSubject::assertThat);
}
private EditInfoSubject(FailureMetadata failureMetadata, EditInfo editInfo) {
super(failureMetadata, editInfo);
}
public CommitInfoSubject commit() {
isNotNull();
EditInfo editInfo = actual();
return CommitInfoSubject.assertThat(editInfo.commit).named("commit");
}
public StringSubject baseRevision() {
isNotNull();
EditInfo editInfo = actual();
return Truth.assertThat(editInfo.baseRevision).named("baseRevision");
}
}

View File

@@ -0,0 +1,52 @@
// 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.ComparableSubject;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.IntegerSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
public class FileInfoSubject extends Subject<FileInfoSubject, FileInfo> {
public static FileInfoSubject assertThat(FileInfo fileInfo) {
return assertAbout(FileInfoSubject::new).that(fileInfo);
}
private FileInfoSubject(FailureMetadata failureMetadata, FileInfo fileInfo) {
super(failureMetadata, fileInfo);
}
public IntegerSubject linesInserted() {
isNotNull();
FileInfo fileInfo = actual();
return Truth.assertThat(fileInfo.linesInserted).named("linesInserted");
}
public IntegerSubject linesDeleted() {
isNotNull();
FileInfo fileInfo = actual();
return Truth.assertThat(fileInfo.linesDeleted).named("linesDeleted");
}
public ComparableSubject<?, Character> status() {
isNotNull();
FileInfo fileInfo = actual();
return Truth.assertThat(fileInfo.status).named("status");
}
}

View File

@@ -0,0 +1,48 @@
// Copyright (C) 2016 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import com.google.gerrit.extensions.client.RangeSubject;
public class FixReplacementInfoSubject
extends Subject<FixReplacementInfoSubject, FixReplacementInfo> {
public static FixReplacementInfoSubject assertThat(FixReplacementInfo fixReplacementInfo) {
return assertAbout(FixReplacementInfoSubject::new).that(fixReplacementInfo);
}
private FixReplacementInfoSubject(
FailureMetadata failureMetadata, FixReplacementInfo fixReplacementInfo) {
super(failureMetadata, fixReplacementInfo);
}
public StringSubject path() {
return Truth.assertThat(actual().path).named("path");
}
public RangeSubject range() {
return RangeSubject.assertThat(actual().range).named("range");
}
public StringSubject replacement() {
return Truth.assertThat(actual().replacement).named("replacement");
}
}

View File

@@ -0,0 +1,52 @@
// Copyright (C) 2016 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import com.google.gerrit.truth.ListSubject;
public class FixSuggestionInfoSubject extends Subject<FixSuggestionInfoSubject, FixSuggestionInfo> {
public static FixSuggestionInfoSubject assertThat(FixSuggestionInfo fixSuggestionInfo) {
return assertAbout(FixSuggestionInfoSubject::new).that(fixSuggestionInfo);
}
private FixSuggestionInfoSubject(
FailureMetadata failureMetadata, FixSuggestionInfo fixSuggestionInfo) {
super(failureMetadata, fixSuggestionInfo);
}
public StringSubject fixId() {
return Truth.assertThat(actual().fixId).named("fixId");
}
public ListSubject<FixReplacementInfoSubject, FixReplacementInfo> replacements() {
return ListSubject.assertThat(actual().replacements, FixReplacementInfoSubject::assertThat)
.named("replacements");
}
public FixReplacementInfoSubject onlyReplacement() {
return replacements().onlyElement();
}
public StringSubject description() {
return Truth.assertThat(actual().description).named("description");
}
}

View File

@@ -0,0 +1,40 @@
// 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.ComparableSubject;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import java.sql.Timestamp;
public class GitPersonSubject extends Subject<GitPersonSubject, GitPerson> {
public static GitPersonSubject assertThat(GitPerson gitPerson) {
return assertAbout(GitPersonSubject::new).that(gitPerson);
}
private GitPersonSubject(FailureMetadata failureMetadata, GitPerson gitPerson) {
super(failureMetadata, gitPerson);
}
public ComparableSubject<?, Timestamp> creationDate() {
isNotNull();
GitPerson gitPerson = actual();
return Truth.assertThat(gitPerson.date).named("creationDate");
}
}

View File

@@ -0,0 +1,31 @@
// 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import java.nio.file.Path;
public class PathSubject extends Subject<PathSubject, Path> {
private PathSubject(FailureMetadata failureMetadata, Path path) {
super(failureMetadata, path);
}
public static PathSubject assertThat(Path path) {
return assertAbout(PathSubject::new).that(path);
}
}

View File

@@ -0,0 +1,49 @@
// Copyright (C) 2016 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.extensions.common;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import com.google.gerrit.truth.ListSubject;
import java.util.List;
public class RobotCommentInfoSubject extends Subject<RobotCommentInfoSubject, RobotCommentInfo> {
public static ListSubject<RobotCommentInfoSubject, RobotCommentInfo> assertThatList(
List<RobotCommentInfo> robotCommentInfos) {
return ListSubject.assertThat(robotCommentInfos, RobotCommentInfoSubject::assertThat)
.named("robotCommentInfos");
}
public static RobotCommentInfoSubject assertThat(RobotCommentInfo robotCommentInfo) {
return assertAbout(RobotCommentInfoSubject::new).that(robotCommentInfo);
}
private RobotCommentInfoSubject(
FailureMetadata failureMetadata, RobotCommentInfo robotCommentInfo) {
super(failureMetadata, robotCommentInfo);
}
public ListSubject<FixSuggestionInfoSubject, FixSuggestionInfo> fixSuggestions() {
return ListSubject.assertThat(actual().fixSuggestions, FixSuggestionInfoSubject::assertThat)
.named("fixSuggestions");
}
public FixSuggestionInfoSubject onlyFixSuggestion() {
return fixSuggestions().onlyElement();
}
}

View File

@@ -0,0 +1,64 @@
// 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.extensions.restapi;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.PrimitiveByteArraySubject;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import com.google.gerrit.truth.OptionalSubject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Optional;
public class BinaryResultSubject extends Subject<BinaryResultSubject, BinaryResult> {
public static BinaryResultSubject assertThat(BinaryResult binaryResult) {
return assertAbout(BinaryResultSubject::new).that(binaryResult);
}
public static OptionalSubject<BinaryResultSubject, BinaryResult> assertThat(
Optional<BinaryResult> binaryResultOptional) {
return OptionalSubject.assertThat(binaryResultOptional, BinaryResultSubject::assertThat);
}
private BinaryResultSubject(FailureMetadata failureMetadata, BinaryResult binaryResult) {
super(failureMetadata, binaryResult);
}
public StringSubject asString() throws IOException {
isNotNull();
// We shouldn't close the BinaryResult within this method as it might still
// be used afterwards. Besides, closing it doesn't have an effect for most
// implementations of a BinaryResult.
BinaryResult binaryResult = actual();
return Truth.assertThat(binaryResult.asString());
}
public PrimitiveByteArraySubject bytes() throws IOException {
isNotNull();
// We shouldn't close the BinaryResult within this method as it might still
// be used afterwards. Besides, closing it doesn't have an effect for most
// implementations of a BinaryResult.
BinaryResult binaryResult = actual();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
binaryResult.writeTo(byteArrayOutputStream);
byte[] bytes = byteArrayOutputStream.toByteArray();
return Truth.assertThat(bytes);
}
}