diff --git a/android/app/src/com/android/bluetooth/mapclient/obex/Message.java b/android/app/src/com/android/bluetooth/mapclient/obex/Message.java index 606ef0412ec57acac545d3e7bde68b982c451914..007775f409f12320a14f96a66665cb4a4498b54b 100644 --- a/android/app/src/com/android/bluetooth/mapclient/obex/Message.java +++ b/android/app/src/com/android/bluetooth/mapclient/obex/Message.java @@ -132,8 +132,6 @@ public class Message { mProtected = yesnoToBoolean(attrs.get("protected")); } - ; - private boolean yesnoToBoolean(String yesno) { return "yes".equals(yesno); } diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MessageTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MessageTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2f95d563a4dc30d712856a5aaabcbf0e73ab2238 --- /dev/null +++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MessageTest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.bluetooth.mapclient; + +import static com.google.common.truth.Truth.assertThat; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.HashMap; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class MessageTest { + + @Test + public void constructor() throws Exception { + HashMap<String, String> attrs = new HashMap<>(); + + String handle = "FFAB"; + attrs.put("handle", handle); + + String subject = "test_subject"; + attrs.put("subject", subject); + + String dateTime = "20221220T165048"; + attrs.put("datetime", dateTime); + + String senderName = "test_sender_name"; + attrs.put("sender_name", senderName); + + String senderAddr = "test_sender_addressing"; + attrs.put("sender_addressing", senderAddr); + + String replytoAddr = "test_replyto_addressing"; + attrs.put("replyto_addressing", replytoAddr); + + String recipientName = "test_recipient_name"; + attrs.put("recipient_name", recipientName); + + String recipientAddr = "test_recipient_addressing"; + attrs.put("recipient_addressing", recipientAddr); + + String type = "MMS"; + attrs.put("type", type); + + int size = 23; + attrs.put("size", Integer.toString(size)); + + String text = "yes"; + attrs.put("text", text); + + String receptionStatus = "notification"; + attrs.put("reception_status", receptionStatus); + + int attachmentSize = 15; + attrs.put("attachment_size", Integer.toString(attachmentSize)); + + String isPriority = "yes"; + attrs.put("priority", isPriority); + + String isRead = "yes"; + attrs.put("read", isRead); + + String isSent = "yes"; + attrs.put("sent", isSent); + + String isProtected = "yes"; + attrs.put("protected", isProtected); + + Message msg = new Message(attrs); + + assertThat(msg.getHandle()).isEqualTo(handle); + assertThat(msg.getSubject()).isEqualTo(subject); + // TODO: Compare the Date class properly. + // assertThat(msg.getDateTime()).isEqualTo(expectedTime); + assertThat(msg.getDateTime()).isNotNull(); + assertThat(msg.getSenderName()).isEqualTo(senderName); + assertThat(msg.getSenderAddressing()).isEqualTo(senderAddr); + assertThat(msg.getReplytoAddressing()).isEqualTo(replytoAddr); + assertThat(msg.getRecipientName()).isEqualTo(recipientName); + assertThat(msg.getRecipientAddressing()).isEqualTo(recipientAddr); + assertThat(msg.getType()).isEqualTo(Message.Type.MMS); + assertThat(msg.getSize()).isEqualTo(size); + assertThat(msg.getReceptionStatus()).isEqualTo(Message.ReceptionStatus.NOTIFICATION); + assertThat(msg.getAttachmentSize()).isEqualTo(attachmentSize); + assertThat(msg.isText()).isTrue(); + assertThat(msg.isPriority()).isTrue(); + assertThat(msg.isRead()).isTrue(); + assertThat(msg.isSent()).isTrue(); + assertThat(msg.isProtected()).isTrue(); + assertThat(msg.toString()).isNotEmpty(); + } +}