Skip to content

Commit

Permalink
Use Truth instead of Truth8, and resume using static imports.
Browse files Browse the repository at this point in the history
As of Truth 1.4.2, we can use static imports again.

This largely reverts commits cbed17a
and 3f2a11b.

This is the last Gerrit-related loose end that I know of from
google/truth#746, aside from the deprecated
automerger plugin:
https://gerrit-review.git.corp.google.com/c/plugins/automerger/+/406837

Change-Id: I9dda0e4f8825e1e635f07c786dba0951414d9eb4
  • Loading branch information
cpovirk committed Mar 14, 2024
1 parent 004aceb commit 83d8116
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION;
import static com.google.gerrit.plugins.codeowners.testing.RequiredApprovalSubject.assertThat;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static com.google.gerrit.truth.OptionalSubject.assertThat;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All @@ -45,7 +46,6 @@
import com.google.gerrit.plugins.codeowners.backend.config.StatusConfig;
import com.google.gerrit.plugins.codeowners.backend.proto.ProtoBackend;
import com.google.gerrit.plugins.codeowners.common.MergeCommitStrategy;
import com.google.gerrit.truth.OptionalSubject;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
Expand Down Expand Up @@ -257,8 +257,7 @@ public void configurePathExpressionsForProject() throws Exception {

PushResult r = pushRefsMetaConfig();
assertThat(r.getRemoteUpdate(RefNames.REFS_CONFIG).getStatus()).isEqualTo(Status.OK);
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getPathExpressions("master"))
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getPathExpressions("master"))
.value()
.isEqualTo(PathExpressions.GLOB);
}
Expand All @@ -277,8 +276,7 @@ public void configurePathExpressionsForBranch() throws Exception {

PushResult r = pushRefsMetaConfig();
assertThat(r.getRemoteUpdate(RefNames.REFS_CONFIG).getStatus()).isEqualTo(Status.OK);
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getPathExpressions("master"))
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getPathExpressions("master"))
.value()
.isEqualTo(PathExpressions.GLOB);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.gerrit.plugins.codeowners.testing.RequiredApprovalSubject.assertThat;
import static com.google.gerrit.server.project.ProjectCache.illegalState;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static com.google.gerrit.truth.OptionalSubject.assertThat;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All @@ -43,7 +44,6 @@
import com.google.gerrit.plugins.codeowners.common.MergeCommitStrategy;
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.restapi.project.DeleteRef;
import com.google.gerrit.truth.OptionalSubject;
import com.google.inject.Inject;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before;
Expand Down Expand Up @@ -181,25 +181,22 @@ public void cannotSetInvalidDisabledBranch() throws Exception {

@Test
public void setFileExtension() throws Exception {
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getFileExtension())
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getFileExtension())
.isEmpty();

CodeOwnerProjectConfigInput input = new CodeOwnerProjectConfigInput();
input.fileExtension = "foo";
CodeOwnerProjectConfigInfo updatedConfig =
projectCodeOwnersApiFactory.project(project).updateConfig(input);
assertThat(updatedConfig.general.fileExtension).isEqualTo("foo");
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getFileExtension())
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getFileExtension())
.value()
.isEqualTo("foo");

input.fileExtension = "";
updatedConfig = projectCodeOwnersApiFactory.project(project).updateConfig(input);
assertThat(updatedConfig.general.fileExtension).isNull();
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getFileExtension())
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getFileExtension())
.isEmpty();
}

Expand Down Expand Up @@ -409,31 +406,28 @@ public void setImplicitApprovals() throws Exception {

@Test
public void setOverrideInfoUrl() throws Exception {
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getOverrideInfoUrl())
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getOverrideInfoUrl())
.isEmpty();

CodeOwnerProjectConfigInput input = new CodeOwnerProjectConfigInput();
input.overrideInfoUrl = "http://foo.bar";
CodeOwnerProjectConfigInfo updatedConfig =
projectCodeOwnersApiFactory.project(project).updateConfig(input);
assertThat(updatedConfig.general.overrideInfoUrl).isEqualTo("http://foo.bar");
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getOverrideInfoUrl())
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getOverrideInfoUrl())
.value()
.isEqualTo("http://foo.bar");

input.overrideInfoUrl = "";
updatedConfig = projectCodeOwnersApiFactory.project(project).updateConfig(input);
assertThat(updatedConfig.general.overrideInfoUrl).isNull();
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getOverrideInfoUrl())
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getOverrideInfoUrl())
.isEmpty();
}

@Test
public void setInvalidCodeOwnerConfigInfoUrl() throws Exception {
OptionalSubject.assertThat(
assertThat(
codeOwnersPluginConfiguration
.getProjectConfig(project)
.getInvalidCodeOwnerConfigInfoUrl())
Expand All @@ -444,7 +438,7 @@ public void setInvalidCodeOwnerConfigInfoUrl() throws Exception {
CodeOwnerProjectConfigInfo updatedConfig =
projectCodeOwnersApiFactory.project(project).updateConfig(input);
assertThat(updatedConfig.general.invalidCodeOwnerConfigInfoUrl).isEqualTo("http://foo.bar");
OptionalSubject.assertThat(
assertThat(
codeOwnersPluginConfiguration
.getProjectConfig(project)
.getInvalidCodeOwnerConfigInfoUrl())
Expand All @@ -454,7 +448,7 @@ public void setInvalidCodeOwnerConfigInfoUrl() throws Exception {
input.invalidCodeOwnerConfigInfoUrl = "";
updatedConfig = projectCodeOwnersApiFactory.project(project).updateConfig(input);
assertThat(updatedConfig.general.invalidCodeOwnerConfigInfoUrl).isNull();
OptionalSubject.assertThat(
assertThat(
codeOwnersPluginConfiguration
.getProjectConfig(project)
.getInvalidCodeOwnerConfigInfoUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.plugins.codeowners.testing.CodeOwnerConfigSubject.assertThat;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static com.google.gerrit.truth.OptionalSubject.assertThat;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.truth.Truth8;
import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RefNames;
Expand All @@ -36,7 +36,6 @@
import com.google.gerrit.plugins.codeowners.backend.CodeOwners;
import com.google.gerrit.plugins.codeowners.backend.CodeOwnersUpdate;
import com.google.gerrit.server.ServerInitiated;
import com.google.gerrit.truth.OptionalSubject;
import com.google.inject.Key;
import com.google.inject.Provider;
import java.nio.file.Path;
Expand Down Expand Up @@ -176,7 +175,7 @@ public void specifiedFolderPathIsRespectedForCodeOwnerConfigCreation() throws Ex
.folderPath(folderPath)
.addCodeOwnerEmail(admin.email())
.create();
Truth8.assertThat(codeOwnerConfigKey.folderPath()).isEqualTo(Path.of(folderPath));
assertThat(codeOwnerConfigKey.folderPath()).isEqualTo(Path.of(folderPath));
assertThat(getCodeOwnerConfigFromServer(codeOwnerConfigKey))
.hasCodeOwnerSetsThat()
.onlyElement()
Expand All @@ -195,7 +194,7 @@ public void specifiedFileNameIsRespectedForCodeOwnerConfigCreation() throws Exce
.fileName("OWNERS_foo")
.addCodeOwnerEmail(admin.email())
.create();
OptionalSubject.assertThat(codeOwnerConfigKey.fileName()).value().isEqualTo("OWNERS_foo");
assertThat(codeOwnerConfigKey.fileName()).value().isEqualTo("OWNERS_foo");
assertThat(getCodeOwnerConfigFromServer(codeOwnerConfigKey))
.hasCodeOwnerSetsThat()
.onlyElement()
Expand Down Expand Up @@ -441,7 +440,7 @@ public void clearCodeOwners_emptyCodeOwnerConfigIsDeleted() throws Exception {
// was dropped.
// Since this made the code owner config empty it caused a deletion of the code owner config
// file.
OptionalSubject.assertThat(codeOwners.getFromCurrentRevision(codeOwnerConfig.key())).isEmpty();
assertThat(codeOwners.getFromCurrentRevision(codeOwnerConfig.key())).isEmpty();
}

@Test
Expand Down Expand Up @@ -507,7 +506,7 @@ public void clearCodeOwnerSets() throws Exception {
.update();

// Removing all code owner sets leads to a deletion of the code owner config file.
OptionalSubject.assertThat(codeOwners.getFromCurrentRevision(codeOwnerConfig.key())).isEmpty();
assertThat(codeOwners.getFromCurrentRevision(codeOwnerConfig.key())).isEmpty();
}

@Test
Expand Down Expand Up @@ -570,7 +569,7 @@ public void clearImports() throws Exception {
.update();

// Removing all code owner sets leads to a deletion of the code owner config file.
OptionalSubject.assertThat(codeOwners.getFromCurrentRevision(codeOwnerConfig.key())).isEmpty();
assertThat(codeOwners.getFromCurrentRevision(codeOwnerConfig.key())).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static com.google.gerrit.plugins.codeowners.testing.CodeOwnerConfigSubject.assertThatOptional;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;

import com.google.common.truth.Truth8;
import com.google.gerrit.acceptance.config.GerritConfig;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.BranchNameKey;
Expand Down Expand Up @@ -476,15 +475,15 @@ public void cannotUpdateCodeOwnerConfigInNonExistingBranch() throws Exception {
@Test
public void getFilePathForCodeOwnerConfigKeyWithoutFileName() throws Exception {
CodeOwnerConfig.Key codeOwnerConfigKey = CodeOwnerConfig.Key.create(project, "master", "/");
Truth8.assertThat(codeOwnerBackend.getFilePath(codeOwnerConfigKey))
assertThat(codeOwnerBackend.getFilePath(codeOwnerConfigKey))
.isEqualTo(Path.of(codeOwnerConfigKey.folderPath() + getFileName()));
}

@Test
public void getFilePathForCodeOwnerConfigKeyWithFileName() throws Exception {
CodeOwnerConfig.Key codeOwnerConfigKey =
CodeOwnerConfig.Key.create(project, "master", "/", getFileName() + "_foo_bar");
Truth8.assertThat(codeOwnerBackend.getFilePath(codeOwnerConfigKey))
assertThat(codeOwnerBackend.getFilePath(codeOwnerConfigKey))
.isEqualTo(Path.of(codeOwnerConfigKey.folderPath() + codeOwnerConfigKey.fileName().get()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static com.google.gerrit.truth.OptionalSubject.assertThat;
import static org.mockito.Mockito.when;

import com.google.gerrit.common.Nullable;
Expand All @@ -24,7 +25,6 @@
import com.google.gerrit.plugins.codeowners.common.ChangedFile;
import com.google.gerrit.server.patch.PatchListEntry;
import com.google.gerrit.server.patch.filediff.FileDiffOutput;
import com.google.gerrit.truth.OptionalSubject;
import java.nio.file.Path;
import java.util.Optional;
import org.eclipse.jgit.diff.DiffEntry;
Expand All @@ -48,16 +48,14 @@ public class ChangedFileTest extends AbstractCodeOwnersTest {
public void getNewPath_diffEntry() throws Exception {
String newPath = "foo/bar/baz.txt";
setupDiffEntry(newPath, /* oldPath= */ null, ChangeType.ADD);
OptionalSubject.assertThat(ChangedFile.create(diffEntry).newPath())
.value()
.isEqualTo(Path.of("/" + newPath));
assertThat(ChangedFile.create(diffEntry).newPath()).value().isEqualTo(Path.of("/" + newPath));
}

@Test
public void getNewPath_patchListEntry() throws Exception {
String newPath = "foo/bar/baz.txt";
setupPatchListEntry(newPath, /* oldPath= */ null, Patch.ChangeType.ADDED);
OptionalSubject.assertThat(ChangedFile.create(patchListEntry).newPath())
assertThat(ChangedFile.create(patchListEntry).newPath())
.value()
.isEqualTo(Path.of("/" + newPath));
}
Expand All @@ -66,27 +64,27 @@ public void getNewPath_patchListEntry() throws Exception {
public void getNewPath_fileDiffOutput() throws Exception {
String newPath = "foo/bar/baz.txt";
setupFileDiffOutput(newPath, /* oldPath= */ null, Patch.ChangeType.ADDED);
OptionalSubject.assertThat(ChangedFile.create(fileDiffOutput).newPath())
assertThat(ChangedFile.create(fileDiffOutput).newPath())
.value()
.isEqualTo(Path.of("/" + newPath));
}

@Test
public void getNewPathWhenNewPathIsNotSet_diffEntry() throws Exception {
setupDiffEntry(/* newPath= */ null, /* oldPath= */ null, ChangeType.ADD);
OptionalSubject.assertThat(ChangedFile.create(diffEntry).newPath()).isEmpty();
assertThat(ChangedFile.create(diffEntry).newPath()).isEmpty();
}

@Test
public void getNewPathWhenNewPathIsNotSet_patchListEntry() throws Exception {
setupPatchListEntry(/* newPath= */ null, /* oldPath= */ null, Patch.ChangeType.ADDED);
OptionalSubject.assertThat(ChangedFile.create(patchListEntry).newPath()).isEmpty();
assertThat(ChangedFile.create(patchListEntry).newPath()).isEmpty();
}

@Test
public void getNewPathWhenNewPathIsNotSet_fileDiffOutput() throws Exception {
setupFileDiffOutput(/* newPath= */ null, /* oldPath= */ null, Patch.ChangeType.ADDED);
OptionalSubject.assertThat(ChangedFile.create(fileDiffOutput).newPath()).isEmpty();
assertThat(ChangedFile.create(fileDiffOutput).newPath()).isEmpty();
}

@Test
Expand Down Expand Up @@ -195,16 +193,14 @@ public void cannotCheckHasNewPathWithRelativePath_fileDiffOutput() throws Except
public void getOldPath_diffEntry() throws Exception {
String oldPath = "foo/bar/baz.txt";
setupDiffEntry(/* newPath= */ null, oldPath, ChangeType.DELETE);
OptionalSubject.assertThat(ChangedFile.create(diffEntry).oldPath())
.value()
.isEqualTo(Path.of("/" + oldPath));
assertThat(ChangedFile.create(diffEntry).oldPath()).value().isEqualTo(Path.of("/" + oldPath));
}

@Test
public void getOldPath_patchListEntry() throws Exception {
String oldPath = "foo/bar/baz.txt";
setupPatchListEntry(/* newPath= */ null, oldPath, Patch.ChangeType.DELETED);
OptionalSubject.assertThat(ChangedFile.create(patchListEntry).oldPath())
assertThat(ChangedFile.create(patchListEntry).oldPath())
.value()
.isEqualTo(Path.of("/" + oldPath));
}
Expand All @@ -213,7 +209,7 @@ public void getOldPath_patchListEntry() throws Exception {
public void getOldPath_fileDiffOutput() throws Exception {
String oldPath = "foo/bar/baz.txt";
setupFileDiffOutput(/* newPath= */ null, oldPath, Patch.ChangeType.DELETED);
OptionalSubject.assertThat(ChangedFile.create(fileDiffOutput).oldPath())
assertThat(ChangedFile.create(fileDiffOutput).oldPath())
.value()
.isEqualTo(Path.of("/" + oldPath));
}
Expand All @@ -222,19 +218,19 @@ public void getOldPath_fileDiffOutput() throws Exception {
public void getOldPathWhenOldPathIsNotSet_diffEntry() throws Exception {
setupDiffEntry(/* newPath= */ null, /* oldPath= */ null, ChangeType.DELETE);
when(diffEntry.getOldPath()).thenReturn(DiffEntry.DEV_NULL);
OptionalSubject.assertThat(ChangedFile.create(diffEntry).oldPath()).isEmpty();
assertThat(ChangedFile.create(diffEntry).oldPath()).isEmpty();
}

@Test
public void getOldPathWhenOldPathIsNotSet_patchListEntry() throws Exception {
setupPatchListEntry(/* newPath= */ null, /* oldPath= */ null, Patch.ChangeType.DELETED);
OptionalSubject.assertThat(ChangedFile.create(patchListEntry).oldPath()).isEmpty();
assertThat(ChangedFile.create(patchListEntry).oldPath()).isEmpty();
}

@Test
public void getOldPathWhenOldPathIsNotSet_fileDiffOutput() throws Exception {
setupFileDiffOutput(/* newPath= */ null, /* oldPath= */ null, Patch.ChangeType.DELETED);
OptionalSubject.assertThat(ChangedFile.create(fileDiffOutput).oldPath()).isEmpty();
assertThat(ChangedFile.create(fileDiffOutput).oldPath()).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;

import com.google.common.truth.Truth8;
import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersTest;
import java.nio.file.Path;
import java.util.Optional;
Expand Down Expand Up @@ -65,7 +64,7 @@ public void absoluteFilePathCanBeSpecifiedInDifferentFormats() throws Exception
public void relativeFilePathCanBeSpecified() throws Exception {
Path path =
CodeOwnerConfigReference.create(CodeOwnerConfigImportMode.ALL, "foo/OWNERS").filePath();
Truth8.assertThat(path).isEqualTo(Path.of("foo/OWNERS"));
assertThat(path).isEqualTo(Path.of("foo/OWNERS"));
assertThat(path.isAbsolute()).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;

import com.google.common.truth.Truth8;
import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RefNames;
Expand Down Expand Up @@ -87,8 +86,7 @@ public void getFilePath() throws Exception {
String folderPath = "/foo/bar/";
CodeOwnerConfig.Key codeOwnerConfigKey =
CodeOwnerConfig.Key.create(Project.nameKey("project"), "master", folderPath);
Truth8.assertThat(codeOwnerConfigKey.filePath("OWNERS"))
.isEqualTo(Path.of(folderPath, "OWNERS"));
assertThat(codeOwnerConfigKey.filePath("OWNERS")).isEqualTo(Path.of(folderPath, "OWNERS"));
}

@Test
Expand All @@ -98,7 +96,7 @@ public void getFilePathWithCustomFileName() throws Exception {
CodeOwnerConfig.Key codeOwnerConfigKey =
CodeOwnerConfig.Key.create(
Project.nameKey("project"), "master", folderPath, customFileName);
Truth8.assertThat(codeOwnerConfigKey.filePath("OWNERS"))
assertThat(codeOwnerConfigKey.filePath("OWNERS"))
.isEqualTo(Path.of(folderPath, customFileName));
}

Expand Down Expand Up @@ -141,7 +139,7 @@ public void relativizePath() throws Exception {
TEST_REVISION)
.build();
Path relativizedPath = codeOwnerConfig.relativize(Path.of("/foo/bar/baz.md"));
Truth8.assertThat(relativizedPath).isEqualTo(Path.of("baz.md"));
assertThat(relativizedPath).isEqualTo(Path.of("baz.md"));
}

private static CodeOwnerConfig.Builder createCodeOwnerBuilder() {
Expand Down
Loading

0 comments on commit 83d8116

Please # to comment.