BUG-272: cleanup sal-rest-connector
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / DummyFuture.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.sal.restconf.impl.test;
9
10 import java.util.concurrent.ExecutionException;
11 import java.util.concurrent.Future;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
14
15 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
16 import org.opendaylight.yangtools.yang.common.RpcResult;
17
18 public class DummyFuture implements Future<RpcResult<TransactionStatus>> {
19
20     private final boolean cancel;
21     private final boolean isCancelled;
22     private final boolean isDone;
23     private final RpcResult<TransactionStatus> result;
24
25     public DummyFuture() {
26         cancel = false;
27         isCancelled = false;
28         isDone = false;
29         result = null;
30     }
31
32     private DummyFuture(final Builder builder) {
33         cancel = builder.cancel;
34         isCancelled = builder.isCancelled;
35         isDone = builder.isDone;
36         result = builder.result;
37     }
38
39     public static Builder builder() {
40         return new DummyFuture.Builder();
41     }
42
43     @Override
44     public boolean cancel(final boolean mayInterruptIfRunning) {
45         return cancel;
46     }
47
48     @Override
49     public boolean isCancelled() {
50         return isCancelled;
51     }
52
53     @Override
54     public boolean isDone() {
55         return isDone;
56     }
57
58     @Override
59     public RpcResult<TransactionStatus> get() throws InterruptedException, ExecutionException {
60         return result;
61     }
62
63     @Override
64     public RpcResult<TransactionStatus> get(final long timeout, final TimeUnit unit) throws InterruptedException,
65     ExecutionException, TimeoutException {
66         return result;
67     }
68
69     public static class Builder {
70
71         private boolean cancel;
72         private boolean isCancelled;
73         private boolean isDone;
74         private RpcResult<TransactionStatus> result;
75
76         public Builder cancel(final boolean cancel) {
77             this.cancel = cancel;
78             return this;
79         }
80
81         public Builder isCancelled(final boolean isCancelled) {
82             this.isCancelled = isCancelled;
83             return this;
84         }
85
86         public Builder isDone(final boolean isDone) {
87             this.isDone = isDone;
88             return this;
89         }
90
91         public Builder rpcResult(final RpcResult<TransactionStatus> result) {
92             this.result = result;
93             return this;
94         }
95
96         public Future<RpcResult<TransactionStatus>> build() {
97             return new DummyFuture(this);
98         }
99     }
100 }