• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.phone.vvm.omtp;
18 
19 import android.os.Bundle;
20 
21 import com.android.phone.vvm.omtp.sms.SyncMessage;
22 
23 import junit.framework.TestCase;
24 
25 import java.text.ParseException;
26 import java.text.SimpleDateFormat;
27 import java.util.Locale;
28 
29 public class SyncMessageTest extends TestCase {
30 
testSyncMessage()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 
testSyncMessage_EmptyBundle()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