FetchDeviceInfoAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { AirshipLocationClient locationClient = UAirship.shared().getLocationClient(); JsonMap.Builder properties = JsonMap.newBuilder() .put(CHANNEL_ID_KEY, UAirship.shared().getChannel().getId()) .put(PUSH_OPT_IN_KEY, UAirship.shared().getPushManager().isOptIn()) .put(LOCATION_ENABLED_KEY, locationClient != null && locationClient.isLocationUpdatesEnabled()) .putOpt(NAMED_USER_ID_KEY, UAirship.shared().getNamedUser().getId()); Set<String> tags = UAirship.shared().getChannel().getTags(); if (!tags.isEmpty()) { properties.put(TAGS_KEY, JsonValue.wrapOpt(tags)); } return ActionResult.newResult(new ActionValue(properties.build().toJsonValue())); }  @NonNull @Override ActionResult perform(@NonNull ActionArguments arguments); @NonNull
    static final String DEFAULT_REGISTRY_NAME; @NonNull
    static final String DEFAULT_REGISTRY_SHORT_NAME; @NonNull
    static final String CHANNEL_ID_KEY; @NonNull
    static final String NAMED_USER_ID_KEY; @NonNull
    static final String TAGS_KEY; @NonNull
    static final String PUSH_OPT_IN_KEY; @NonNull
    static final String LOCATION_ENABLED_KEY; }
@Test public void testPerform() throws JsonException { List<String> tags = Arrays.asList("tag1", "tag2"); String channelId = "channel_id"; String namedUserId = "named_user"; when(airshipChannel.getId()).thenReturn(channelId); when(pushManager.isOptIn()).thenReturn(true); when(airshipChannel.getTags()).thenReturn(new HashSet<>(tags)); when(locationClient.isLocationUpdatesEnabled()).thenReturn(true); when(namedUser.getId()).thenReturn(namedUserId); JsonMap result = action.perform(ActionTestUtils.createArgs(Action.SITUATION_MANUAL_INVOCATION, null)).getValue().getMap(); assertEquals(channelId, result.get(FetchDeviceInfoAction.CHANNEL_ID_KEY).getString()); assertEquals(true, result.get(FetchDeviceInfoAction.PUSH_OPT_IN_KEY).getBoolean(false)); assertEquals(JsonValue.wrap(tags), result.get(FetchDeviceInfoAction.TAGS_KEY)); assertEquals(true, result.get(FetchDeviceInfoAction.LOCATION_ENABLED_KEY).getBoolean(false)); assertEquals(namedUserId, result.get(FetchDeviceInfoAction.NAMED_USER_ID_KEY).getString()); }
@Test public void testPerformWithoutTags() throws JsonException { String channelId = "channel_id"; String namedUserId = "named_user"; when(airshipChannel.getId()).thenReturn(channelId); when(pushManager.isOptIn()).thenReturn(true); when(airshipChannel.getTags()).thenReturn(new HashSet<String>()); when(locationClient.isLocationUpdatesEnabled()).thenReturn(true); when(namedUser.getId()).thenReturn(namedUserId); JsonMap result = action.perform(ActionTestUtils.createArgs(Action.SITUATION_MANUAL_INVOCATION, null)).getValue().getMap(); assertEquals(channelId, result.get(FetchDeviceInfoAction.CHANNEL_ID_KEY).getString()); assertEquals(true, result.get(FetchDeviceInfoAction.PUSH_OPT_IN_KEY).getBoolean(false)); assertNull(result.get(FetchDeviceInfoAction.TAGS_KEY)); assertEquals(true, result.get(FetchDeviceInfoAction.LOCATION_ENABLED_KEY).getBoolean(false)); assertEquals(namedUserId, result.get(FetchDeviceInfoAction.NAMED_USER_ID_KEY).getString()); }