1 /* 2 * Copyright (C) 2021 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 package com.android.car.rotary; 17 18 import static org.mockito.internal.util.MockUtil.isMock; 19 20 import android.view.accessibility.AccessibilityNodeInfo; 21 22 import androidx.annotation.Nullable; 23 24 /** A class that can provide a mock {@link NodeCopier}. */ 25 class MockNodeCopierProvider { 26 private static final NodeCopier sNodeCopier = new NodeCopier() { 27 // NodeCopier#copyNode() doesn't work when passed a mock node, so we create the mock method 28 // which returns the passed node itself rather than a copy when the parameter is a mocked 29 // node. As a result, mocked nodes created by the mock method shouldn't be recycled. 30 @Override 31 AccessibilityNodeInfo copy(@Nullable AccessibilityNodeInfo node) { 32 if (isMock(node)) { 33 return node; 34 } 35 return node == null ? null : AccessibilityNodeInfo.obtain(node); 36 } 37 }; 38 get()39 static NodeCopier get() { 40 return sNodeCopier; 41 } 42 } 43