Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c028c02 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add BluetoothMapbMessageEmailTest"

parents d0c81e5f 171b1782
Loading
Loading
Loading
Loading
+78 −0
Original line number Diff line number Diff line
/*
 * 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.map;

import static com.google.common.truth.Truth.assertThat;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.map.BluetoothMapUtils.TYPE;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class BluetoothMapbMessageEmailTest {
    public static final String TEST_EMAIL_BODY = "test_email_body";

    @Test
    public void setAndGetEmailBody() {
        BluetoothMapbMessageEmail messageEmail = new BluetoothMapbMessageEmail();
        messageEmail.setEmailBody(TEST_EMAIL_BODY);
        assertThat(messageEmail.getEmailBody()).isEqualTo(TEST_EMAIL_BODY);
    }

    @Test
    public void encodeToByteArray_thenCreateByParsing() throws Exception {
        BluetoothMapbMessageEmail messageEmailToEncode = new BluetoothMapbMessageEmail();
        messageEmailToEncode.setType(TYPE.EMAIL);
        messageEmailToEncode.setFolder("placeholder");
        messageEmailToEncode.setStatus(true);
        messageEmailToEncode.setEmailBody(TEST_EMAIL_BODY);

        byte[] encodedMessageEmail = messageEmailToEncode.encode();
        InputStream inputStream = new ByteArrayInputStream(encodedMessageEmail);

        BluetoothMapbMessage messageParsed = BluetoothMapbMessage.parse(inputStream,
                BluetoothMapAppParams.CHARSET_UTF8);
        assertThat(messageParsed).isInstanceOf(BluetoothMapbMessageEmail.class);
        BluetoothMapbMessageEmail messageEmailParsed = (BluetoothMapbMessageEmail) messageParsed;
        assertThat(messageEmailParsed.getEmailBody()).isEqualTo(TEST_EMAIL_BODY);
    }

    @Test
    public void encodeToByteArray_withEmptyBody_thenCreateByParsing() throws Exception {
        BluetoothMapbMessageEmail messageEmailToEncode = new BluetoothMapbMessageEmail();
        messageEmailToEncode.setType(TYPE.EMAIL);
        messageEmailToEncode.setFolder("placeholder");
        messageEmailToEncode.setStatus(true);

        byte[] encodedMessageEmail = messageEmailToEncode.encode();
        InputStream inputStream = new ByteArrayInputStream(encodedMessageEmail);

        BluetoothMapbMessage messageParsed = BluetoothMapbMessage.parse(inputStream,
                BluetoothMapAppParams.CHARSET_UTF8);
        assertThat(messageParsed).isInstanceOf(BluetoothMapbMessageEmail.class);
        BluetoothMapbMessageEmail messageEmailParsed = (BluetoothMapbMessageEmail) messageParsed;
        assertThat(messageEmailParsed.getEmailBody()).isEqualTo("");
    }
}
 No newline at end of file