2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com.android.server.notification;
18 import static com.android.server.notification.AlertRateLimiter.ALLOWED_ALERT_INTERVAL;
20 import static junit.framework.Assert.assertFalse;
21 import static junit.framework.Assert.assertTrue;
23 import android.support.test.runner.AndroidJUnit4;
24 import android.test.suitebuilder.annotation.SmallTest;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
30 @RunWith(AndroidJUnit4.class)
31 public class AlertRateLimiterTest extends NotificationTestCase {
33 private long mTestStartTime;
35 AlertRateLimiter mLimiter;
39 mTestStartTime = 1225731600000L;
40 mLimiter = new AlertRateLimiter();
44 public void testFirstAlertAllowed() throws Exception {
45 assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
49 public void testAllowedAfterSecond() throws Exception {
50 assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
51 assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime + ALLOWED_ALERT_INTERVAL));
55 public void testAllowedAfterSecondEvenWithBlockedEntries() throws Exception {
56 assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
57 assertTrue(mLimiter.shouldRateLimitAlert(mTestStartTime + ALLOWED_ALERT_INTERVAL - 1));
58 assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime + ALLOWED_ALERT_INTERVAL));
62 public void testAllowedDisallowedBeforeSecond() throws Exception {
63 assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
64 assertTrue(mLimiter.shouldRateLimitAlert(mTestStartTime + ALLOWED_ALERT_INTERVAL - 1));
68 public void testDisallowedTimePast() throws Exception {
69 assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
70 assertTrue(mLimiter.shouldRateLimitAlert(mTestStartTime - ALLOWED_ALERT_INTERVAL));