Skip to content

Commit

Permalink
Temporarily qualify calls to custom assertThat(Optional) methods
Browse files Browse the repository at this point in the history
The Truth team is working on migrating callers of the Truth8.assertThat
methods to call equivalent methods on the main Truth class.

Due to this calls to custom assertThat(Optional) methods will
temporarily become ambiguous and hence need to be qualified to avoid
breakage.

Change-Id: I53afa474f4025cdaf6090868f13d46fead315dc0
Signed-off-by: Edwin Kempin <ekempin@google.com>
Reviewed-on: https://gerrit-review.googlesource.com/c/plugins/code-owners/+/402728
Reviewed-by: Patrick Hiesel <hiesel@google.com>
  • Loading branch information
EdwinKempin authored and phiesel committed Jan 15, 2024
1 parent 02acc99 commit cbed17a
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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 @@ -46,6 +45,7 @@
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,7 +257,8 @@ public void configurePathExpressionsForProject() throws Exception {

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

PushResult r = pushRefsMetaConfig();
assertThat(r.getRemoteUpdate(RefNames.REFS_CONFIG).getStatus()).isEqualTo(Status.OK);
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getPathExpressions("master"))
OptionalSubject.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,7 +19,6 @@
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 @@ -44,6 +43,7 @@
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,22 +181,25 @@ public void cannotSetInvalidDisabledBranch() throws Exception {

@Test
public void setFileExtension() throws Exception {
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getFileExtension())
OptionalSubject.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");
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getFileExtension())
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getFileExtension())
.value()
.isEqualTo("foo");

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

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

@Test
public void setOverrideInfoUrl() throws Exception {
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getOverrideInfoUrl())
OptionalSubject.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");
assertThat(codeOwnersPluginConfiguration.getProjectConfig(project).getOverrideInfoUrl())
OptionalSubject.assertThat(
codeOwnersPluginConfiguration.getProjectConfig(project).getOverrideInfoUrl())
.value()
.isEqualTo("http://foo.bar");

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

@Test
public void setInvalidCodeOwnerConfigInfoUrl() throws Exception {
assertThat(
OptionalSubject.assertThat(
codeOwnersPluginConfiguration
.getProjectConfig(project)
.getInvalidCodeOwnerConfigInfoUrl())
Expand All @@ -438,7 +444,7 @@ public void setInvalidCodeOwnerConfigInfoUrl() throws Exception {
CodeOwnerProjectConfigInfo updatedConfig =
projectCodeOwnersApiFactory.project(project).updateConfig(input);
assertThat(updatedConfig.general.invalidCodeOwnerConfigInfoUrl).isEqualTo("http://foo.bar");
assertThat(
OptionalSubject.assertThat(
codeOwnersPluginConfiguration
.getProjectConfig(project)
.getInvalidCodeOwnerConfigInfoUrl())
Expand All @@ -448,7 +454,7 @@ public void setInvalidCodeOwnerConfigInfoUrl() throws Exception {
input.invalidCodeOwnerConfigInfoUrl = "";
updatedConfig = projectCodeOwnersApiFactory.project(project).updateConfig(input);
assertThat(updatedConfig.general.invalidCodeOwnerConfigInfoUrl).isNull();
assertThat(
OptionalSubject.assertThat(
codeOwnersPluginConfiguration
.getProjectConfig(project)
.getInvalidCodeOwnerConfigInfoUrl())
Expand Down
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.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;
Expand All @@ -37,6 +36,7 @@
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.Paths;
Expand Down Expand Up @@ -195,7 +195,7 @@ public void specifiedFileNameIsRespectedForCodeOwnerConfigCreation() throws Exce
.fileName("OWNERS_foo")
.addCodeOwnerEmail(admin.email())
.create();
assertThat(codeOwnerConfigKey.fileName()).value().isEqualTo("OWNERS_foo");
OptionalSubject.assertThat(codeOwnerConfigKey.fileName()).value().isEqualTo("OWNERS_foo");
assertThat(getCodeOwnerConfigFromServer(codeOwnerConfigKey))
.hasCodeOwnerSetsThat()
.onlyElement()
Expand Down Expand Up @@ -441,7 +441,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.
assertThat(codeOwners.getFromCurrentRevision(codeOwnerConfig.key())).isEmpty();
OptionalSubject.assertThat(codeOwners.getFromCurrentRevision(codeOwnerConfig.key())).isEmpty();
}

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

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

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

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

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

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 @@ -25,6 +24,7 @@
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.Paths;
import java.util.Optional;
import org.eclipse.jgit.diff.DiffEntry;
Expand All @@ -48,14 +48,16 @@ public class ChangedFileTest extends AbstractCodeOwnersTest {
public void getNewPath_diffEntry() throws Exception {
String newPath = "foo/bar/baz.txt";
setupDiffEntry(newPath, /* oldPath= */ null, ChangeType.ADD);
assertThat(ChangedFile.create(diffEntry).newPath()).value().isEqualTo(Paths.get("/" + newPath));
OptionalSubject.assertThat(ChangedFile.create(diffEntry).newPath())
.value()
.isEqualTo(Paths.get("/" + newPath));
}

@Test
public void getNewPath_patchListEntry() throws Exception {
String newPath = "foo/bar/baz.txt";
setupPatchListEntry(newPath, /* oldPath= */ null, Patch.ChangeType.ADDED);
assertThat(ChangedFile.create(patchListEntry).newPath())
OptionalSubject.assertThat(ChangedFile.create(patchListEntry).newPath())
.value()
.isEqualTo(Paths.get("/" + newPath));
}
Expand All @@ -64,27 +66,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);
assertThat(ChangedFile.create(fileDiffOutput).newPath())
OptionalSubject.assertThat(ChangedFile.create(fileDiffOutput).newPath())
.value()
.isEqualTo(Paths.get("/" + newPath));
}

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

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

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

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

@Test
public void getOldPath_patchListEntry() throws Exception {
String oldPath = "foo/bar/baz.txt";
setupPatchListEntry(/* newPath= */ null, oldPath, Patch.ChangeType.DELETED);
assertThat(ChangedFile.create(patchListEntry).oldPath())
OptionalSubject.assertThat(ChangedFile.create(patchListEntry).oldPath())
.value()
.isEqualTo(Paths.get("/" + oldPath));
}
Expand All @@ -209,7 +213,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);
assertThat(ChangedFile.create(fileDiffOutput).oldPath())
OptionalSubject.assertThat(ChangedFile.create(fileDiffOutput).oldPath())
.value()
.isEqualTo(Paths.get("/" + oldPath));
}
Expand All @@ -218,19 +222,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);
assertThat(ChangedFile.create(diffEntry).oldPath()).isEmpty();
OptionalSubject.assertThat(ChangedFile.create(diffEntry).oldPath()).isEmpty();
}

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

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package com.google.gerrit.plugins.codeowners.backend;

import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.truth.OptionalSubject.assertThat;

import com.google.common.collect.ImmutableList;
import com.google.gerrit.acceptance.config.GerritConfig;
import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersTest;
import com.google.gerrit.plugins.codeowners.backend.config.InvalidPluginConfigurationException;
import com.google.gerrit.server.ExceptionHook.Status;
import com.google.gerrit.truth.OptionalSubject;
import java.nio.file.InvalidPathException;
import java.util.Optional;
import org.junit.Before;
Expand Down Expand Up @@ -114,29 +114,36 @@ public void getUserMessages_withInvalidCodeOwnerConfigInfoUrl() throws Exception
@Test
public void getStatus() throws Exception {
Status conflictStatus = Status.create(409, "Conflict");
assertThat(getStatus(newInvalidPluginConfigurationException()))
OptionalSubject.assertThat(getStatus(newInvalidPluginConfigurationException()))
.value()
.isEqualTo(conflictStatus);
assertThat(getStatus(newExceptionWithCause(newInvalidPluginConfigurationException())))
OptionalSubject.assertThat(
getStatus(newExceptionWithCause(newInvalidPluginConfigurationException())))
.value()
.isEqualTo(conflictStatus);

assertThat(getStatus(newInvalidCodeOwnerConfigException())).value().isEqualTo(conflictStatus);
assertThat(getStatus(newExceptionWithCause(newInvalidCodeOwnerConfigException())))
OptionalSubject.assertThat(getStatus(newInvalidCodeOwnerConfigException()))
.value()
.isEqualTo(conflictStatus);
OptionalSubject.assertThat(
getStatus(newExceptionWithCause(newInvalidCodeOwnerConfigException())))
.value()
.isEqualTo(conflictStatus);

assertThat(getStatus(newInvalidPathException())).value().isEqualTo(conflictStatus);
assertThat(getStatus(newExceptionWithCause(newInvalidPathException())))
OptionalSubject.assertThat(getStatus(newInvalidPathException()))
.value()
.isEqualTo(conflictStatus);
OptionalSubject.assertThat(getStatus(newExceptionWithCause(newInvalidPathException())))
.value()
.isEqualTo(conflictStatus);

assertThat(getStatus(new Exception())).isEmpty();
assertThat(getStatus(newExceptionWithCause(new Exception()))).isEmpty();
OptionalSubject.assertThat(getStatus(new Exception())).isEmpty();
OptionalSubject.assertThat(getStatus(newExceptionWithCause(new Exception()))).isEmpty();

assertThat(getStatus(CodeOwnersInternalServerErrorException.newInternalServerError("msg")))
OptionalSubject.assertThat(
getStatus(CodeOwnersInternalServerErrorException.newInternalServerError("msg")))
.isEmpty();
assertThat(
OptionalSubject.assertThat(
getStatus(
newExceptionWithCause(
CodeOwnersInternalServerErrorException.newInternalServerError("msg"))))
Expand Down
Loading

0 comments on commit cbed17a

Please # to comment.