1 /* 2 * Copyright (C) 2019 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.app; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.app.StatsManager.PullAtomMetadata; 22 23 import androidx.test.filters.SmallTest; 24 import androidx.test.runner.AndroidJUnit4; 25 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 @SmallTest 30 @RunWith(AndroidJUnit4.class) 31 public final class PullAtomMetadataTest { 32 33 @Test testEmpty()34 public void testEmpty() { 35 PullAtomMetadata metadata = new PullAtomMetadata.Builder().build(); 36 assertThat(metadata.getTimeoutMillis()).isEqualTo(StatsManager.DEFAULT_TIMEOUT_MILLIS); 37 assertThat(metadata.getCoolDownMillis()).isEqualTo(StatsManager.DEFAULT_COOL_DOWN_MILLIS); 38 assertThat(metadata.getAdditiveFields()).isNull(); 39 } 40 41 @Test testSetTimeoutMillis()42 public void testSetTimeoutMillis() { 43 long timeoutMillis = 500L; 44 PullAtomMetadata metadata = 45 new PullAtomMetadata.Builder().setTimeoutMillis(timeoutMillis).build(); 46 assertThat(metadata.getTimeoutMillis()).isEqualTo(timeoutMillis); 47 assertThat(metadata.getCoolDownMillis()).isEqualTo(StatsManager.DEFAULT_COOL_DOWN_MILLIS); 48 assertThat(metadata.getAdditiveFields()).isNull(); 49 } 50 51 @Test testSetCoolDownMillis()52 public void testSetCoolDownMillis() { 53 long coolDownMillis = 10_000L; 54 PullAtomMetadata metadata = 55 new PullAtomMetadata.Builder().setCoolDownMillis(coolDownMillis).build(); 56 assertThat(metadata.getTimeoutMillis()).isEqualTo(StatsManager.DEFAULT_TIMEOUT_MILLIS); 57 assertThat(metadata.getCoolDownMillis()).isEqualTo(coolDownMillis); 58 assertThat(metadata.getAdditiveFields()).isNull(); 59 } 60 61 @Test testSetAdditiveFields()62 public void testSetAdditiveFields() { 63 int[] fields = {2, 4, 6}; 64 PullAtomMetadata metadata = 65 new PullAtomMetadata.Builder().setAdditiveFields(fields).build(); 66 assertThat(metadata.getTimeoutMillis()).isEqualTo(StatsManager.DEFAULT_TIMEOUT_MILLIS); 67 assertThat(metadata.getCoolDownMillis()).isEqualTo(StatsManager.DEFAULT_COOL_DOWN_MILLIS); 68 assertThat(metadata.getAdditiveFields()).isEqualTo(fields); 69 } 70 71 @Test testSetAllElements()72 public void testSetAllElements() { 73 long timeoutMillis = 300L; 74 long coolDownMillis = 9572L; 75 int[] fields = {3, 2}; 76 PullAtomMetadata metadata = new PullAtomMetadata.Builder() 77 .setTimeoutMillis(timeoutMillis) 78 .setCoolDownMillis(coolDownMillis) 79 .setAdditiveFields(fields) 80 .build(); 81 assertThat(metadata.getTimeoutMillis()).isEqualTo(timeoutMillis); 82 assertThat(metadata.getCoolDownMillis()).isEqualTo(coolDownMillis); 83 assertThat(metadata.getAdditiveFields()).isEqualTo(fields); 84 } 85 } 86