Migrate StickerControllerTest to JUnit 5

This commit is contained in:
Chris Eager 2021-07-23 13:25:54 -05:00 committed by Chris Eager
parent 8f41176c76
commit f971c76a99
1 changed files with 18 additions and 19 deletions

View File

@ -14,14 +14,14 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider; import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider;
import io.dropwizard.testing.junit.ResourceTestRule; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import java.io.IOException; import io.dropwizard.testing.junit5.ResourceExtension;
import java.util.Base64; import java.util.Base64;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory; import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.ClassRule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith;
import org.whispersystems.textsecuregcm.auth.DisabledPermittedAccount; import org.whispersystems.textsecuregcm.auth.DisabledPermittedAccount;
import org.whispersystems.textsecuregcm.controllers.RateLimitExceededException; import org.whispersystems.textsecuregcm.controllers.RateLimitExceededException;
import org.whispersystems.textsecuregcm.controllers.StickerController; import org.whispersystems.textsecuregcm.controllers.StickerController;
@ -32,27 +32,27 @@ import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.tests.util.AuthHelper; import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
import org.whispersystems.textsecuregcm.util.SystemMapper; import org.whispersystems.textsecuregcm.util.SystemMapper;
public class StickerControllerTest { @ExtendWith(DropwizardExtensionsSupport.class)
class StickerControllerTest {
private static RateLimiter rateLimiter = mock(RateLimiter.class ); private static RateLimiter rateLimiter = mock(RateLimiter.class );
private static RateLimiters rateLimiters = mock(RateLimiters.class); private static RateLimiters rateLimiters = mock(RateLimiters.class);
@ClassRule private static final ResourceExtension resources = ResourceExtension.builder()
public static final ResourceTestRule resources = ResourceTestRule.builder() .addProvider(AuthHelper.getAuthFilter())
.addProvider(AuthHelper.getAuthFilter()) .addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(Account.class, DisabledPermittedAccount.class)))
.addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(Account.class, DisabledPermittedAccount.class))) .setMapper(SystemMapper.getMapper())
.setMapper(SystemMapper.getMapper()) .setTestContainerFactory(new GrizzlyWebTestContainerFactory())
.setTestContainerFactory(new GrizzlyWebTestContainerFactory()) .addResource(new StickerController(rateLimiters, "foo", "bar", "us-east-1", "mybucket"))
.addResource(new StickerController(rateLimiters, "foo", "bar", "us-east-1", "mybucket")) .build();
.build();
@Before @BeforeEach
public void setup() { void setup() {
when(rateLimiters.getStickerPackLimiter()).thenReturn(rateLimiter); when(rateLimiters.getStickerPackLimiter()).thenReturn(rateLimiter);
} }
@Test @Test
public void testCreatePack() throws RateLimitExceededException, IOException { void testCreatePack() throws RateLimitExceededException {
StickerPackFormUploadAttributes attributes = resources.getJerseyTest() StickerPackFormUploadAttributes attributes = resources.getJerseyTest()
.target("/v1/sticker/pack/form/10") .target("/v1/sticker/pack/form/10")
.request() .request()
@ -90,7 +90,7 @@ public class StickerControllerTest {
} }
@Test @Test
public void testCreateTooLargePack() throws Exception { void testCreateTooLargePack() {
Response response = resources.getJerseyTest() Response response = resources.getJerseyTest()
.target("/v1/sticker/pack/form/202") .target("/v1/sticker/pack/form/202")
.request() .request()
@ -98,7 +98,6 @@ public class StickerControllerTest {
.get(); .get();
assertThat(response.getStatus()).isEqualTo(400); assertThat(response.getStatus()).isEqualTo(400);
} }
} }