View Javadoc

1   package com.atlassian.plugin.descriptors;
2   
3   import com.atlassian.plugin.ModuleDescriptor;
4   import junit.framework.TestCase;
5   
6   import static org.mockito.Mockito.mock;
7   import static org.mockito.Mockito.when;
8   
9   /**
10   * Responsible for testing that the <tt>hashCode</tt> contract defined by
11   * {@link com.atlassian.plugin.ModuleDescriptor#hashCode()} is fulfilled by the
12   * {@link ModuleDescriptors.HashCodeBuilder} class.
13   *
14   * @since 2.8.0
15   */
16  public class TestModuleDescriptorsHashCodeBuilder extends TestCase
17  {
18      public void testTheHashCodeOfADescriptorWithANullCompleteKeyShouldBeZero()
19      {
20          final ModuleDescriptor descriptor = mock(ModuleDescriptor.class);
21  
22          when(descriptor.getCompleteKey()).thenReturn(null);
23  
24          assertEquals(new ModuleDescriptors.HashCodeBuilder().descriptor(descriptor).toHashCode(), 0);
25      }
26  
27      public void testTheHashCodeOfADescriptorWithANonNullCompleteKeyIsEqualToTheHashCodeOfTheCompleteKey()
28      {
29          final ModuleDescriptor descriptor = mock(ModuleDescriptor.class);
30  
31          when(descriptor.getCompleteKey()).thenReturn("test-plugin:test-key");
32  
33          assertEquals
34                  (
35                          new ModuleDescriptors.HashCodeBuilder().descriptor(descriptor).toHashCode(),
36                          descriptor.getCompleteKey().hashCode()
37                  );
38      }
39  }
40