@Override
  public DeviceLastSeenState getState(@Nullable final Account account, @Nullable final Device device) {
    if (account != null && device != null) {
      final DeviceLastSeenState.PushTokenType pushTokenType;

      if (StringUtils.isNotBlank(device.getApnId())) {
        pushTokenType = DeviceLastSeenState.PushTokenType.APNS;
      } else if (StringUtils.isNotBlank(device.getGcmId())) {
        pushTokenType = DeviceLastSeenState.PushTokenType.FCM;
      } else {
        pushTokenType = null;
      }

      return new DeviceLastSeenState(true, device.getCreated(), hasPushToken(device), device.getLastSeen(), pushTokenType);
    } else {
      return DeviceLastSeenState.MISSING_DEVICE_STATE;
    }
  }
@Test
  void getState() {
    final IdleDevicePushNotificationExperiment experiment = getExperiment();

    assertEquals(DeviceLastSeenState.MISSING_DEVICE_STATE, experiment.getState(null, null));
    assertEquals(DeviceLastSeenState.MISSING_DEVICE_STATE, experiment.getState(mock(Account.class), null));

    final long createdAtMillis = CURRENT_TIME.minus(Duration.ofDays(14)).toEpochMilli();

    {
      final Device apnsDevice = mock(Device.class);
      when(apnsDevice.getApnId()).thenReturn("apns-token");
      when(apnsDevice.getCreated()).thenReturn(createdAtMillis);
      when(apnsDevice.getLastSeen()).thenReturn(CURRENT_TIME.toEpochMilli());

      assertEquals(
          new DeviceLastSeenState(true, createdAtMillis, true, CURRENT_TIME.toEpochMilli(), DeviceLastSeenState.PushTokenType.APNS),
          experiment.getState(mock(Account.class), apnsDevice));
    }

    {
      final Device fcmDevice = mock(Device.class);
      when(fcmDevice.getGcmId()).thenReturn("fcm-token");
      when(fcmDevice.getCreated()).thenReturn(createdAtMillis);
      when(fcmDevice.getLastSeen()).thenReturn(CURRENT_TIME.toEpochMilli());

      assertEquals(
          new DeviceLastSeenState(true, createdAtMillis, true, CURRENT_TIME.toEpochMilli(), DeviceLastSeenState.PushTokenType.FCM),
          experiment.getState(mock(Account.class), fcmDevice));
    }

    {
      final Device noTokenDevice = mock(Device.class);
      when(noTokenDevice.getCreated()).thenReturn(createdAtMillis);
      when(noTokenDevice.getLastSeen()).thenReturn(CURRENT_TIME.toEpochMilli());

      assertEquals(
          new DeviceLastSeenState(true, createdAtMillis, false, CURRENT_TIME.toEpochMilli(), null),
          experiment.getState(mock(Account.class), noTokenDevice));
    }
  }