Merge changes Ia4cd7ff1,I565375da

* changes:
  GetUsername: Remove unused 'self' member variable
  ChangeEditIT: Fix incorrect usage of ExpectedException
This commit is contained in:
Edwin Kempin
2016-01-13 21:22:24 +00:00
committed by Gerrit Code Review
2 changed files with 14 additions and 20 deletions

View File

@@ -317,13 +317,25 @@ public class ChangeEditIT extends AbstractDaemonTest {
edit.get().getEditCommit().getFullMessage()); edit.get().getEditCommit().getFullMessage());
} }
@Test
public void updateMessageOnlyAddTrailingNewLines() throws Exception {
assertThat(modifier.createEdit(change, getCurrentPatchSet(changeId)))
.isEqualTo(RefUpdate.Result.NEW);
Optional<ChangeEdit> edit = editUtil.byChange(change);
exception.expect(UnchangedCommitMessageException.class);
exception.expectMessage(
"New commit message cannot be same as existing commit message");
modifier.modifyMessage(
edit.get(),
edit.get().getEditCommit().getFullMessage() + "\n\n");
}
@Test @Test
public void updateMessage() throws Exception { public void updateMessage() throws Exception {
assertThat(modifier.createEdit(change, getCurrentPatchSet(changeId))) assertThat(modifier.createEdit(change, getCurrentPatchSet(changeId)))
.isEqualTo(RefUpdate.Result.NEW); .isEqualTo(RefUpdate.Result.NEW);
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
assertUnchangedMessage(edit, edit.get().getEditCommit().getFullMessage());
assertUnchangedMessage(edit, edit.get().getEditCommit().getFullMessage() + "\n\n");
String msg = String.format("New commit message\n\nChange-Id: %s\n", String msg = String.format("New commit message\n\nChange-Id: %s\n",
change.getKey()); change.getKey());
assertThat(modifier.modifyMessage(edit.get(), msg)).isEqualTo( assertThat(modifier.modifyMessage(edit.get(), msg)).isEqualTo(
@@ -672,14 +684,6 @@ public class ChangeEditIT extends AbstractDaemonTest {
assertThat(approvals.get(0).value).isEqualTo(1); assertThat(approvals.get(0).value).isEqualTo(1);
} }
private void assertUnchangedMessage(Optional<ChangeEdit> edit, String message)
throws Exception {
exception.expect(UnchangedCommitMessageException.class);
exception.expectMessage(
"New commit message cannot be same as existing commit message");
modifier.modifyMessage(edit.get(), message);
}
@Test @Test
public void testHasEditPredicate() throws Exception { public void testHasEditPredicate() throws Exception {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW); assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);

View File

@@ -17,21 +17,11 @@ package com.google.gerrit.server.account;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.CurrentUser;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@Singleton @Singleton
public class GetUsername implements RestReadView<AccountResource> { public class GetUsername implements RestReadView<AccountResource> {
private final Provider<CurrentUser> self;
@Inject
GetUsername(Provider<CurrentUser> self) {
this.self = self;
}
@Override @Override
public String apply(AccountResource rsrc) throws AuthException, public String apply(AccountResource rsrc) throws AuthException,
ResourceNotFoundException { ResourceNotFoundException {