Merge "Add missing unit tests for radio"
This commit is contained in:
@@ -533,7 +533,6 @@ public final class ProgramSelector implements Parcelable {
|
||||
mProgramType = in.readInt();
|
||||
mPrimaryId = in.readTypedObject(Identifier.CREATOR);
|
||||
mSecondaryIds = in.createTypedArray(Identifier.CREATOR);
|
||||
Arrays.sort(mSecondaryIds);
|
||||
if (Stream.of(mSecondaryIds).anyMatch(id -> id == null)) {
|
||||
throw new IllegalArgumentException("secondaryIds list must not contain nulls");
|
||||
}
|
||||
|
||||
@@ -23,11 +23,13 @@ import static org.junit.Assert.assertThrows;
|
||||
import android.annotation.Nullable;
|
||||
import android.hardware.radio.ProgramSelector;
|
||||
import android.hardware.radio.RadioManager;
|
||||
import android.os.Parcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public final class ProgramSelectorTest {
|
||||
|
||||
private static final int CREATOR_ARRAY_SIZE = 2;
|
||||
private static final int FM_PROGRAM_TYPE = ProgramSelector.PROGRAM_TYPE_FM;
|
||||
private static final int DAB_PROGRAM_TYPE = ProgramSelector.PROGRAM_TYPE_DAB;
|
||||
private static final long FM_FREQUENCY = 88500;
|
||||
@@ -96,6 +98,33 @@ public final class ProgramSelectorTest {
|
||||
.that(FM_IDENTIFIER).isEqualTo(fmIdentifierSame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forIdentifier() {
|
||||
assertWithMessage("FM identifier contents")
|
||||
.that(FM_IDENTIFIER.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forIdentifierCreator() {
|
||||
ProgramSelector.Identifier[] identifiers =
|
||||
ProgramSelector.Identifier.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("Identifiers").that(identifiers).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forIdentifier() {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
FM_IDENTIFIER.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
ProgramSelector.Identifier identifierFromParcel =
|
||||
ProgramSelector.Identifier.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("Identifier created from parcel")
|
||||
.that(identifierFromParcel).isEqualTo(FM_IDENTIFIER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProgramType() {
|
||||
ProgramSelector selector = getFmSelector(/* secondaryIds= */ null, /* vendorIds= */ null);
|
||||
@@ -394,6 +423,34 @@ public final class ProgramSelectorTest {
|
||||
.that(selector1.strictEquals(selector2)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forProgramSelector() {
|
||||
assertWithMessage("FM selector contents")
|
||||
.that(getFmSelector(/* secondaryIds= */ null, /* vendorIds= */ null)
|
||||
.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forProgramSelectorCreator() {
|
||||
ProgramSelector[] programSelectors = ProgramSelector.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("Program selectors").that(programSelectors).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forProgramSelector() {
|
||||
ProgramSelector selectorExpected =
|
||||
getFmSelector(/* secondaryIds= */ null, /* vendorIds= */ null);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
selectorExpected.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
ProgramSelector selectorFromParcel = ProgramSelector.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("Program selector created from parcel")
|
||||
.that(selectorFromParcel).isEqualTo(selectorExpected);
|
||||
}
|
||||
|
||||
private ProgramSelector getFmSelector(@Nullable ProgramSelector.Identifier[] secondaryIds,
|
||||
@Nullable long[] vendorIds) {
|
||||
return new ProgramSelector(FM_PROGRAM_TYPE, FM_IDENTIFIER, secondaryIds, vendorIds);
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertThrows;
|
||||
|
||||
import android.hardware.radio.Announcement;
|
||||
import android.hardware.radio.ProgramSelector;
|
||||
import android.os.Parcel;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -83,4 +84,35 @@ public final class RadioAnnouncementTest {
|
||||
vendorInfo.put("vendorKeyMock", "vendorValueMock");
|
||||
return vendorInfo;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forAnnouncement() {
|
||||
assertWithMessage("Radio announcement contents")
|
||||
.that(TEST_ANNOUNCEMENT.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forAnnouncementCreator() {
|
||||
int sizeExpected = 2;
|
||||
|
||||
Announcement[] announcements = Announcement.CREATOR.newArray(sizeExpected);
|
||||
|
||||
assertWithMessage("Announcements").that(announcements).hasLength(sizeExpected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forAnnouncement() {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
TEST_ANNOUNCEMENT.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
Announcement announcementFromParcel = Announcement.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("Selector of announcement created from parcel")
|
||||
.that(announcementFromParcel.getSelector()).isEqualTo(FM_PROGRAM_SELECTOR);
|
||||
assertWithMessage("Type of announcement created from parcel")
|
||||
.that(announcementFromParcel.getType()).isEqualTo(TRAFFIC_ANNOUNCEMENT_TYPE);
|
||||
assertWithMessage("Vendor info of announcement created from parcel")
|
||||
.that(announcementFromParcel.getVendorInfo()).isEqualTo(VENDOR_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.hardware.radio.ProgramSelector;
|
||||
import android.hardware.radio.RadioManager;
|
||||
import android.hardware.radio.RadioMetadata;
|
||||
import android.hardware.radio.RadioTuner;
|
||||
import android.os.Parcel;
|
||||
import android.os.RemoteException;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
@@ -80,6 +81,8 @@ public final class RadioManagerTest {
|
||||
private static final int[] SUPPORTED_IDENTIFIERS_TYPES = new int[]{
|
||||
ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY, ProgramSelector.IDENTIFIER_TYPE_RDS_PI};
|
||||
|
||||
private static final int CREATOR_ARRAY_SIZE = 3;
|
||||
|
||||
private static final RadioManager.FmBandDescriptor FM_BAND_DESCRIPTOR =
|
||||
createFmBandDescriptor();
|
||||
private static final RadioManager.AmBandDescriptor AM_BAND_DESCRIPTOR =
|
||||
@@ -172,6 +175,22 @@ public final class RadioManagerTest {
|
||||
.that(bandDescriptor.getSpacing()).isEqualTo(AM_SPACING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forBandDescriptor() {
|
||||
RadioManager.BandDescriptor bandDescriptor = createFmBandDescriptor();
|
||||
|
||||
assertWithMessage("Band Descriptor contents")
|
||||
.that(bandDescriptor.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forBandDescriptorCreator() {
|
||||
RadioManager.BandDescriptor[] bandDescriptors =
|
||||
RadioManager.BandDescriptor.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("Band Descriptors").that(bandDescriptors).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAmBand_forAmBandDescriptor_returnsTrue() {
|
||||
RadioManager.BandDescriptor bandDescriptor = createAmBandDescriptor();
|
||||
@@ -218,19 +237,74 @@ public final class RadioManagerTest {
|
||||
.that(FM_BAND_DESCRIPTOR.isEaSupported()).isEqualTo(EA_SUPPORTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forFmBandDescriptor() {
|
||||
assertWithMessage("FM Band Descriptor contents")
|
||||
.that(FM_BAND_DESCRIPTOR.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forFmBandDescriptor() {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
FM_BAND_DESCRIPTOR.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
RadioManager.FmBandDescriptor fmBandDescriptorFromParcel =
|
||||
RadioManager.FmBandDescriptor.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("FM Band Descriptor created from parcel")
|
||||
.that(fmBandDescriptorFromParcel).isEqualTo(FM_BAND_DESCRIPTOR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forFmBandDescriptorCreator() {
|
||||
RadioManager.FmBandDescriptor[] fmBandDescriptors =
|
||||
RadioManager.FmBandDescriptor.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("FM Band Descriptors")
|
||||
.that(fmBandDescriptors).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isStereoSupported_forAmBandDescriptor() {
|
||||
assertWithMessage("AM Band Descriptor stereo")
|
||||
.that(AM_BAND_DESCRIPTOR.isStereoSupported()).isEqualTo(STEREO_SUPPORTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forAmBandDescriptor() {
|
||||
assertWithMessage("AM Band Descriptor contents")
|
||||
.that(AM_BAND_DESCRIPTOR.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forAmBandDescriptor() {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
AM_BAND_DESCRIPTOR.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
RadioManager.AmBandDescriptor amBandDescriptorFromParcel =
|
||||
RadioManager.AmBandDescriptor.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("FM Band Descriptor created from parcel")
|
||||
.that(amBandDescriptorFromParcel).isEqualTo(AM_BAND_DESCRIPTOR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forAmBandDescriptorCreator() {
|
||||
RadioManager.AmBandDescriptor[] amBandDescriptors =
|
||||
RadioManager.AmBandDescriptor.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("AM Band Descriptors")
|
||||
.that(amBandDescriptors).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_withSameFmBandDescriptors_returnsTrue() {
|
||||
RadioManager.FmBandDescriptor fmBandDescriptor1 = createFmBandDescriptor();
|
||||
RadioManager.FmBandDescriptor fmBandDescriptor2 = createFmBandDescriptor();
|
||||
RadioManager.FmBandDescriptor fmBandDescriptorCompared = createFmBandDescriptor();
|
||||
|
||||
assertWithMessage("The same FM Band Descriptor")
|
||||
.that(fmBandDescriptor1).isEqualTo(fmBandDescriptor2);
|
||||
.that(FM_BAND_DESCRIPTOR).isEqualTo(fmBandDescriptorCompared);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -257,6 +331,44 @@ public final class RadioManagerTest {
|
||||
.that(AM_BAND_DESCRIPTOR).isNotEqualTo(FM_BAND_DESCRIPTOR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withSameFmBandDescriptors_equals() {
|
||||
RadioManager.FmBandDescriptor fmBandDescriptorCompared = createFmBandDescriptor();
|
||||
|
||||
assertWithMessage("Hash code of the same FM Band Descriptor")
|
||||
.that(fmBandDescriptorCompared.hashCode()).isEqualTo(FM_BAND_DESCRIPTOR.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withSameAmBandDescriptors_equals() {
|
||||
RadioManager.AmBandDescriptor amBandDescriptorCompared = createAmBandDescriptor();
|
||||
|
||||
assertWithMessage("Hash code of the same AM Band Descriptor")
|
||||
.that(amBandDescriptorCompared.hashCode()).isEqualTo(AM_BAND_DESCRIPTOR.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withFmBandDescriptorsOfDifferentAfSupports_notEquals() {
|
||||
RadioManager.FmBandDescriptor fmBandDescriptorCompared = new RadioManager.FmBandDescriptor(
|
||||
REGION, RadioManager.BAND_FM, FM_LOWER_LIMIT, FM_UPPER_LIMIT, FM_SPACING,
|
||||
STEREO_SUPPORTED, RDS_SUPPORTED, TA_SUPPORTED, !AF_SUPPORTED, EA_SUPPORTED);
|
||||
|
||||
assertWithMessage("Hash code of FM Band Descriptor of different spacing")
|
||||
.that(fmBandDescriptorCompared.hashCode())
|
||||
.isNotEqualTo(FM_BAND_DESCRIPTOR.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withAmBandDescriptorsOfDifferentSpacings_notEquals() {
|
||||
RadioManager.AmBandDescriptor amBandDescriptorCompared =
|
||||
new RadioManager.AmBandDescriptor(REGION, RadioManager.BAND_AM, AM_LOWER_LIMIT,
|
||||
AM_UPPER_LIMIT, AM_SPACING * 2, STEREO_SUPPORTED);
|
||||
|
||||
assertWithMessage("Hash code of AM Band Descriptor of different spacing")
|
||||
.that(amBandDescriptorCompared.hashCode())
|
||||
.isNotEqualTo(AM_BAND_DESCRIPTOR.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getType_forBandConfig() {
|
||||
RadioManager.BandConfig fmBandConfig = createFmBandConfig();
|
||||
@@ -297,9 +409,25 @@ public final class RadioManagerTest {
|
||||
.that(fmBandConfig.getSpacing()).isEqualTo(FM_SPACING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forBandConfig() {
|
||||
RadioManager.BandConfig bandConfig = createFmBandConfig();
|
||||
|
||||
assertWithMessage("FM Band Config contents")
|
||||
.that(bandConfig.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forBandConfigCreator() {
|
||||
RadioManager.BandConfig[] bandConfigs =
|
||||
RadioManager.BandConfig.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("Band Configs").that(bandConfigs).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStereo_forFmBandConfig() {
|
||||
assertWithMessage("FM Band Config stereo ")
|
||||
assertWithMessage("FM Band Config stereo")
|
||||
.that(FM_BAND_CONFIG.getStereo()).isEqualTo(STEREO_SUPPORTED);
|
||||
}
|
||||
|
||||
@@ -327,12 +455,66 @@ public final class RadioManagerTest {
|
||||
.that(FM_BAND_CONFIG.getEa()).isEqualTo(EA_SUPPORTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forFmBandConfig() {
|
||||
assertWithMessage("FM Band Config contents")
|
||||
.that(FM_BAND_CONFIG.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forFmBandConfig() {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
FM_BAND_CONFIG.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
RadioManager.FmBandConfig fmBandConfigFromParcel =
|
||||
RadioManager.FmBandConfig.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("FM Band Config created from parcel")
|
||||
.that(fmBandConfigFromParcel).isEqualTo(FM_BAND_CONFIG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forFmBandConfigCreator() {
|
||||
RadioManager.FmBandConfig[] fmBandConfigs =
|
||||
RadioManager.FmBandConfig.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("FM Band Configs").that(fmBandConfigs).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStereo_forAmBandConfig() {
|
||||
assertWithMessage("AM Band Config stereo")
|
||||
.that(AM_BAND_CONFIG.getStereo()).isEqualTo(STEREO_SUPPORTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forAmBandConfig() {
|
||||
assertWithMessage("AM Band Config contents")
|
||||
.that(AM_BAND_CONFIG.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forAmBandConfig() {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
AM_BAND_CONFIG.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
RadioManager.AmBandConfig amBandConfigFromParcel =
|
||||
RadioManager.AmBandConfig.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("AM Band Config created from parcel")
|
||||
.that(amBandConfigFromParcel).isEqualTo(AM_BAND_CONFIG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forAmBandConfigCreator() {
|
||||
RadioManager.AmBandConfig[] amBandConfigs =
|
||||
RadioManager.AmBandConfig.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("AM Band Configs").that(amBandConfigs).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_withSameFmBandConfigs_returnsTrue() {
|
||||
RadioManager.FmBandConfig fmBandConfigCompared = createFmBandConfig();
|
||||
@@ -386,6 +568,43 @@ public final class RadioManagerTest {
|
||||
.that(AM_BAND_CONFIG).isNotEqualTo(amBandConfigFromBuilder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withSameFmBandConfigs_equals() {
|
||||
RadioManager.FmBandConfig fmBandConfigCompared = createFmBandConfig();
|
||||
|
||||
assertWithMessage("Hash code of the same FM Band Config")
|
||||
.that(FM_BAND_CONFIG.hashCode()).isEqualTo(fmBandConfigCompared.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withSameAmBandConfigs_equals() {
|
||||
RadioManager.AmBandConfig amBandConfigCompared = createAmBandConfig();
|
||||
|
||||
assertWithMessage("Hash code of the same AM Band Config")
|
||||
.that(amBandConfigCompared.hashCode()).isEqualTo(AM_BAND_CONFIG.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withFmBandConfigsOfDifferentTypes_notEquals() {
|
||||
RadioManager.FmBandConfig fmBandConfigCompared = new RadioManager.FmBandConfig(
|
||||
new RadioManager.FmBandDescriptor(REGION, RadioManager.BAND_FM_HD, FM_LOWER_LIMIT,
|
||||
FM_UPPER_LIMIT, FM_SPACING, STEREO_SUPPORTED, RDS_SUPPORTED, TA_SUPPORTED,
|
||||
AF_SUPPORTED, EA_SUPPORTED));
|
||||
|
||||
assertWithMessage("Hash code of FM Band Config with different type")
|
||||
.that(fmBandConfigCompared.hashCode()).isNotEqualTo(FM_BAND_CONFIG.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withAmBandConfigsOfDifferentStereoSupports_notEquals() {
|
||||
RadioManager.AmBandConfig amBandConfigCompared = new RadioManager.AmBandConfig(
|
||||
new RadioManager.AmBandDescriptor(REGION, RadioManager.BAND_AM, AM_LOWER_LIMIT,
|
||||
AM_UPPER_LIMIT, AM_SPACING, !STEREO_SUPPORTED));
|
||||
|
||||
assertWithMessage("Hash code of AM Band Config with different stereo support")
|
||||
.that(amBandConfigCompared.hashCode()).isNotEqualTo(AM_BAND_CONFIG.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getId_forModuleProperties() {
|
||||
assertWithMessage("Properties id")
|
||||
@@ -508,6 +727,12 @@ public final class RadioManagerTest {
|
||||
.containsExactly(AM_BAND_DESCRIPTOR, FM_BAND_DESCRIPTOR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forModuleProperties() {
|
||||
assertWithMessage("Module properties contents")
|
||||
.that(AMFM_PROPERTIES.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_withSameProperties_returnsTrue() {
|
||||
RadioManager.ModuleProperties propertiesCompared = createAmFmProperties();
|
||||
@@ -529,6 +754,23 @@ public final class RadioManagerTest {
|
||||
.that(AMFM_PROPERTIES).isNotEqualTo(propertiesDab);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withSameModuleProperties_equals() {
|
||||
RadioManager.ModuleProperties propertiesCompared = createAmFmProperties();
|
||||
|
||||
assertWithMessage("Hash code of the same module properties")
|
||||
.that(propertiesCompared.hashCode()).isEqualTo(AMFM_PROPERTIES.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forModulePropertiesCreator() {
|
||||
RadioManager.ModuleProperties[] modulePropertiesArray =
|
||||
RadioManager.ModuleProperties.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("Module properties array")
|
||||
.that(modulePropertiesArray).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSelector_forProgramInfo() {
|
||||
assertWithMessage("Selector of DAB program info")
|
||||
@@ -549,7 +791,7 @@ public final class RadioManagerTest {
|
||||
|
||||
@Test
|
||||
public void getRelatedContent_forProgramInfo() {
|
||||
assertWithMessage("Related contents of DAB program info")
|
||||
assertWithMessage("DAB program info contents")
|
||||
.that(DAB_PROGRAM_INFO.getRelatedContent())
|
||||
.containsExactly(DAB_SID_EXT_IDENTIFIER_RELATED);
|
||||
}
|
||||
@@ -626,6 +868,33 @@ public final class RadioManagerTest {
|
||||
.that(DAB_PROGRAM_INFO.getVendorInfo()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forProgramInfo() {
|
||||
assertWithMessage("Program info contents")
|
||||
.that(DAB_PROGRAM_INFO.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forProgramInfoCreator() {
|
||||
RadioManager.ProgramInfo[] programInfoArray =
|
||||
RadioManager.ProgramInfo.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("Program infos").that(programInfoArray).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forProgramInfo() {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
DAB_PROGRAM_INFO.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
RadioManager.ProgramInfo programInfoFromParcel =
|
||||
RadioManager.ProgramInfo.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("Program info created from parcel")
|
||||
.that(programInfoFromParcel).isEqualTo(DAB_PROGRAM_INFO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_withSameProgramInfo_returnsTrue() {
|
||||
RadioManager.ProgramInfo dabProgramInfoCompared = createDabProgramInfo(DAB_SELECTOR);
|
||||
|
||||
@@ -20,18 +20,63 @@ import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.hardware.radio.RadioMetadata;
|
||||
import android.os.Parcel;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public final class RadioMetadataTest {
|
||||
|
||||
private static final int CREATOR_ARRAY_SIZE = 3;
|
||||
private static final int INT_KEY_VALUE = 1;
|
||||
private static final long TEST_UTC_SECOND_SINCE_EPOCH = 200;
|
||||
private static final int TEST_TIME_ZONE_OFFSET_MINUTES = 1;
|
||||
|
||||
private final RadioMetadata.Builder mBuilder = new RadioMetadata.Builder();
|
||||
|
||||
@Mock
|
||||
private Bitmap mBitmapValue;
|
||||
|
||||
@Test
|
||||
public void describeContents_forClock() {
|
||||
RadioMetadata.Clock clock = new RadioMetadata.Clock(TEST_UTC_SECOND_SINCE_EPOCH,
|
||||
TEST_TIME_ZONE_OFFSET_MINUTES);
|
||||
|
||||
assertWithMessage("Describe contents for metadata clock")
|
||||
.that(clock.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forClockCreator() {
|
||||
RadioMetadata.Clock[] clocks = RadioMetadata.Clock.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("Clock array size").that(clocks.length).isEqualTo(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forClock() {
|
||||
RadioMetadata.Clock clockExpected = new RadioMetadata.Clock(TEST_UTC_SECOND_SINCE_EPOCH,
|
||||
TEST_TIME_ZONE_OFFSET_MINUTES);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
clockExpected.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
RadioMetadata.Clock clockFromParcel = RadioMetadata.Clock.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("UTC second since epoch of metadata clock created from parcel")
|
||||
.that(clockFromParcel.getUtcEpochSeconds()).isEqualTo(TEST_UTC_SECOND_SINCE_EPOCH);
|
||||
assertWithMessage("Time zone offset minutes of metadata clock created from parcel")
|
||||
.that(clockFromParcel.getTimezoneOffsetMinutes())
|
||||
.isEqualTo(TEST_TIME_ZONE_OFFSET_MINUTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putString_withIllegalKey() {
|
||||
String invalidStringKey = RadioMetadata.METADATA_KEY_RDS_PI;
|
||||
@@ -128,23 +173,57 @@ public final class RadioMetadataTest {
|
||||
.that(metadata.getString(key)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBitmap_withKeyInMetadata() {
|
||||
String key = RadioMetadata.METADATA_KEY_ICON;
|
||||
RadioMetadata metadata = mBuilder.putBitmap(key, mBitmapValue).build();
|
||||
|
||||
assertWithMessage("Bitmap value for key %s in metadata", key)
|
||||
.that(metadata.getBitmap(key)).isEqualTo(mBitmapValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBitmap_withKeyNotInMetadata() {
|
||||
String key = RadioMetadata.METADATA_KEY_ICON;
|
||||
RadioMetadata metadata = mBuilder.build();
|
||||
|
||||
assertWithMessage("Bitmap value for key %s not in metadata", key)
|
||||
.that(metadata.getBitmap(key)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBitmapId_withKeyInMetadata() {
|
||||
String key = RadioMetadata.METADATA_KEY_ART;
|
||||
RadioMetadata metadata = mBuilder.putInt(key, INT_KEY_VALUE).build();
|
||||
|
||||
assertWithMessage("Bitmap id value for key %s in metadata", key)
|
||||
.that(metadata.getBitmapId(key)).isEqualTo(INT_KEY_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBitmapId_withKeyNotInMetadata() {
|
||||
String key = RadioMetadata.METADATA_KEY_ART;
|
||||
RadioMetadata metadata = mBuilder.build();
|
||||
|
||||
assertWithMessage("Bitmap id value for key %s not in metadata", key)
|
||||
.that(metadata.getBitmapId(key)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getClock_withKeyInMetadata() {
|
||||
String key = RadioMetadata.METADATA_KEY_CLOCK;
|
||||
long utcSecondsSinceEpochExpected = 200;
|
||||
int timezoneOffsetMinutesExpected = 1;
|
||||
RadioMetadata metadata = mBuilder
|
||||
.putClock(key, utcSecondsSinceEpochExpected, timezoneOffsetMinutesExpected)
|
||||
.putClock(key, TEST_UTC_SECOND_SINCE_EPOCH, TEST_TIME_ZONE_OFFSET_MINUTES)
|
||||
.build();
|
||||
|
||||
RadioMetadata.Clock clockExpected = metadata.getClock(key);
|
||||
|
||||
assertWithMessage("Number of seconds since epoch of value for key %s in metadata", key)
|
||||
.that(clockExpected.getUtcEpochSeconds())
|
||||
.isEqualTo(utcSecondsSinceEpochExpected);
|
||||
.isEqualTo(TEST_UTC_SECOND_SINCE_EPOCH);
|
||||
assertWithMessage("Offset of timezone in minutes of value for key %s in metadata", key)
|
||||
.that(clockExpected.getTimezoneOffsetMinutes())
|
||||
.isEqualTo(timezoneOffsetMinutesExpected);
|
||||
.isEqualTo(TEST_TIME_ZONE_OFFSET_MINUTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,12 +259,13 @@ public final class RadioMetadataTest {
|
||||
RadioMetadata metadata = mBuilder
|
||||
.putInt(RadioMetadata.METADATA_KEY_RDS_PI, INT_KEY_VALUE)
|
||||
.putString(RadioMetadata.METADATA_KEY_ARTIST, "artistTest")
|
||||
.putBitmap(RadioMetadata.METADATA_KEY_ICON, mBitmapValue)
|
||||
.build();
|
||||
|
||||
Set<String> metadataSet = metadata.keySet();
|
||||
|
||||
assertWithMessage("Metadata set of non-empty metadata")
|
||||
.that(metadataSet).containsExactly(
|
||||
.that(metadataSet).containsExactly(RadioMetadata.METADATA_KEY_ICON,
|
||||
RadioMetadata.METADATA_KEY_RDS_PI, RadioMetadata.METADATA_KEY_ARTIST);
|
||||
}
|
||||
|
||||
@@ -208,4 +288,46 @@ public final class RadioMetadataTest {
|
||||
.that(key).isEqualTo(RadioMetadata.METADATA_KEY_RDS_PI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_forMetadataWithSameContents_returnsTrue() {
|
||||
RadioMetadata metadata = mBuilder
|
||||
.putInt(RadioMetadata.METADATA_KEY_RDS_PI, INT_KEY_VALUE)
|
||||
.putString(RadioMetadata.METADATA_KEY_ARTIST, "artistTest")
|
||||
.build();
|
||||
RadioMetadata.Builder copyBuilder = new RadioMetadata.Builder(metadata);
|
||||
RadioMetadata metadataCopied = copyBuilder.build();
|
||||
|
||||
assertWithMessage("Metadata with the same contents")
|
||||
.that(metadataCopied).isEqualTo(metadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeContents_forMetadata() {
|
||||
RadioMetadata metadata = mBuilder.build();
|
||||
|
||||
assertWithMessage("Metadata contents").that(metadata.describeContents()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newArray_forRadioMetadataCreator() {
|
||||
RadioMetadata[] metadataArray = RadioMetadata.CREATOR.newArray(CREATOR_ARRAY_SIZE);
|
||||
|
||||
assertWithMessage("Radio metadata array").that(metadataArray).hasLength(CREATOR_ARRAY_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToParcel_forRadioMetadata() {
|
||||
RadioMetadata metadataExpected = mBuilder
|
||||
.putInt(RadioMetadata.METADATA_KEY_RDS_PI, INT_KEY_VALUE)
|
||||
.putString(RadioMetadata.METADATA_KEY_ARTIST, "artistTest")
|
||||
.build();
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
metadataExpected.writeToParcel(parcel, /* flags= */ 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
RadioMetadata metadataFromParcel = RadioMetadata.CREATOR.createFromParcel(parcel);
|
||||
assertWithMessage("Radio metadata created from parcel")
|
||||
.that(metadataFromParcel).isEqualTo(metadataExpected);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user