Use assertThrows for testing exceptions
Based on a change generated by an automated refactoring tool. Covers just the portions of Gerrit tests that are run internally at Google. The refactoring tool is not perfect, so some modifications were required to get tests to compile and pass, for example: * The tool didn't detect when variables referenced from newly-created lambdas were not effectively final in the enclosing scope. * The tool moved the entire body of methods with @Test(expected). This does actually match the semantics of the @Test annotation (and is the reason that construction is so strongly discouraged). However, our implementation of assertThrows does not propagate the exceptions thrown when an assume() call fails. This may or may not be desirable in our library, but for all the instances where it occurred in the code, it was clear that the right thing to do was to minimize the code in the lambda body anyway. For a full list of modifications from the tool's original output, diff this commit against earlier patch sets of this change. PiperOrigin-RevId: 246326737 Change-Id: I65a4c9635ed62ecae8097f9d284609add6b9929b
This commit is contained in:
@@ -17,6 +17,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.GitUtil;
|
||||
@@ -143,8 +144,7 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void createAccessChangeNop() throws Exception {
|
||||
ProjectAccessInput accessInput = newProjectAccessInput();
|
||||
exception.expect(BadRequestException.class);
|
||||
pApi().accessChange(accessInput);
|
||||
assertThrows(BadRequestException.class, () -> pApi().accessChange(accessInput));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -326,8 +326,7 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
pApi().access(accessInput);
|
||||
|
||||
requestScopeOperations.setApiUser(user.id());
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
pApi().access();
|
||||
assertThrows(ResourceNotFoundException.class, () -> pApi().access());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -346,8 +345,7 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
accessInfoToApply.add.put(REFS_HEADS, accessSectionInfoToApply);
|
||||
|
||||
requestScopeOperations.setApiUser(user.id());
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
pApi().access();
|
||||
assertThrows(ResourceNotFoundException.class, () -> pApi().access());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -409,9 +407,8 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
accessInput.parent = newParentProjectName;
|
||||
|
||||
requestScopeOperations.setApiUser(user.id());
|
||||
exception.expect(AuthException.class);
|
||||
exception.expectMessage("administrate server not permitted");
|
||||
pApi().access(accessInput);
|
||||
AuthException thrown = assertThrows(AuthException.class, () -> pApi().access(accessInput));
|
||||
assertThat(thrown).hasMessageThat().contains("administrate server not permitted");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -436,8 +433,8 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
accessInput.add.put(AccessSection.GLOBAL_CAPABILITIES, accessSectionInfo);
|
||||
|
||||
requestScopeOperations.setApiUser(user.id());
|
||||
exception.expect(AuthException.class);
|
||||
gApi.projects().name(allProjects.get()).access(accessInput);
|
||||
assertThrows(
|
||||
AuthException.class, () -> gApi.projects().name(allProjects.get()).access(accessInput));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -465,8 +462,7 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
|
||||
accessInput.add.put(AccessSection.GLOBAL_CAPABILITIES, accessSectionInfo);
|
||||
|
||||
exception.expect(BadRequestException.class);
|
||||
pApi().access(accessInput);
|
||||
assertThrows(BadRequestException.class, () -> pApi().access(accessInput));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -479,9 +475,9 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
accessSectionInfo.permissions.put(Permission.PUSH, permissionInfo);
|
||||
|
||||
accessInput.add.put(AccessSection.GLOBAL_CAPABILITIES, accessSectionInfo);
|
||||
|
||||
exception.expect(BadRequestException.class);
|
||||
gApi.projects().name(allProjects.get()).access(accessInput);
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() -> gApi.projects().name(allProjects.get()).access(accessInput));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -492,8 +488,8 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
accessInput.remove.put(AccessSection.GLOBAL_CAPABILITIES, accessSectionInfo);
|
||||
|
||||
requestScopeOperations.setApiUser(user.id());
|
||||
exception.expect(AuthException.class);
|
||||
gApi.projects().name(allProjects.get()).access(accessInput);
|
||||
assertThrows(
|
||||
AuthException.class, () -> gApi.projects().name(allProjects.get()).access(accessInput));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -598,9 +594,13 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
public void allUsersCanOnlyInheritFromAllProjects() throws Exception {
|
||||
ProjectAccessInput accessInput = newProjectAccessInput();
|
||||
accessInput.parent = project.get();
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage(allUsers.get() + " must inherit from " + allProjects.get());
|
||||
gApi.projects().name(allUsers.get()).access(accessInput);
|
||||
BadRequestException thrown =
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() -> gApi.projects().name(allUsers.get()).access(accessInput));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(allUsers.get() + " must inherit from " + allProjects.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -650,9 +650,9 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
String invalidRef = Constants.R_HEADS + "stable_*";
|
||||
accessInput.add.put(invalidRef, accessSectionInfo);
|
||||
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("Invalid Name: " + invalidRef);
|
||||
pApi().access(accessInput);
|
||||
BadRequestException thrown =
|
||||
assertThrows(BadRequestException.class, () -> pApi().access(accessInput));
|
||||
assertThat(thrown).hasMessageThat().contains("Invalid Name: " + invalidRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -664,9 +664,9 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
String invalidRef = Constants.R_HEADS + "stable_*";
|
||||
accessInput.add.put(invalidRef, accessSectionInfo);
|
||||
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("Invalid Name: " + invalidRef);
|
||||
pApi().accessChange(accessInput);
|
||||
BadRequestException thrown =
|
||||
assertThrows(BadRequestException.class, () -> pApi().accessChange(accessInput));
|
||||
assertThat(thrown).hasMessageThat().contains("Invalid Name: " + invalidRef);
|
||||
}
|
||||
|
||||
private ProjectApi pApi() throws Exception {
|
||||
|
||||
@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth8.assertThat;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_HEADS;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
@@ -160,11 +161,10 @@ public class CreateBranchIT extends AbstractDaemonTest {
|
||||
throws Exception {
|
||||
BranchInput in = new BranchInput();
|
||||
in.revision = revision;
|
||||
RestApiException thrown = assertThrows(errType, () -> branch(branch).create(in));
|
||||
if (errMsg != null) {
|
||||
exception.expectMessage(errMsg);
|
||||
assertThat(thrown).hasMessageThat().contains(errMsg);
|
||||
}
|
||||
exception.expect(errType);
|
||||
branch(branch).create(in);
|
||||
}
|
||||
|
||||
private void assertCreateFails(BranchNameKey branch, Class<? extends RestApiException> errType)
|
||||
|
||||
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth8.assertThat;
|
||||
import static com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo;
|
||||
import static com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectOwners;
|
||||
import static com.google.gerrit.server.project.ProjectConfig.PROJECT_CONFIG;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -469,8 +470,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
|
||||
private void assertCreateFails(ProjectInput in, Class<? extends RestApiException> errType)
|
||||
throws Exception {
|
||||
exception.expect(errType);
|
||||
gApi.projects().create(in);
|
||||
assertThrows(errType, () -> gApi.projects().create(in));
|
||||
}
|
||||
|
||||
private Optional<String> readProjectConfig(String projectName) throws Exception {
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.acceptance.rest.project;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
import static org.eclipse.jgit.lib.Constants.R_HEADS;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
@@ -136,9 +137,11 @@ public class DeleteBranchIT extends AbstractDaemonTest {
|
||||
allow(allUsers, RefNames.REFS_USERS + "*", Permission.CREATE, REGISTERED_USERS);
|
||||
allow(allUsers, RefNames.REFS_USERS + "*", Permission.PUSH, REGISTERED_USERS);
|
||||
|
||||
exception.expect(ResourceConflictException.class);
|
||||
exception.expectMessage("Not allowed to delete user branch.");
|
||||
branch(BranchNameKey.create(allUsers, RefNames.refsUsers(admin.id()))).delete();
|
||||
ResourceConflictException thrown =
|
||||
assertThrows(
|
||||
ResourceConflictException.class,
|
||||
() -> branch(BranchNameKey.create(allUsers, RefNames.refsUsers(admin.id()))).delete());
|
||||
assertThat(thrown).hasMessageThat().contains("Not allowed to delete user branch.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,9 +149,13 @@ public class DeleteBranchIT extends AbstractDaemonTest {
|
||||
allow(allUsers, RefNames.REFS_GROUPS + "*", Permission.CREATE, REGISTERED_USERS);
|
||||
allow(allUsers, RefNames.REFS_GROUPS + "*", Permission.PUSH, REGISTERED_USERS);
|
||||
|
||||
exception.expect(ResourceConflictException.class);
|
||||
exception.expectMessage("Not allowed to delete group branch.");
|
||||
branch(BranchNameKey.create(allUsers, RefNames.refsGroups(adminGroupUuid()))).delete();
|
||||
ResourceConflictException thrown =
|
||||
assertThrows(
|
||||
ResourceConflictException.class,
|
||||
() ->
|
||||
branch(BranchNameKey.create(allUsers, RefNames.refsGroups(adminGroupUuid())))
|
||||
.delete());
|
||||
assertThat(thrown).hasMessageThat().contains("Not allowed to delete group branch.");
|
||||
}
|
||||
|
||||
private void blockForcePush() throws Exception {
|
||||
@@ -179,8 +186,7 @@ public class DeleteBranchIT extends AbstractDaemonTest {
|
||||
+ "/branches/"
|
||||
+ IdString.fromDecoded(ref).encoded());
|
||||
r.assertNoContent();
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
branch(branch).get();
|
||||
assertThrows(ResourceNotFoundException.class, () -> branch(branch).get());
|
||||
}
|
||||
|
||||
private void assertDeleteSucceeds(BranchNameKey branch) throws Exception {
|
||||
@@ -189,14 +195,12 @@ public class DeleteBranchIT extends AbstractDaemonTest {
|
||||
branch(branch).delete();
|
||||
eventRecorder.assertRefUpdatedEvents(
|
||||
project.get(), branch.branch(), null, branchRev, branchRev, null);
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
branch(branch).get();
|
||||
assertThrows(ResourceNotFoundException.class, () -> branch(branch).get());
|
||||
}
|
||||
|
||||
private void assertDeleteForbidden(BranchNameKey branch) throws Exception {
|
||||
assertThat(branch(branch).get().canDelete).isNull();
|
||||
exception.expect(AuthException.class);
|
||||
exception.expectMessage("not permitted: delete");
|
||||
branch(branch).delete();
|
||||
AuthException thrown = assertThrows(AuthException.class, () -> branch(branch).delete());
|
||||
assertThat(thrown).hasMessageThat().contains("not permitted: delete");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.eclipse.jgit.lib.Constants.R_HEADS;
|
||||
import static org.eclipse.jgit.lib.Constants.R_REFS;
|
||||
@@ -139,26 +140,26 @@ public class DeleteBranchesIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void missingInput() throws Exception {
|
||||
DeleteBranchesInput input = null;
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("branches must be specified");
|
||||
project().deleteBranches(input);
|
||||
BadRequestException thrown =
|
||||
assertThrows(BadRequestException.class, () -> project().deleteBranches(input));
|
||||
assertThat(thrown).hasMessageThat().contains("branches must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingBranchList() throws Exception {
|
||||
DeleteBranchesInput input = new DeleteBranchesInput();
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("branches must be specified");
|
||||
project().deleteBranches(input);
|
||||
BadRequestException thrown =
|
||||
assertThrows(BadRequestException.class, () -> project().deleteBranches(input));
|
||||
assertThat(thrown).hasMessageThat().contains("branches must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyBranchList() throws Exception {
|
||||
DeleteBranchesInput input = new DeleteBranchesInput();
|
||||
input.branches = Lists.newArrayList();
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("branches must be specified");
|
||||
project().deleteBranches(input);
|
||||
BadRequestException thrown =
|
||||
assertThrows(BadRequestException.class, () -> project().deleteBranches(input));
|
||||
assertThat(thrown).hasMessageThat().contains("branches must be specified");
|
||||
}
|
||||
|
||||
private String errorMessageForBranches(List<String> branches) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.acceptance.rest.project;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
import static org.eclipse.jgit.lib.Constants.R_TAGS;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
@@ -122,14 +123,12 @@ public class DeleteTagIT extends AbstractDaemonTest {
|
||||
String tagRev = tagInfo.revision;
|
||||
tag().delete();
|
||||
eventRecorder.assertRefUpdatedEvents(project.get(), TAG, null, tagRev, tagRev, null);
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
tag().get();
|
||||
assertThrows(ResourceNotFoundException.class, () -> tag().get());
|
||||
}
|
||||
|
||||
private void assertDeleteForbidden() throws Exception {
|
||||
assertThat(tag().get().canDelete).isNull();
|
||||
exception.expect(AuthException.class);
|
||||
exception.expectMessage("not permitted: delete");
|
||||
tag().delete();
|
||||
AuthException thrown = assertThrows(AuthException.class, () -> tag().delete());
|
||||
assertThat(thrown).hasMessageThat().contains("not permitted: delete");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
@@ -45,9 +46,9 @@ public class FileBranchIT extends AbstractDaemonTest {
|
||||
assertThat(content.asString()).isEqualTo(PushOneCommit.FILE_CONTENT);
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class)
|
||||
@Test
|
||||
public void getNonExistingFile() throws Exception {
|
||||
branch().file("does-not-exist");
|
||||
assertThrows(ResourceNotFoundException.class, () -> branch().file("does-not-exist"));
|
||||
}
|
||||
|
||||
private BranchApi branch() throws Exception {
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
@@ -69,8 +71,10 @@ public class GetChildProjectIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
private void assertChildNotFound(Project.NameKey parent, String child) throws Exception {
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
exception.expectMessage(child);
|
||||
gApi.projects().name(parent.get()).child(child).get();
|
||||
ResourceNotFoundException thrown =
|
||||
assertThrows(
|
||||
ResourceNotFoundException.class,
|
||||
() -> gApi.projects().name(parent.get()).child(child).get());
|
||||
assertThat(thrown).hasMessageThat().contains(child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
@@ -54,8 +55,9 @@ public class GetProjectIT extends AbstractDaemonTest {
|
||||
assertThat(p.name).isEqualTo(name);
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class)
|
||||
@Test
|
||||
public void getProjectNotExisting() throws Exception {
|
||||
gApi.projects().name("does-not-exist").get();
|
||||
assertThrows(
|
||||
ResourceNotFoundException.class, () -> gApi.projects().name("does-not-exist").get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.gerrit.acceptance.rest.project.RefAssert.assertRefs;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
@@ -35,16 +36,18 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
public void listBranchesOfNonExistingProject_NotFound() throws Exception {
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
gApi.projects().name("non-existing").branches().get();
|
||||
assertThrows(
|
||||
ResourceNotFoundException.class,
|
||||
() -> gApi.projects().name("non-existing").branches().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listBranchesOfNonVisibleProject_NotFound() throws Exception {
|
||||
blockRead("refs/*");
|
||||
requestScopeOperations.setApiUser(user.id());
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
gApi.projects().name(project.get()).branches().get();
|
||||
assertThrows(
|
||||
ResourceNotFoundException.class,
|
||||
() -> gApi.projects().name(project.get()).branches().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.acceptance.rest.project.ProjectAssert.assertThatNameList;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
@@ -31,9 +33,11 @@ public class ListChildProjectsIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
public void listChildrenOfNonExistingProject_NotFound() throws Exception {
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
exception.expectMessage("non-existing");
|
||||
gApi.projects().name(name("non-existing")).child("children");
|
||||
ResourceNotFoundException thrown =
|
||||
assertThrows(
|
||||
ResourceNotFoundException.class,
|
||||
() -> gApi.projects().name(name("non-existing")).child("children"));
|
||||
assertThat(thrown).hasMessageThat().contains("non-existing");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||
import static org.eclipse.jgit.lib.Constants.R_TAGS;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
@@ -62,29 +63,31 @@ public class TagsIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
public void listTagsOfNonExistingProject() throws Exception {
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
gApi.projects().name("does-not-exist").tags().get();
|
||||
assertThrows(
|
||||
ResourceNotFoundException.class, () -> gApi.projects().name("does-not-exist").tags().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTagOfNonExistingProject() throws Exception {
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
gApi.projects().name("does-not-exist").tag("tag").get();
|
||||
assertThrows(
|
||||
ResourceNotFoundException.class,
|
||||
() -> gApi.projects().name("does-not-exist").tag("tag").get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listTagsOfNonVisibleProject() throws Exception {
|
||||
blockRead("refs/*");
|
||||
requestScopeOperations.setApiUser(user.id());
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
gApi.projects().name(project.get()).tags().get();
|
||||
assertThrows(
|
||||
ResourceNotFoundException.class, () -> gApi.projects().name(project.get()).tags().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTagOfNonVisibleProject() throws Exception {
|
||||
blockRead("refs/*");
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
gApi.projects().name(project.get()).tag("tag").get();
|
||||
assertThrows(
|
||||
ResourceNotFoundException.class,
|
||||
() -> gApi.projects().name(project.get()).tag("tag").get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,9 +250,9 @@ public class TagsIT extends AbstractDaemonTest {
|
||||
assertThat(result.ref).isEqualTo(R_TAGS + "test");
|
||||
|
||||
input.ref = "refs/tags/test";
|
||||
exception.expect(ResourceConflictException.class);
|
||||
exception.expectMessage("tag \"" + R_TAGS + "test\" already exists");
|
||||
tag(input.ref).create(input);
|
||||
ResourceConflictException thrown =
|
||||
assertThrows(ResourceConflictException.class, () -> tag(input.ref).create(input));
|
||||
assertThat(thrown).hasMessageThat().contains("tag \"" + R_TAGS + "test\" already exists");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -257,9 +260,8 @@ public class TagsIT extends AbstractDaemonTest {
|
||||
block(R_TAGS + "*", Permission.CREATE, REGISTERED_USERS);
|
||||
TagInput input = new TagInput();
|
||||
input.ref = "test";
|
||||
exception.expect(AuthException.class);
|
||||
exception.expectMessage("not permitted: create");
|
||||
tag(input.ref).create(input);
|
||||
AuthException thrown = assertThrows(AuthException.class, () -> tag(input.ref).create(input));
|
||||
assertThat(thrown).hasMessageThat().contains("not permitted: create");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -268,9 +270,10 @@ public class TagsIT extends AbstractDaemonTest {
|
||||
TagInput input = new TagInput();
|
||||
input.ref = "test";
|
||||
input.message = "annotation";
|
||||
exception.expect(AuthException.class);
|
||||
exception.expectMessage("Cannot create annotated tag \"" + R_TAGS + "test\"");
|
||||
tag(input.ref).create(input);
|
||||
AuthException thrown = assertThrows(AuthException.class, () -> tag(input.ref).create(input));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Cannot create annotated tag \"" + R_TAGS + "test\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -278,9 +281,9 @@ public class TagsIT extends AbstractDaemonTest {
|
||||
TagInput input = new TagInput();
|
||||
input.ref = "test";
|
||||
input.message = SIGNED_ANNOTATION;
|
||||
exception.expect(MethodNotAllowedException.class);
|
||||
exception.expectMessage("Cannot create signed tag \"" + R_TAGS + "test\"");
|
||||
tag(input.ref).create(input);
|
||||
MethodNotAllowedException thrown =
|
||||
assertThrows(MethodNotAllowedException.class, () -> tag(input.ref).create(input));
|
||||
assertThat(thrown).hasMessageThat().contains("Cannot create signed tag \"" + R_TAGS + "test\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -288,9 +291,9 @@ public class TagsIT extends AbstractDaemonTest {
|
||||
TagInput input = new TagInput();
|
||||
input.ref = "test";
|
||||
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("ref must match URL");
|
||||
tag("TEST").create(input);
|
||||
BadRequestException thrown =
|
||||
assertThrows(BadRequestException.class, () -> tag("TEST").create(input));
|
||||
assertThat(thrown).hasMessageThat().contains("ref must match URL");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -300,9 +303,9 @@ public class TagsIT extends AbstractDaemonTest {
|
||||
TagInput input = new TagInput();
|
||||
input.ref = "refs/heads/test";
|
||||
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("invalid tag name \"" + input.ref + "\"");
|
||||
tag(input.ref).create(input);
|
||||
BadRequestException thrown =
|
||||
assertThrows(BadRequestException.class, () -> tag(input.ref).create(input));
|
||||
assertThat(thrown).hasMessageThat().contains("invalid tag name \"" + input.ref + "\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -312,9 +315,9 @@ public class TagsIT extends AbstractDaemonTest {
|
||||
TagInput input = new TagInput();
|
||||
input.ref = "//";
|
||||
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("invalid tag name \"refs/tags/\"");
|
||||
tag(input.ref).create(input);
|
||||
BadRequestException thrown =
|
||||
assertThrows(BadRequestException.class, () -> tag(input.ref).create(input));
|
||||
assertThat(thrown).hasMessageThat().contains("invalid tag name \"refs/tags/\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -325,9 +328,9 @@ public class TagsIT extends AbstractDaemonTest {
|
||||
input.ref = "test";
|
||||
input.revision = "abcdefg";
|
||||
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("Invalid base revision");
|
||||
tag(input.ref).create(input);
|
||||
BadRequestException thrown =
|
||||
assertThrows(BadRequestException.class, () -> tag(input.ref).create(input));
|
||||
assertThat(thrown).hasMessageThat().contains("Invalid base revision");
|
||||
}
|
||||
|
||||
private void assertTagList(FluentIterable<String> expected, List<TagInfo> actual)
|
||||
|
||||
Reference in New Issue
Block a user