View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config;
8   
9   import org.mule.tck.junit4.AbstractMuleTestCase;
10  
11  import org.junit.Before;
12  import org.junit.Test;
13  
14  import static org.junit.Assert.assertEquals;
15  import static org.mockito.Mockito.mock;
16  import static org.mockito.Mockito.when;
17  
18  public class PreferredComparatorTestCase extends AbstractMuleTestCase
19  {
20  
21      private PreferredComparator comparator;
22  
23      @Before
24      public void setUpComparator()
25      {
26          comparator = new PreferredComparator();
27      }
28  
29      @Test
30      public void testCompareEqualInstances()
31      {
32          Preferred preferred1 = mock(Preferred.class);
33          when(preferred1.weight()).thenReturn(1);
34  
35          Preferred preferred2 = mock(Preferred.class);
36          when(preferred2.weight()).thenReturn(1);
37  
38          assertEquals(0, comparator.compare(preferred1, preferred2));
39      }
40  
41      @Test
42      public void testCompareMinorThanInstance()
43      {
44          Preferred preferred1 = mock(Preferred.class);
45          when(preferred1.weight()).thenReturn(1);
46  
47          Preferred preferred2 = mock(Preferred.class);
48          when(preferred2.weight()).thenReturn(2);
49  
50          assertEquals(-1, comparator.compare(preferred1, preferred2));
51      }
52  
53      @Test
54      public void testCompareGreaterThanInstance()
55      {
56          Preferred preferred1 = mock(Preferred.class);
57          when(preferred1.weight()).thenReturn(2);
58  
59          Preferred preferred2 = mock(Preferred.class);
60          when(preferred2.weight()).thenReturn(1);
61  
62          assertEquals(1, comparator.compare(preferred1, preferred2));
63      }
64  }