Fix warnings in sal-akka-raft test classes
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / utils / ForwardMessageToBehaviorActor.java
1 /*
2  * Copyright (c) 2015 Cisco 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
9 package org.opendaylight.controller.cluster.raft.utils;
10
11 import static org.junit.Assert.assertTrue;
12
13 import akka.actor.Props;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
17
18 public class ForwardMessageToBehaviorActor extends MessageCollectorActor {
19     private volatile RaftActorBehavior behavior;
20     private final List<RaftActorBehavior> behaviorChanges = new ArrayList<>();
21
22     @Override
23     public void onReceive(Object message) throws Exception {
24         if (behavior != null) {
25             behaviorChanges.add(behavior.handleMessage(sender(), message));
26         }
27         super.onReceive(message);
28     }
29
30     public static Props props() {
31         return Props.create(ForwardMessageToBehaviorActor.class);
32     }
33
34     public void setBehavior(RaftActorBehavior behavior) {
35         this.behavior = behavior;
36     }
37
38     public RaftActorBehavior getFirstBehaviorChange() {
39         assertTrue("no behavior changes present", behaviorChanges.size() > 0);
40         return behaviorChanges.get(0);
41     }
42
43     public RaftActorBehavior getLastBehaviorChange() {
44         assertTrue("no behavior changes present", behaviorChanges.size() > 0);
45         return behaviorChanges.get(behaviorChanges.size() - 1);
46     }
47
48     public List<RaftActorBehavior> getBehaviorChanges() {
49         return behaviorChanges;
50     }
51
52     @Override
53     public void clear() {
54         super.clear();
55         behaviorChanges.clear();
56     }
57 }
58