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

Commit cf9f6e84 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add tests for BluetoothMapAccountItemTest and BluetoothMapAppParamsTest" into tm-qpr-dev

parents 173849ab d9a54f0f
Loading
Loading
Loading
Loading
+166 −0
Original line number Diff line number Diff line
@@ -42,10 +42,12 @@ public class BluetoothMapAccountItemTest {
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
        assertThat(accountItem.getId()).isEqualTo(TEST_ID);
        assertThat(accountItem.getAccountId()).isEqualTo(Long.parseLong(TEST_ID));
        assertThat(accountItem.getName()).isEqualTo(TEST_NAME);
        assertThat(accountItem.getPackageName()).isEqualTo(TEST_PACKAGE_NAME);
        assertThat(accountItem.getProviderAuthority()).isEqualTo(TEST_PROVIDER_AUTHORITY);
        assertThat(accountItem.getIcon()).isEqualTo(TEST_DRAWABLE);
        assertThat(accountItem.getType()).isEqualTo(TEST_TYPE);
        assertThat(accountItem.getUci()).isEqualTo(TEST_UCI);
        assertThat(accountItem.getUciPrefix()).isEqualTo(TEST_UCI_PREFIX);
@@ -55,10 +57,12 @@ public class BluetoothMapAccountItemTest {
    public void create_withoutIdAndUciData() {
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(/*id=*/null, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE, TEST_TYPE);
        assertThat(accountItem.getId()).isNull();
        assertThat(accountItem.getAccountId()).isEqualTo(-1);
        assertThat(accountItem.getName()).isEqualTo(TEST_NAME);
        assertThat(accountItem.getPackageName()).isEqualTo(TEST_PACKAGE_NAME);
        assertThat(accountItem.getProviderAuthority()).isEqualTo(TEST_PROVIDER_AUTHORITY);
        assertThat(accountItem.getIcon()).isEqualTo(TEST_DRAWABLE);
        assertThat(accountItem.getType()).isEqualTo(TEST_TYPE);
        assertThat(accountItem.getUci()).isNull();
        assertThat(accountItem.getUciPrefix()).isNull();
@@ -109,4 +113,166 @@ public class BluetoothMapAccountItemTest {
        assertThat(accountItem.equals(accountItemWithoutUciData)).isTrue();
        assertThat(accountItem.compareTo(accountItemWithoutUciData)).isEqualTo(0);
    }

    @Test
    public void equals_withSameInstance() {
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);

        assertThat(accountItem.equals(accountItem)).isTrue();
    }
    @Test
    public void equals_withNull() {
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);

        assertThat(accountItem).isNotEqualTo(null);
    }

    @SuppressWarnings("EqualsIncompatibleType")
    @Test
    public void equals_withDifferentClass() {
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
        String accountItemString = "accountItem_string";

        assertThat(accountItem.equals(accountItemString)).isFalse();
    }

    @Test
    public void equals_withNullId() {
        BluetoothMapAccountItem accountItemWithNullId = BluetoothMapAccountItem.create(/*id=*/null,
                TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE, TEST_TYPE,
                TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapAccountItem accountItemWithNonNullId = BluetoothMapAccountItem.create(TEST_ID,
                TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE, TEST_TYPE,
                TEST_UCI, TEST_UCI_PREFIX);

        assertThat(accountItemWithNullId).isNotEqualTo(accountItemWithNonNullId);
    }

    @Test
    public void equals_withDifferentId() {
        String TEST_ID_DIFFERENT = "2222";
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapAccountItem accountItemWithDifferentId = BluetoothMapAccountItem.create(
                TEST_ID_DIFFERENT, TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY,
                TEST_DRAWABLE, TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);

        assertThat(accountItem).isNotEqualTo(accountItemWithDifferentId);
    }

    @Test
    public void equals_withNullName() {
        BluetoothMapAccountItem accountItemWithNullName = BluetoothMapAccountItem.create(
                TEST_ID, /*name=*/null, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapAccountItem accountItemWithNonNullName = BluetoothMapAccountItem.create(TEST_ID,
                TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE, TEST_TYPE,
                TEST_UCI, TEST_UCI_PREFIX);

        assertThat(accountItemWithNullName).isNotEqualTo(accountItemWithNonNullName);
    }

    @Test
    public void equals_withDifferentName() {
        String TEST_NAME_DIFFERENT = "test_name_different";
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapAccountItem accountItemWithDifferentName = BluetoothMapAccountItem.create(
                TEST_ID, TEST_NAME_DIFFERENT, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY,
                TEST_DRAWABLE, TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);

        assertThat(accountItem).isNotEqualTo(accountItemWithDifferentName);
    }

    @Test
    public void equals_withNullPackageName() {
        BluetoothMapAccountItem accountItemWithNullPackageName = BluetoothMapAccountItem.create(
                TEST_ID, TEST_NAME, /*package_name=*/null, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapAccountItem accountItemWithNonNullPackageName = BluetoothMapAccountItem.create(
                TEST_ID, TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);

        assertThat(accountItemWithNullPackageName).isNotEqualTo(accountItemWithNonNullPackageName);
    }

    @Test
    public void equals_withDifferentPackageName() {
        String TEST_PACKAGE_NAME_DIFFERENT = "test.different.package.name";
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapAccountItem accountItemWithDifferentPackageName =
                BluetoothMapAccountItem.create(TEST_ID, TEST_NAME, TEST_PACKAGE_NAME_DIFFERENT,
                        TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE, TEST_TYPE, TEST_UCI,
                        TEST_UCI_PREFIX);

        assertThat(accountItem).isNotEqualTo(accountItemWithDifferentPackageName);
    }

    @Test
    public void equals_withNullAuthority() {
        BluetoothMapAccountItem accountItemWithNullAuthority = BluetoothMapAccountItem.create(
                TEST_ID, TEST_NAME, TEST_PACKAGE_NAME, /*provider_authority=*/null, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapAccountItem accountItemWithNonNullAuthority = BluetoothMapAccountItem.create(
                TEST_ID, TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);

        assertThat(accountItemWithNullAuthority).isNotEqualTo(accountItemWithNonNullAuthority);
    }

    @Test
    public void equals_withDifferentAuthority() {
        String TEST_PROVIDER_AUTHORITY_DIFFERENT = "test.project.different.provider";
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapAccountItem accountItemWithDifferentAuthority =
                BluetoothMapAccountItem.create(TEST_ID, TEST_NAME, TEST_PACKAGE_NAME,
                        TEST_PROVIDER_AUTHORITY_DIFFERENT, TEST_DRAWABLE, TEST_TYPE, TEST_UCI,
                        TEST_UCI_PREFIX);

        assertThat(accountItem).isNotEqualTo(accountItemWithDifferentAuthority);
    }

    @Test
    public void equals_withNullType() {
        BluetoothMapAccountItem accountItemWithNullType = BluetoothMapAccountItem.create(
                TEST_ID, TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                /*type=*/null, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapAccountItem accountItemWithNonNullType = BluetoothMapAccountItem.create(TEST_ID,
                TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE, TEST_TYPE,
                TEST_UCI, TEST_UCI_PREFIX);

        assertThat(accountItemWithNullType).isNotEqualTo(accountItemWithNonNullType);
    }

    @Test
    public void hashCode_withOnlyIdNotNull() {
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, null,
                null, null, null, null);

        int expected = (31 + TEST_ID.hashCode()) * 31 * 31 * 31;
        assertThat(accountItem.hashCode()).isEqualTo(expected);
    }

    @Test
    public void toString_returnsNameAndUriInfo() {
        BluetoothMapAccountItem accountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME,
                TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);

        String expected =
                TEST_NAME + " (" + "content://" + TEST_PROVIDER_AUTHORITY + "/" + TEST_ID + ")";
        assertThat(accountItem.toString()).isEqualTo(expected);
    }
}
 No newline at end of file
+78 −3
Original line number Diff line number Diff line
@@ -76,6 +76,82 @@ public class BluetoothMapAppParamsTest {
    public static final int TEST_SUBJECT_LENGTH = 1;
    public static final int TEST_TRANSPARENT = 1;

    @Test
    public void encodeToBuffer_thenDecode() throws Exception {
        ByteBuffer ret = ByteBuffer.allocate(16);
        ret.putLong(TEST_COUNT_HIGH);
        ret.putLong(TEST_COUNT_LOW);

        BluetoothMapAppParams appParams = new BluetoothMapAppParams();
        appParams.setMaxListCount(TEST_MAX_LIST_COUNT);
        appParams.setStartOffset(TEST_START_OFFSET);
        appParams.setFilterMessageType(TEST_FILTER_MESSAGE_TYPE);
        appParams.setFilterPeriodBegin(TEST_FILTER_PERIOD_BEGIN);
        appParams.setFilterPeriodEnd(TEST_FILTER_PERIOD_END);
        appParams.setFilterReadStatus(TEST_FILTER_READ_STATUS);
        appParams.setFilterRecipient(TEST_FILTER_RECIPIENT);
        appParams.setFilterOriginator(TEST_FILTER_ORIGINATOR);
        appParams.setFilterPriority(TEST_FILTER_PRIORITY);
        appParams.setAttachment(TEST_ATTACHMENT);
        appParams.setTransparent(TEST_TRANSPARENT);
        appParams.setRetry(TEST_RETRY);
        appParams.setNewMessage(TEST_NEW_MESSAGE);
        appParams.setNotificationFilter(TEST_NOTIFICATION_FILTER);
        appParams.setMasInstanceId(TEST_MAS_INSTANCE_ID);
        appParams.setParameterMask(TEST_PARAMETER_MASK);
        appParams.setFolderListingSize(TEST_FOLDER_LISTING_SIZE);
        appParams.setMessageListingSize(TEST_MESSAGE_LISTING_SIZE);
        appParams.setSubjectLength(TEST_SUBJECT_LENGTH);
        appParams.setCharset(TEST_CHARSET);
        appParams.setFractionRequest(TEST_FRACTION_REQUEST);
        appParams.setFractionDeliver(TEST_FRACTION_DELIVER);
        appParams.setStatusIndicator(TEST_STATUS_INDICATOR);
        appParams.setStatusValue(TEST_STATUS_VALUE);
        appParams.setMseTime(TEST_MSE_TIME);
        appParams.setDatabaseIdentifier(TEST_ID_HIGH, TEST_ID_LOW);
        appParams.setConvoListingVerCounter(TEST_COUNT_LOW, TEST_COUNT_HIGH);
        appParams.setPresenceStatus(TEST_PRESENCE_STATUS);
        appParams.setLastActivity(TEST_LAST_ACTIVITY);
        appParams.setConvoListingSize(TEST_CONVO_LISTING_SIZE);
        appParams.setChatStateConvoId(TEST_ID_HIGH, TEST_ID_LOW);
        appParams.setFolderVerCounter(TEST_COUNT_LOW, TEST_COUNT_HIGH);

        byte[] encodedParams = appParams.encodeParams();
        BluetoothMapAppParams appParamsDecoded = new BluetoothMapAppParams(encodedParams);

        assertThat(appParamsDecoded.getMaxListCount()).isEqualTo(TEST_MAX_LIST_COUNT);
        assertThat(appParamsDecoded.getStartOffset()).isEqualTo(TEST_START_OFFSET);
        assertThat(appParamsDecoded.getFilterMessageType()).isEqualTo(TEST_FILTER_MESSAGE_TYPE);
        assertThat(appParamsDecoded.getFilterPeriodBegin()).isEqualTo(TEST_FILTER_PERIOD_BEGIN);
        assertThat(appParamsDecoded.getFilterPeriodEnd()).isEqualTo(TEST_FILTER_PERIOD_END);
        assertThat(appParamsDecoded.getFilterReadStatus()).isEqualTo(TEST_FILTER_READ_STATUS);
        assertThat(appParamsDecoded.getFilterRecipient()).isEqualTo(TEST_FILTER_RECIPIENT);
        assertThat(appParamsDecoded.getFilterOriginator()).isEqualTo(TEST_FILTER_ORIGINATOR);
        assertThat(appParamsDecoded.getFilterPriority()).isEqualTo(TEST_FILTER_PRIORITY);
        assertThat(appParamsDecoded.getAttachment()).isEqualTo(TEST_ATTACHMENT);
        assertThat(appParamsDecoded.getTransparent()).isEqualTo(TEST_TRANSPARENT);
        assertThat(appParamsDecoded.getRetry()).isEqualTo(TEST_RETRY);
        assertThat(appParamsDecoded.getNewMessage()).isEqualTo(TEST_NEW_MESSAGE);
        assertThat(appParamsDecoded.getNotificationFilter()).isEqualTo(TEST_NOTIFICATION_FILTER);
        assertThat(appParamsDecoded.getMasInstanceId()).isEqualTo(TEST_MAS_INSTANCE_ID);
        assertThat(appParamsDecoded.getParameterMask()).isEqualTo(TEST_PARAMETER_MASK);
        assertThat(appParamsDecoded.getFolderListingSize()).isEqualTo(TEST_FOLDER_LISTING_SIZE);
        assertThat(appParamsDecoded.getMessageListingSize()).isEqualTo(TEST_MESSAGE_LISTING_SIZE);
        assertThat(appParamsDecoded.getSubjectLength()).isEqualTo(TEST_SUBJECT_LENGTH);
        assertThat(appParamsDecoded.getCharset()).isEqualTo(TEST_CHARSET);
        assertThat(appParamsDecoded.getFractionRequest()).isEqualTo(TEST_FRACTION_REQUEST);
        assertThat(appParamsDecoded.getFractionDeliver()).isEqualTo(TEST_FRACTION_DELIVER);
        assertThat(appParamsDecoded.getStatusIndicator()).isEqualTo(TEST_STATUS_INDICATOR);
        assertThat(appParamsDecoded.getStatusValue()).isEqualTo(TEST_STATUS_VALUE);
        assertThat(appParamsDecoded.getMseTime()).isEqualTo(TEST_MSE_TIME);
        assertThat(appParamsDecoded.getDatabaseIdentifier()).isEqualTo(ret.array());
        assertThat(appParamsDecoded.getConvoListingVerCounter()).isEqualTo(ret.array());
        assertThat(appParamsDecoded.getPresenceStatus()).isEqualTo(TEST_PRESENCE_STATUS);
        assertThat(appParamsDecoded.getLastActivity()).isEqualTo(TEST_LAST_ACTIVITY);
        assertThat(appParamsDecoded.getConvoListingSize()).isEqualTo(TEST_CONVO_LISTING_SIZE);
        assertThat(appParamsDecoded.getChatStateConvoId()).isEqualTo(new SignedLongLong(
                TEST_ID_HIGH, TEST_ID_LOW));
    }
    @Test
    public void settersAndGetters() throws Exception {
        ByteBuffer ret = ByteBuffer.allocate(16);
@@ -133,8 +209,7 @@ public class BluetoothMapAppParamsTest {
        assertThat(appParams.getChatStateConvoIdByteArray()).isEqualTo(ret.array());
        assertThat(appParams.getChatStateConvoIdString()).isEqualTo(new String(ret.array()));
        assertThat(appParams.getConvoListingSize()).isEqualTo(TEST_CONVO_LISTING_SIZE);
        assertThat(appParams.getConvoListingVerCounter()).isEqualTo(
                ret.array());
        assertThat(appParams.getConvoListingVerCounter()).isEqualTo(ret.array());
        assertThat(appParams.getConvoParameterMask()).isEqualTo(TEST_CONVO_PARAMETER_MASK);
        assertThat(appParams.getDatabaseIdentifier()).isEqualTo(ret.array());
        assertThat(appParams.getFilterConvoId()).isEqualTo(
@@ -181,7 +256,7 @@ public class BluetoothMapAppParamsTest {

        assertThat(appParams.getFilterLastActivityBegin()).isEqualTo(
                TEST_FILTER_LAST_ACTIVITY_BEGIN);
        assertThat(appParams.getFilterLastActivityBegin()).isEqualTo(TEST_FILTER_LAST_ACTIVITY_END);
        assertThat(appParams.getFilterLastActivityEnd()).isEqualTo(TEST_FILTER_LAST_ACTIVITY_END);
    }

    @Test