package ro.isdc.wro.util.provider;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import ro.isdc.wro.config.Context;
import ro.isdc.wro.util.Ordered;


public class TestProviderPriority {
  
  private static Ordered HIGH = new Ordered() {
    public int getOrder() {
      return Ordered.HIGHEST;
    }
  };
  private static Object MEDIUM = new Object();
  private static Ordered MEDIUM_HIGH = new Ordered() {
    public int getOrder() {
      return 10;
    }
  };
  private static Ordered LOW = new Ordered() {
    public int getOrder() {
      return Ordered.LOWEST;
    }
  };
  
  @BeforeClass
  public static void onBeforeClass() {
    assertEquals(0, Context.countActive());
  }
  
  @AfterClass
  public static void onAfterClass() {
    assertEquals(0, Context.countActive());
  }
  
  @Test
  public void shouldSortFromLowToHigh() {
    List<?> priorities = Arrays.asList(MEDIUM_HIGH, HIGH, LOW, MEDIUM, MEDIUM, HIGH, LOW, MEDIUM, HIGH);
    
    Collections.sort(priorities, Ordered.DESCENDING_COMPARATOR);
    
    assertEquals(Arrays.asList(LOW, LOW, MEDIUM, MEDIUM, MEDIUM, MEDIUM_HIGH, HIGH, HIGH, HIGH), priorities);
  }
  
  @Test
  public void shouldCompareSamePriorityEqually() {
    assertEquals(0, Ordered.DESCENDING_COMPARATOR.compare(LOW, LOW));
    assertEquals(0, Ordered.DESCENDING_COMPARATOR.compare(MEDIUM, MEDIUM));
    assertEquals(0, Ordered.DESCENDING_COMPARATOR.compare(HIGH, HIGH));
  }
}

@@ -343,18 +343,16 @@
 ority %7B%0A
-  
 %0A  priva
@@ -734,18 +734,16 @@
  %7D%0A  %7D;%0A
-  
 %0A  @Befo
@@ -833,26 +833,24 @@
 ive());%0A  %7D%0A
-  
 %0A  @AfterCla
@@ -934,26 +934,24 @@
 ive());%0A  %7D%0A
-  
 %0A  @Test%0A  p
@@ -993,16 +993,22 @@
 ) %7B%0A    
+final 
 List%3C?%3E 
@@ -1100,20 +1100,16 @@
  HIGH);%0A
-    
 %0A    Col
@@ -1166,20 +1166,16 @@
 RATOR);%0A
-    
 %0A    ass
@@ -1202,24 +1202,32 @@
 ist(
-LOW, LOW
+HIGH, HIGH, HIGH
 , MEDIUM
 , ME
@@ -1214,32 +1214,37 @@
 GH, HIGH, MEDIUM
+_HIGH
 , MEDIUM, MEDIUM
@@ -1255,31 +1255,18 @@
 DIUM
-_HIGH, HIGH, HIGH, HIGH
+, LOW, LOW
 ), p
@@ -1281,18 +1281,16 @@
 s);%0A  %7D%0A
-  
 %0A  @Test

fix failing test