### Question:
DeviceTokenValidator implements ConstraintValidator<DeviceTokenCheck, Installation> { public static boolean isValidDeviceTokenForVariant(final String deviceToken, final VariantType type) { switch (type) { case IOS: case IOS_TOKEN: return IOS_DEVICE_TOKEN.matcher(deviceToken).matches(); case ANDROID: return ANDROID_DEVICE_TOKEN.matcher(deviceToken).matches(); case WEB_PUSH: return isWebPushRegistration(deviceToken); } return false; }  @Override void initialize(DeviceTokenCheck constraintAnnotation); @Override boolean isValid(Installation installation, ConstraintValidatorContext context); static boolean isValidDeviceTokenForVariant(final String deviceToken, final VariantType type);  }### Answer:
@Test public void testValidToken() { final VariantType andVariantType = VariantType.ANDROID; assertThat(DeviceTokenValidator.isValidDeviceTokenForVariant("eHlfnI0__dI:APA91bEhtHefML2lr_sBQ-bdXIyEn5owzkZg_p_y7SRyNKRMZ3XuzZhBpTOYIh46tqRYQIc-7RTADk4nM5H-ONgPDWHodQDS24O5GuKP8EZEKwNh4Zxdv1wkZJh7cU2PoLz9gn4Nxqz-", andVariantType)).isTrue(); }
@Test public void testEmptyString() { final VariantType andVariantType = VariantType.ANDROID; assertThat(DeviceTokenValidator.isValidDeviceTokenForVariant("", andVariantType)).isFalse(); }
@Test public void testInvalidToken() { final VariantType andVariantType = VariantType.ANDROID; assertThat(DeviceTokenValidator.isValidDeviceTokenForVariant("some-bogus:token", andVariantType)).isFalse(); }
@Test public void testInvalidWebPush() { final Gson gson = new Gson(); final VariantType webPushType = VariantType.WEB_PUSH; assertThat(DeviceTokenValidator.isValidDeviceTokenForVariant("some-bogus:token", webPushType)).isFalse(); WebPushRegistration registration = new WebPushRegistration(); String registrationJson = Base64.getEncoder().encodeToString(gson.toJson(registration).getBytes()); assertThat(DeviceTokenValidator.isValidDeviceTokenForVariant(registrationJson, webPushType)).isFalse(); registration.setEndpoint("https: registrationJson = gson.toJson(registration); assertThat(DeviceTokenValidator.isValidDeviceTokenForVariant(registrationJson, webPushType)).isFalse(); }
@Test public void testValidWebPush() { final Gson gson = new Gson(); final VariantType webPushType = VariantType.WEB_PUSH; WebPushRegistration registration = new WebPushRegistration(); registration.setEndpoint("https: registration.getKeys().setAuth("authTokens"); registration.getKeys().setP256dh("devicePublicKey"); String registrationJson = Base64.getEncoder().encodeToString(gson.toJson(registration).getBytes()); assertThat(DeviceTokenValidator.isValidDeviceTokenForVariant(registrationJson, webPushType)).isTrue(); }