EA-81551 Check that list of colors isn't empty, so that EnumSet#copyOf accepts it
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Mon, 18 Apr 2016 11:42:12 +0000 (14:42 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Tue, 19 Apr 2016 11:16:39 +0000 (14:16 +0300)
plugins/tasks/tasks-core/src/com/intellij/tasks/trello/model/TrelloCard.java
plugins/tasks/tasks-tests/test/com/intellij/tasks/integration/live/TrelloIntegrationTest.java

index 137c82a9fb7038fdbb77c9c17cd264d839abc362..0a1d4bb5d715f7c2eb5d18756572204a755aa159 100644 (file)
@@ -17,7 +17,6 @@
 package com.intellij.tasks.trello.model;
 
 import com.google.gson.annotations.SerializedName;
-import com.intellij.util.Function;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.xmlb.annotations.Attribute;
 import org.jetbrains.annotations.NotNull;
@@ -131,13 +130,11 @@ public class TrelloCard extends TrelloModel {
     if (labels == null || labels.isEmpty()) {
       return EnumSet.noneOf(LabelColor.class);
     }
-    return EnumSet.copyOf(ContainerUtil.mapNotNull(labels, new Function<TrelloLabel, LabelColor>() {
-      @Override
-      public LabelColor fun(TrelloLabel label) {
-        final LabelColor color = label.getColor();
-        return color == LabelColor.NO_COLOR ? null : color;
-      }
-    }));
+    final List<LabelColor> labelColors = ContainerUtil.mapNotNull(labels, label -> {
+      final LabelColor color = label.getColor();
+      return color == LabelColor.NO_COLOR ? null : color;
+    });
+    return labelColors.isEmpty() ? EnumSet.noneOf(LabelColor.class) : EnumSet.copyOf(labelColors);
   }
 
   public boolean isVisible() {
index 8ad9d30c059b83127d5c2f8a4fad9b8735d1b770..06ffed3f2f1e9fb443bae6f744db3bed487a14a8 100644 (file)
@@ -38,7 +38,8 @@ public class TrelloIntegrationTest extends LiveIntegrationTestCase<TrelloReposit
   // Labels and colors
   private static final String LABELS_AND_COLORS_BOARD_NAME = "Labels and Colors";
   private static final String COLORED_CARD_ID = "548591e00f3d598512ced37b";
-
+  private static final String CARD_WITH_COLORLESS_LABELS_ID = "5714ccd9f6ab69c4de522346";
+  
   // State updates
   private static final String STATE_UPDATES_BOARD_NAME = "State Updates";
   private static final String STATE_UPDATES_BOARD_ID = "54b3e0e3b4f415b3c9d03449";
@@ -170,16 +171,22 @@ public class TrelloIntegrationTest extends LiveIntegrationTestCase<TrelloReposit
     final List<TrelloLabel> labels = card.getLabels();
 
     assertEquals(6, labels.size());
-    final Set<String> labelNames = ContainerUtil.map2Set(labels, new Function<TrelloLabel, String>() {
-      @Override
-      public String fun(TrelloLabel label) {
-        return label.getName();
-      }
-    });
-    assertEquals(ContainerUtil.newHashSet("Sky colored label", "Boring label", "Dull label", ""), labelNames);
+    final Set<String> labelNames = ContainerUtil.map2Set(labels, TrelloLabel::getName);
+    assertSameElements(labelNames, "Sky colored label", "Boring label", "Dull label", "");
 
     assertEquals(EnumSet.of(SKY, LIME, PINK, BLACK), card.getColors());
   }
+  
+  // EA-81551
+  public void testAllLabelsWithoutColor() throws Exception {
+    final TrelloCard card = myRepository.fetchCardById(CARD_WITH_COLORLESS_LABELS_ID);
+    assertNotNull(card);
+    final List<TrelloLabel> labels = card.getLabels();
+    assertSize(2, labels);
+    final List<String> labelNames = ContainerUtil.map(labels, TrelloLabel::getName);
+    assertSameElements(labelNames, "Boring label", "Dull label");
+    assertEmpty(card.getColors());
+  }
 
   public void testStateUpdates() throws Exception {
     TrelloCard card = myRepository.fetchCardById(FEATURE_CARD_ID);
@@ -226,7 +233,9 @@ public class TrelloIntegrationTest extends LiveIntegrationTestCase<TrelloReposit
     assertEquals(CARD_1_1_1_NUMBER, new TrelloTask(card, myRepository).getNumber());
   }
 
-  static void assertObjectsNamed(@NotNull String message, @NotNull Collection<? extends TrelloModel> objects, @NotNull String... names) {
+  private static void assertObjectsNamed(@NotNull String message,
+                                         @NotNull Collection<? extends TrelloModel> objects,
+                                         @NotNull String... names) {
     assertEquals(message, ContainerUtil.newHashSet(names), ContainerUtil.map2Set(objects, new Function<TrelloModel, String>() {
       @Override
       public String fun(TrelloModel model) {