### Question:
MajorityVoteAlgorithm { public static int findMajorityElement(int[] sequence) { if (sequence == null || sequence.length == 0) { throw new IllegalArgumentException("Input array is null or empty"); } int cnt = 0; int currentElement = 0; for (int element : sequence) { if (cnt == 0) { currentElement = element; cnt = 1; } else if (element == currentElement) { cnt++; } else { cnt--; } } int occurrence = 0; for (int element : sequence) { if (element == currentElement) { occurrence++; } } if (occurrence << 1 >= sequence.length) { return currentElement; } else { throw new IllegalArgumentException("Input array does not have majority element"); } }  static int findMajorityElement(int[] sequence);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testFindMajorityElementNullArray() { findMajorityElement(null); }
@Test(expected = IllegalArgumentException.class) public void testFindMajorityElementEmptyArray() { findMajorityElement(new int[0]); }
@Test(expected = IllegalArgumentException.class) public void testFindMajorityElementNoMajorityElement() { findMajorityElement(new int[]{1, 2, 3, 4, 5, 1, 1, 1, 3}); }
@Test public void testFindMajorityElement1() { assertThat(findMajorityElement(new int[]{10}), is(10)); }
@Test public void testFindMajorityElement2() { assertThat(findMajorityElement(new int[]{9, 10}), is(9)); }
@Test public void testFindMajorityElement3() { assertThat(findMajorityElement(new int[]{9, 10, 10, 11}), is(10)); }
@Test public void testFindMajorityElement4() { assertThat(findMajorityElement(new int[]{1, 2, 1, 4, 1, 1, 2, 1, 3}), is(1)); }
@Test public void testFindMajorityElement5() { assertThat(findMajorityElement(new int[]{5, 5, 2, 3, 4, 5, 6, 5, 7, 5, 5, 5, 3}), is(5)); }