blob: 84ac2c212854d78ce9ae27999ee00e273b7b759b [file] [log] [blame]
Artem Iglikovbd476ea2017-09-01 10:57:26 +01001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.server.backup.testing;
18
19import com.android.internal.backup.IBackupTransport;
20import com.android.server.backup.TransportManager;
21
22import java.util.HashSet;
23import java.util.Set;
24
25/**
26 * Stub implementation of TransportBoundListener, which returns given result and can tell whether
27 * it was called for given transport.
28 */
29public class TransportBoundListenerStub implements
30 TransportManager.TransportBoundListener {
31 private boolean mAlwaysReturnSuccess;
32 private Set<IBackupTransport> mTransportsCalledFor = new HashSet<>();
33
34 public TransportBoundListenerStub(boolean alwaysReturnSuccess) {
35 this.mAlwaysReturnSuccess = alwaysReturnSuccess;
36 }
37
38 @Override
39 public boolean onTransportBound(IBackupTransport binder) {
40 mTransportsCalledFor.add(binder);
41 return mAlwaysReturnSuccess;
42 }
43
Artem Iglikov19e12272017-05-31 17:12:28 +010044 /**
45 * Returns whether the listener was called for the specified transport at least once.
46 */
Artem Iglikovbd476ea2017-09-01 10:57:26 +010047 public boolean isCalledForTransport(IBackupTransport binder) {
48 return mTransportsCalledFor.contains(binder);
49 }
50
Artem Iglikov19e12272017-05-31 17:12:28 +010051 /**
52 * Returns whether the listener was called at least once.
53 */
Artem Iglikovbd476ea2017-09-01 10:57:26 +010054 public boolean isCalled() {
55 return !mTransportsCalledFor.isEmpty();
56 }
Artem Iglikov19e12272017-05-31 17:12:28 +010057
58 /**
59 * Resets listener calls.
60 */
61 public void resetState() {
62 mTransportsCalledFor.clear();
63 }
Artem Iglikovbd476ea2017-09-01 10:57:26 +010064}