View Javadoc

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