DefaultQuotaBackendIT: Migrate to assertThrows
Change-Id: Id18b88bba294708dfc3817c3824f4fab38591926
This commit is contained in:
@@ -37,9 +37,7 @@ import com.google.inject.Module;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
public class DefaultQuotaBackendIT extends AbstractDaemonTest {
|
public class DefaultQuotaBackendIT extends AbstractDaemonTest {
|
||||||
|
|
||||||
@@ -48,8 +46,6 @@ public class DefaultQuotaBackendIT extends AbstractDaemonTest {
|
|||||||
private IdentifiedUser identifiedAdmin;
|
private IdentifiedUser identifiedAdmin;
|
||||||
@Inject private QuotaBackend quotaBackend;
|
@Inject private QuotaBackend quotaBackend;
|
||||||
|
|
||||||
@Rule public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Module createModule() {
|
public Module createModule() {
|
||||||
return new FactoryModule() {
|
return new FactoryModule() {
|
||||||
@@ -205,9 +201,8 @@ public class DefaultQuotaBackendIT extends AbstractDaemonTest {
|
|||||||
QuotaResponse.Aggregated result =
|
QuotaResponse.Aggregated result =
|
||||||
quotaBackend.user(identifiedAdmin).availableTokens("testGroup");
|
quotaBackend.user(identifiedAdmin).availableTokens("testGroup");
|
||||||
assertThat(result).isEqualTo(singletonAggregation(QuotaResponse.error("failed")));
|
assertThat(result).isEqualTo(singletonAggregation(QuotaResponse.error("failed")));
|
||||||
exception.expect(QuotaException.class);
|
QuotaException thrown = assertThrows(QuotaException.class, () -> result.throwOnError());
|
||||||
exception.expectMessage("failed");
|
assertThat(thrown).hasMessageThat().contains("failed");
|
||||||
result.throwOnError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -215,6 +210,7 @@ public class DefaultQuotaBackendIT extends AbstractDaemonTest {
|
|||||||
QuotaRequestContext ctx = QuotaRequestContext.builder().user(identifiedAdmin).build();
|
QuotaRequestContext ctx = QuotaRequestContext.builder().user(identifiedAdmin).build();
|
||||||
expect(quotaEnforcer.requestTokens("testGroup", ctx, 1)).andThrow(new NullPointerException());
|
expect(quotaEnforcer.requestTokens("testGroup", ctx, 1)).andThrow(new NullPointerException());
|
||||||
replay(quotaEnforcer);
|
replay(quotaEnforcer);
|
||||||
|
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NullPointerException.class,
|
NullPointerException.class,
|
||||||
() -> quotaBackend.user(identifiedAdmin).requestToken("testGroup"));
|
() -> quotaBackend.user(identifiedAdmin).requestToken("testGroup"));
|
||||||
@@ -226,8 +222,9 @@ public class DefaultQuotaBackendIT extends AbstractDaemonTest {
|
|||||||
expect(quotaEnforcer.availableTokens("testGroup", ctx)).andThrow(new NullPointerException());
|
expect(quotaEnforcer.availableTokens("testGroup", ctx)).andThrow(new NullPointerException());
|
||||||
replay(quotaEnforcer);
|
replay(quotaEnforcer);
|
||||||
|
|
||||||
exception.expect(NullPointerException.class);
|
assertThrows(
|
||||||
quotaBackend.user(identifiedAdmin).availableTokens("testGroup");
|
NullPointerException.class,
|
||||||
|
() -> quotaBackend.user(identifiedAdmin).availableTokens("testGroup"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Change.Id retrieveChangeId() throws Exception {
|
private Change.Id retrieveChangeId() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user