• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 
17 package android.adservices.common;
18 
19 import com.google.common.collect.ImmutableSet;
20 
21 import java.time.Duration;
22 
23 /** Utility class for creating and testing {@link KeyedFrequencyCap} objects. */
24 public class KeyedFrequencyCapFixture {
25     public static final String KEY1 = "key1";
26     public static final String KEY2 = "key2";
27     public static final String KEY3 = "key3";
28     public static final String KEY4 = "key4";
29     public static final int VALID_COUNT = 10;
30     public static final int FILTER_COUNT = 1;
31     public static final int FILTER_EXCEED_COUNT = FILTER_COUNT + 1;
32     public static final Duration ONE_DAY_DURATION = Duration.ofDays(1);
33 
34     public static final ImmutableSet<KeyedFrequencyCap> VALID_KEYED_FREQUENCY_CAP_SET =
35             ImmutableSet.of(
36                     getValidKeyedFrequencyCapBuilderOncePerDay(KEY1).build(),
37                     getValidKeyedFrequencyCapBuilderOncePerDay(KEY2).build(),
38                     getValidKeyedFrequencyCapBuilderOncePerDay(KEY3).build(),
39                     getValidKeyedFrequencyCapBuilderOncePerDay(KEY4).build());
40 
getValidKeyedFrequencyCapBuilderOncePerDay(String key)41     public static KeyedFrequencyCap.Builder getValidKeyedFrequencyCapBuilderOncePerDay(String key) {
42         return new KeyedFrequencyCap.Builder()
43                 .setAdCounterKey(key)
44                 .setMaxCount(FILTER_COUNT)
45                 .setInterval(ONE_DAY_DURATION);
46     }
47 }
48