/*
 * Copyright 2018-present Open Networking Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.atomix.primitive.partition;

import io.atomix.cluster.MemberId;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * Primary term test.
 */
public class PrimaryTermTest {
  @Test
  public void testPrimaryTerm() throws Exception {
    GroupMember primary = new GroupMember(MemberId.from("1"), MemberGroupId.from("1"));
    List<GroupMember> candidates = Arrays.asList(
        new GroupMember(MemberId.from("2"), MemberGroupId.from("2")),
        new GroupMember(MemberId.from("3"), MemberGroupId.from("2")),
        new GroupMember(MemberId.from("4"), MemberGroupId.from("3")),
        new GroupMember(MemberId.from("5"), MemberGroupId.from("3")));

    PrimaryTerm term = new PrimaryTerm(1, primary, candidates);
    assertEquals(primary, term.primary());
    assertEquals(candidates, term.candidates());

    assertEquals(Arrays.asList(), term.backups(0));
    assertEquals(Arrays.asList(candidates.get(0)), term.backups(1));
    assertEquals(Arrays.asList(candidates.get(0), candidates.get(2)), term.backups(2));
    assertEquals(Arrays.asList(candidates.get(0), candidates.get(2), candidates.get(1)), term.backups(3));
    assertEquals(Arrays.asList(candidates.get(0), candidates.get(2), candidates.get(1), candidates.get(3)), term.backups(4));
    assertEquals(Arrays.asList(candidates.get(0), candidates.get(2), candidates.get(1), candidates.get(3)), term.backups(5));
  }
}

@@ -1059,16 +1059,86 @@
 asList(%0A
+        new GroupMember(MemberId.from(%221%22), MemberGroupId.from(%221%22)),%0A
         
@@ -1191,32 +1191,32 @@
 pId.from(%222%22)),%0A
-
         new Grou
@@ -1666,17 +1666,17 @@
 tes.get(
-0
+1
 )), term
@@ -1727,33 +1727,33 @@
 (candidates.get(
-0
+1
 ), candidates.ge
@@ -1815,33 +1815,33 @@
 (candidates.get(
-0
+1
 ), candidates.ge
@@ -1853,33 +1853,33 @@
  candidates.get(
-1
+3
 )), term.backups
@@ -1922,33 +1922,33 @@
 (candidates.get(
-0
+1
 ), candidates.ge
@@ -1960,33 +1960,33 @@
  candidates.get(
-1
+3
 ), candidates.ge
@@ -1979,33 +1979,33 @@
  candidates.get(
-3
+4
 )), term.backups
@@ -2056,17 +2056,17 @@
 tes.get(
-0
+1
 ), candi
@@ -2086,33 +2086,33 @@
  candidates.get(
-1
+3
 ), candidates.ge
@@ -2105,33 +2105,33 @@
  candidates.get(
-3
+4
 )), term.backups

Fix broken PrimaryTerm test.