• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
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.google.android.libraries.mobiledatadownload.file.common.testing;
17 
18 import static org.mockito.ArgumentMatchers.argThat;
19 
20 import android.net.Uri;
21 import com.google.android.libraries.mobiledatadownload.file.common.internal.LiteTransformFragments;
22 import com.google.common.collect.ImmutableList;
23 import org.mockito.ArgumentMatcher;
24 
25 /** Matchers for Fragment Params. */
26 public final class FragmentParamMatchers {
27 
28   /** Matcher for {@link Fragment.ParamValue}s. */
29   private static class ParamValueMatcher implements ArgumentMatcher<Uri> {
30     private final String expectedSpec;
31 
ParamValueMatcher(Uri expected)32     ParamValueMatcher(Uri expected) {
33       ImmutableList<String> specs = LiteTransformFragments.parseTransformSpecs(expected);
34       if (specs.size() != 1) {
35         throw new IllegalArgumentException("Should have only one spec: " + expected);
36       }
37       this.expectedSpec = specs.get(0);
38     }
39 
40     @Override
matches(Uri other)41     public boolean matches(Uri other) {
42       Uri otherUri = (Uri) other;
43       ImmutableList<String> otherSpecs = LiteTransformFragments.parseTransformSpecs(otherUri);
44       for (String otherSpec : otherSpecs) {
45         if (expectedSpec.equals(otherSpec)) {
46           return true;
47         }
48       }
49       return false;
50     }
51   }
52 
eqParam(Uri expected)53   public static Uri eqParam(Uri expected) {
54     return argThat(new ParamValueMatcher(expected));
55   }
56 }
57