IdEnumSupport extends AttributeDefinitionEnumSupport { @NotNull @Override public List<ValueWithDisplayString> getAllValues() { List<ValueWithDisplayString> values = myIdAnalyzer.findIds().stream() .map(id -> new ValueWithDisplayString(isEnumValue(id) ? NEW_ID_PREFIX + id : id, NEW_ID_PREFIX + id)) .collect(Collectors.toList()); addAttributeDefinitionValues(values); return values; } IdEnumSupport(@NotNull NlProperty property); @VisibleForTesting  IdEnumSupport(@NotNull NlProperty property, @NotNull IdAnalyzer analyzer); @NotNull @Override List<ValueWithDisplayString> getAllValues();  }
@Test public void testFindPossibleValues() { when(myIdAnalyzer.findIds()).thenReturn(ImmutableList.of("id1", "id2")); assertThat(mySupport.getAllValues()).containsExactly( new ValueWithDisplayString("id1", "@+id/id1"), new ValueWithDisplayString("id2", "@+id/id2")).inOrder(); }
@Test public void testFindPossibleValuesFromConstraintLayoutProperty() { myDefinition.setValueMappings(ImmutableMap.of(SdkConstants.ATTR_PARENT, 1)); when(myIdAnalyzer.findIds()).thenReturn(ImmutableList.of("id1", "id2")); assertThat(mySupport.getAllValues()).containsExactly( new ValueWithDisplayString("id1", "@+id/id1"), new ValueWithDisplayString("id2", "@+id/id2"), new ValueWithDisplayString("parent", "parent")).inOrder(); }
@Test public void testFindPossibleValuesFromConstraintLayoutPropertyAndExistingParentId() { myDefinition.setValueMappings(ImmutableMap.of(SdkConstants.ATTR_PARENT, 1)); when(myIdAnalyzer.findIds()).thenReturn(ImmutableList.of("id1", "id2", "parent")); assertThat(mySupport.getAllValues()).containsExactly( new ValueWithDisplayString("id1", "@+id/id1"), new ValueWithDisplayString("id2", "@+id/id2"), new ValueWithDisplayString("@+id/parent", "@+id/parent"), new ValueWithDisplayString("parent", "parent")).inOrder(); }