Fix warnings in sal-akka-raft test classes
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / ElectionTermImplTest.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.raft;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.verify;
12
13 import akka.japi.Procedure;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.mockito.ArgumentCaptor;
17 import org.mockito.Mock;
18 import org.mockito.MockitoAnnotations;
19 import org.opendaylight.controller.cluster.DataPersistenceProvider;
20 import org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * Unit tests for ElectionTermImpl.
26  *
27  * @author Thomas Pantelis
28  */
29 public class ElectionTermImplTest {
30     private static final Logger LOG = LoggerFactory.getLogger(RaftActorRecoverySupportTest.class);
31
32     @Mock
33     private DataPersistenceProvider mockPersistence;
34
35     @Before
36     public void setup() {
37         MockitoAnnotations.initMocks(this);
38     }
39
40     @SuppressWarnings({ "rawtypes", "unchecked" })
41     @Test
42     public void testUpdateAndPersist() throws Exception {
43         ElectionTermImpl impl = new ElectionTermImpl(mockPersistence, "test", LOG);
44
45         impl.updateAndPersist(10, "member-1");
46
47         assertEquals("getCurrentTerm", 10, impl.getCurrentTerm());
48         assertEquals("getVotedFor", "member-1", impl.getVotedFor());
49
50         ArgumentCaptor<Object> message = ArgumentCaptor.forClass(Object.class);
51         ArgumentCaptor<Procedure> procedure = ArgumentCaptor.forClass(Procedure.class);
52         verify(mockPersistence).persist(message.capture(), procedure.capture());
53
54         assertEquals("Message type", UpdateElectionTerm.class, message.getValue().getClass());
55         UpdateElectionTerm update = (UpdateElectionTerm)message.getValue();
56         assertEquals("getCurrentTerm", 10, update.getCurrentTerm());
57         assertEquals("getVotedFor", "member-1", update.getVotedFor());
58
59         procedure.getValue().apply(null);
60     }
61 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.