1/*
2 * Copyright (C) 2016 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
17package com.android.phone.vvm.omtp;
18
19import android.os.Bundle;
20
21import com.android.phone.vvm.omtp.sms.SyncMessage;
22
23import junit.framework.TestCase;
24
25import java.text.ParseException;
26import java.text.SimpleDateFormat;
27import java.util.Locale;
28
29public class SyncMessageTest extends TestCase {
30
31    public void testSyncMessage() {
32        Bundle bundle = new Bundle();
33        bundle.putString(OmtpConstants.SYNC_TRIGGER_EVENT, "event");
34        bundle.putString(OmtpConstants.MESSAGE_UID, "uid");
35        bundle.putString(OmtpConstants.MESSAGE_LENGTH, "1");
36        bundle.putString(OmtpConstants.CONTENT_TYPE, "type");
37        bundle.putString(OmtpConstants.SENDER, "sender");
38        bundle.putString(OmtpConstants.NUM_MESSAGE_COUNT, "2");
39        bundle.putString(OmtpConstants.TIME, "29/08/1997 02:14 -0400");
40
41        SyncMessage message = new SyncMessage(bundle);
42        assertEquals("event", message.getSyncTriggerEvent());
43        assertEquals("uid", message.getId());
44        assertEquals(1, message.getLength());
45        assertEquals("type", message.getContentType());
46        assertEquals("sender", message.getSender());
47        assertEquals(2, message.getNewMessageCount());
48        try {
49            assertEquals(new SimpleDateFormat(
50                    OmtpConstants.DATE_TIME_FORMAT, Locale.US)
51                    .parse("29/08/1997 02:14 -0400").getTime(), message.getTimestampMillis());
52        } catch (ParseException e) {
53            throw new AssertionError(e.toString());
54        }
55    }
56
57    public void testSyncMessage_EmptyBundle() {
58        SyncMessage message = new SyncMessage(new Bundle());
59        assertEquals("", message.getSyncTriggerEvent());
60        assertEquals("", message.getId());
61        assertEquals(0, message.getLength());
62        assertEquals("", message.getContentType());
63        assertEquals("", message.getSender());
64        assertEquals(0, message.getNewMessageCount());
65        assertEquals(0, message.getTimestampMillis());
66    }
67}
68