1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package com.android.calendar.alerts;
18
19import android.app.PendingIntent;
20import android.content.Context;
21import android.text.format.DateUtils;
22
23import junit.framework.Assert;
24
25public class MockAlarmManager implements AlarmManagerInterface {
26    private Context context;
27    private int expectedAlarmType = -1;
28    private long expectedAlarmTime = -1;
29    private boolean alarmSet = false;
30
31    MockAlarmManager(Context context) {
32        this.context = context;
33    }
34
35    public void expectAlarmTime(int type, long millis) {
36        this.expectedAlarmType = type;
37        this.expectedAlarmTime = millis;
38    }
39
40    @Override
41    public void set(int actualAlarmType, long actualAlarmTime, PendingIntent operation) {
42        Assert.assertNotNull(operation);
43        alarmSet = true;
44        if (expectedAlarmType != -1) {
45            Assert.assertEquals("Alarm type not expected.", expectedAlarmType, actualAlarmType);
46            Assert.assertEquals("Alarm time not expected. Expected:" + DateUtils.formatDateTime(
47                    context, expectedAlarmTime, DateUtils.FORMAT_SHOW_TIME) + ", actual:"
48                    + DateUtils.formatDateTime(context, actualAlarmTime,
49                    DateUtils.FORMAT_SHOW_TIME), expectedAlarmTime, actualAlarmTime);
50        }
51    }
52
53    /**
54     * Returns whether set() was invoked.
55     */
56    public boolean isAlarmSet() {
57        return alarmSet;
58    }
59}
60