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