Resolve warnings and accept suggestions throughout `DeviceControllerTest`
This commit is contained in:
parent
7b1b6fa1cf
commit
38d25f9a9b
|
@ -28,7 +28,6 @@ import io.dropwizard.testing.junit5.ResourceExtension;
|
||||||
import io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands;
|
import io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands;
|
||||||
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
|
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -91,22 +90,24 @@ import org.whispersystems.textsecuregcm.util.LinkDeviceToken;
|
||||||
@ExtendWith(DropwizardExtensionsSupport.class)
|
@ExtendWith(DropwizardExtensionsSupport.class)
|
||||||
class DeviceControllerTest {
|
class DeviceControllerTest {
|
||||||
|
|
||||||
private static AccountsManager accountsManager = mock(AccountsManager.class);
|
private static final AccountsManager accountsManager = mock(AccountsManager.class);
|
||||||
private static ClientPublicKeysManager clientPublicKeysManager = mock(ClientPublicKeysManager.class);
|
private static final ClientPublicKeysManager clientPublicKeysManager = mock(ClientPublicKeysManager.class);
|
||||||
private static RateLimiters rateLimiters = mock(RateLimiters.class);
|
private static final RateLimiters rateLimiters = mock(RateLimiters.class);
|
||||||
private static RateLimiter rateLimiter = mock(RateLimiter.class);
|
private static final RateLimiter rateLimiter = mock(RateLimiter.class);
|
||||||
private static RedisAdvancedClusterCommands<String, String> commands = mock(RedisAdvancedClusterCommands.class);
|
@SuppressWarnings("unchecked")
|
||||||
private static RedisAdvancedClusterAsyncCommands<String, String> asyncCommands = mock(RedisAdvancedClusterAsyncCommands.class);
|
private static final RedisAdvancedClusterCommands<String, String> commands = mock(RedisAdvancedClusterCommands.class);
|
||||||
private static Account account = mock(Account.class);
|
@SuppressWarnings("unchecked")
|
||||||
private static Account maxedAccount = mock(Account.class);
|
private static final RedisAdvancedClusterAsyncCommands<String, String> asyncCommands = mock(RedisAdvancedClusterAsyncCommands.class);
|
||||||
private static Device primaryDevice = mock(Device.class);
|
private static final Account account = mock(Account.class);
|
||||||
private static ClientPresenceManager clientPresenceManager = mock(ClientPresenceManager.class);
|
private static final Account maxedAccount = mock(Account.class);
|
||||||
private static Map<String, Integer> deviceConfiguration = new HashMap<>();
|
private static final Device primaryDevice = mock(Device.class);
|
||||||
private static TestClock testClock = TestClock.now();
|
private static final ClientPresenceManager clientPresenceManager = mock(ClientPresenceManager.class);
|
||||||
|
private static final Map<String, Integer> deviceConfiguration = new HashMap<>();
|
||||||
|
private static final TestClock testClock = TestClock.now();
|
||||||
|
|
||||||
private static final byte NEXT_DEVICE_ID = 42;
|
private static final byte NEXT_DEVICE_ID = 42;
|
||||||
|
|
||||||
private static DeviceController deviceController = new DeviceController(
|
private static final DeviceController deviceController = new DeviceController(
|
||||||
accountsManager,
|
accountsManager,
|
||||||
clientPublicKeysManager,
|
clientPublicKeysManager,
|
||||||
rateLimiters,
|
rateLimiters,
|
||||||
|
@ -820,27 +821,31 @@ class DeviceControllerTest {
|
||||||
@Test
|
@Test
|
||||||
void putCapabilitiesSuccessTest() {
|
void putCapabilitiesSuccessTest() {
|
||||||
final DeviceCapabilities deviceCapabilities = new DeviceCapabilities(true, true, false, false);
|
final DeviceCapabilities deviceCapabilities = new DeviceCapabilities(true, true, false, false);
|
||||||
final Response response = resources
|
try (final Response response = resources
|
||||||
.getJerseyTest()
|
.getJerseyTest()
|
||||||
.target("/v1/devices/capabilities")
|
.target("/v1/devices/capabilities")
|
||||||
.request()
|
.request()
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30")
|
.header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30")
|
||||||
.put(Entity.entity(deviceCapabilities, MediaType.APPLICATION_JSON_TYPE));
|
.put(Entity.entity(deviceCapabilities, MediaType.APPLICATION_JSON_TYPE))) {
|
||||||
assertThat(response.getStatus()).isEqualTo(204);
|
|
||||||
assertThat(response.hasEntity()).isFalse();
|
assertThat(response.getStatus()).isEqualTo(204);
|
||||||
|
assertThat(response.hasEntity()).isFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void putCapabilitiesFailureTest() {
|
void putCapabilitiesFailureTest() {
|
||||||
final Response response = resources
|
try (final Response response = resources
|
||||||
.getJerseyTest()
|
.getJerseyTest()
|
||||||
.target("/v1/devices/capabilities")
|
.target("/v1/devices/capabilities")
|
||||||
.request()
|
.request()
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30")
|
.header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30")
|
||||||
.put(Entity.json(""));
|
.put(Entity.json(""))) {
|
||||||
assertThat(response.getStatus()).isEqualTo(422);
|
|
||||||
|
assertThat(response.getStatus()).isEqualTo(422);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -854,18 +859,19 @@ class DeviceControllerTest {
|
||||||
when(accountsManager.removeDevice(AuthHelper.VALID_ACCOUNT, deviceId))
|
when(accountsManager.removeDevice(AuthHelper.VALID_ACCOUNT, deviceId))
|
||||||
.thenReturn(CompletableFuture.completedFuture(AuthHelper.VALID_ACCOUNT));
|
.thenReturn(CompletableFuture.completedFuture(AuthHelper.VALID_ACCOUNT));
|
||||||
|
|
||||||
final Response response = resources
|
try (final Response response = resources
|
||||||
.getJerseyTest()
|
.getJerseyTest()
|
||||||
.target("/v1/devices/" + deviceId)
|
.target("/v1/devices/" + deviceId)
|
||||||
.request()
|
.request()
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||||
.header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30")
|
.header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30")
|
||||||
.delete();
|
.delete()) {
|
||||||
|
|
||||||
assertThat(response.getStatus()).isEqualTo(204);
|
assertThat(response.getStatus()).isEqualTo(204);
|
||||||
assertThat(response.hasEntity()).isFalse();
|
assertThat(response.hasEntity()).isFalse();
|
||||||
|
|
||||||
verify(accountsManager).removeDevice(AuthHelper.VALID_ACCOUNT, deviceId);
|
verify(accountsManager).removeDevice(AuthHelper.VALID_ACCOUNT, deviceId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -894,18 +900,19 @@ class DeviceControllerTest {
|
||||||
when(accountsManager.removeDevice(AuthHelper.VALID_ACCOUNT_3, deviceId))
|
when(accountsManager.removeDevice(AuthHelper.VALID_ACCOUNT_3, deviceId))
|
||||||
.thenReturn(CompletableFuture.completedFuture(AuthHelper.VALID_ACCOUNT));
|
.thenReturn(CompletableFuture.completedFuture(AuthHelper.VALID_ACCOUNT));
|
||||||
|
|
||||||
final Response response = resources
|
try (final Response response = resources
|
||||||
.getJerseyTest()
|
.getJerseyTest()
|
||||||
.target("/v1/devices/" + deviceId)
|
.target("/v1/devices/" + deviceId)
|
||||||
.request()
|
.request()
|
||||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID_3, deviceId, AuthHelper.VALID_PASSWORD_3_LINKED))
|
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID_3, deviceId, AuthHelper.VALID_PASSWORD_3_LINKED))
|
||||||
.header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30")
|
.header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30")
|
||||||
.delete();
|
.delete()) {
|
||||||
|
|
||||||
assertThat(response.getStatus()).isEqualTo(204);
|
assertThat(response.getStatus()).isEqualTo(204);
|
||||||
assertThat(response.hasEntity()).isFalse();
|
assertThat(response.hasEntity()).isFalse();
|
||||||
|
|
||||||
verify(accountsManager).removeDevice(AuthHelper.VALID_ACCOUNT_3, deviceId);
|
verify(accountsManager).removeDevice(AuthHelper.VALID_ACCOUNT_3, deviceId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue