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      public void testTheHashCodeOfADescriptorWithANullCompleteKeyShouldBeZero() {
18          final ModuleDescriptor descriptor = mock(ModuleDescriptor.class);
19  
20          when(descriptor.getCompleteKey()).thenReturn(null);
21  
22          assertEquals(new ModuleDescriptors.HashCodeBuilder().descriptor(descriptor).toHashCode(), 0);
23      }
24  
25      public void testTheHashCodeOfADescriptorWithANonNullCompleteKeyIsEqualToTheHashCodeOfTheCompleteKey() {
26          final ModuleDescriptor descriptor = mock(ModuleDescriptor.class);
27  
28          when(descriptor.getCompleteKey()).thenReturn("test-plugin:test-key");
29  
30          assertEquals
31                  (
32                          new ModuleDescriptors.HashCodeBuilder().descriptor(descriptor).toHashCode(),
33                          descriptor.getCompleteKey().hashCode()
34                  );
35      }
36  }
37