Split up Id3DecoderTest methods

It's clearer if each test method follows the Arrange/Act/Assert pattern

PiperOrigin-RevId: 491299379
(cherry picked from commit fc5d17832f90f36eb30ee0058204d110e27adcc9)
This commit is contained in:
ibaker 2022-11-28 11:33:36 +00:00 committed by christosts
parent 887179f50a
commit 26f5e9b83c

View File

@ -37,8 +37,7 @@ public final class Id3DecoderTest {
private static final int ID3_TEXT_ENCODING_UTF_8 = 3;
@Test
public void decodeTxxxFrame() {
// Test UTF-8.
public void decodeTxxxFrame_utf8() {
byte[] rawId3 =
buildSingleFrameTag(
"TXXX",
@ -47,52 +46,74 @@ public final class Id3DecoderTest {
55, 54, 54, 52, 95, 115, 116, 97, 114, 116, 0
});
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TXXX");
assertThat(textInformationFrame.description).isEmpty();
assertThat(textInformationFrame.values.get(0)).isEqualTo("mdialog_VINDICO1527664_start");
}
// Test UTF-16.
rawId3 =
@Test
public void decodeTxxxFrame_utf16() {
byte[] rawId3 =
buildSingleFrameTag(
"TXXX",
new byte[] {
1, 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0,
100, 0, 0
});
metadata = decoder.decode(rawId3, rawId3.length);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
textInformationFrame = (TextInformationFrame) metadata.get(0);
TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TXXX");
assertThat(textInformationFrame.description).isEqualTo("Hello World");
assertThat(textInformationFrame.values).containsExactly("");
}
// Test multiple values.
rawId3 =
@Test
public void decodeTxxxFrame_multipleValues() {
byte[] rawId3 =
buildSingleFrameTag(
"TXXX",
new byte[] {
1, 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0,
100, 0, 0, 0, 70, 0, 111, 0, 111, 0, 0, 0, 66, 0, 97, 0, 114, 0, 0
});
metadata = decoder.decode(rawId3, rawId3.length);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
textInformationFrame = (TextInformationFrame) metadata.get(0);
TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.description).isEqualTo("Hello World");
assertThat(textInformationFrame.values).containsExactly("Foo", "Bar").inOrder();
}
@Test
public void decodeTxxxFrame_empty() {
byte[] rawId3 = buildSingleFrameTag("TXXX", new byte[0]);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test empty.
rawId3 = buildSingleFrameTag("TXXX", new byte[0]);
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(0);
}
@Test
public void decodeTxxxFrame_encodingByteOnly() {
byte[] rawId3 = buildSingleFrameTag("TXXX", new byte[] {ID3_TEXT_ENCODING_UTF_8});
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test encoding byte only.
rawId3 = buildSingleFrameTag("TXXX", new byte[] {ID3_TEXT_ENCODING_UTF_8});
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
textInformationFrame = (TextInformationFrame) metadata.get(0);
TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TXXX");
assertThat(textInformationFrame.description).isEmpty();
assertThat(textInformationFrame.values).containsExactly("");
@ -104,31 +125,49 @@ public final class Id3DecoderTest {
buildSingleFrameTag(
"TIT2", new byte[] {3, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0});
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TIT2");
assertThat(textInformationFrame.description).isNull();
assertThat(textInformationFrame.values.size()).isEqualTo(1);
assertThat(textInformationFrame.values.get(0)).isEqualTo("Hello World");
}
@Test
public void decodeTextInformationFrame_multipleValues() {
// Test multiple values.
rawId3 = buildSingleFrameTag("TIT2", new byte[] {3, 70, 111, 111, 0, 66, 97, 114, 0});
metadata = decoder.decode(rawId3, rawId3.length);
byte[] rawId3 = buildSingleFrameTag("TIT2", new byte[] {3, 70, 111, 111, 0, 66, 97, 114, 0});
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
textInformationFrame = (TextInformationFrame) metadata.get(0);
TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.values).containsExactly("Foo", "Bar").inOrder();
}
@Test
public void decodeTextInformationFrame_empty() {
byte[] rawId3 = buildSingleFrameTag("TIT2", new byte[0]);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test empty.
rawId3 = buildSingleFrameTag("TIT2", new byte[0]);
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(0);
}
@Test
public void decodeTextInformationFrame_encodingByteOnly() {
byte[] rawId3 = buildSingleFrameTag("TIT2", new byte[] {ID3_TEXT_ENCODING_UTF_8});
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test encoding byte only.
rawId3 = buildSingleFrameTag("TIT2", new byte[] {ID3_TEXT_ENCODING_UTF_8});
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
textInformationFrame = (TextInformationFrame) metadata.get(0);
TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TIT2");
assertThat(textInformationFrame.description).isNull();
assertThat(textInformationFrame.values).containsExactly("");
@ -172,23 +211,35 @@ public final class Id3DecoderTest {
102
});
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
UrlLinkFrame urlLinkFrame = (UrlLinkFrame) metadata.get(0);
assertThat(urlLinkFrame.id).isEqualTo("WXXX");
assertThat(urlLinkFrame.description).isEqualTo("test");
assertThat(urlLinkFrame.url).isEqualTo("https://test.com/abc?def");
}
@Test
public void decodeWxxxFrame_empty() {
byte[] rawId3 = buildSingleFrameTag("WXXX", new byte[0]);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test empty.
rawId3 = buildSingleFrameTag("WXXX", new byte[0]);
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(0);
}
@Test
public void decodeWxxxFrame_encodingByteOnly() {
byte[] rawId3 = buildSingleFrameTag("WXXX", new byte[] {ID3_TEXT_ENCODING_UTF_8});
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test encoding byte only.
rawId3 = buildSingleFrameTag("WXXX", new byte[] {ID3_TEXT_ENCODING_UTF_8});
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
urlLinkFrame = (UrlLinkFrame) metadata.get(0);
UrlLinkFrame urlLinkFrame = (UrlLinkFrame) metadata.get(0);
assertThat(urlLinkFrame.id).isEqualTo("WXXX");
assertThat(urlLinkFrame.description).isEmpty();
assertThat(urlLinkFrame.url).isEmpty();
@ -210,12 +261,17 @@ public final class Id3DecoderTest {
assertThat(urlLinkFrame.id).isEqualTo("WCOM");
assertThat(urlLinkFrame.description).isNull();
assertThat(urlLinkFrame.url).isEqualTo("https://test.com/abc?def");
}
@Test
public void decodeUrlLinkFrame_empty() {
byte[] rawId3 = buildSingleFrameTag("WCOM", new byte[0]);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test empty.
rawId3 = buildSingleFrameTag("WCOM", new byte[0]);
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
urlLinkFrame = (UrlLinkFrame) metadata.get(0);
UrlLinkFrame urlLinkFrame = (UrlLinkFrame) metadata.get(0);
assertThat(urlLinkFrame.id).isEqualTo("WCOM");
assertThat(urlLinkFrame.description).isNull();
assertThat(urlLinkFrame.url).isEmpty();
@ -230,12 +286,17 @@ public final class Id3DecoderTest {
PrivFrame privFrame = (PrivFrame) metadata.get(0);
assertThat(privFrame.owner).isEqualTo("test");
assertThat(privFrame.privateData).isEqualTo(new byte[] {1, 2, 3, 4});
}
@Test
public void decodePrivFrame_empty() {
byte[] rawId3 = buildSingleFrameTag("PRIV", new byte[0]);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test empty.
rawId3 = buildSingleFrameTag("PRIV", new byte[0]);
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
privFrame = (PrivFrame) metadata.get(0);
PrivFrame privFrame = (PrivFrame) metadata.get(0);
assertThat(privFrame.owner).isEmpty();
assertThat(privFrame.privateData).isEqualTo(new byte[0]);
}
@ -258,9 +319,11 @@ public final class Id3DecoderTest {
assertThat(apicFrame.description).isEqualTo("Hello World");
assertThat(apicFrame.pictureData).hasLength(10);
assertThat(apicFrame.pictureData).isEqualTo(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0});
}
// Test with UTF-16 description at even offset.
rawId3 =
@Test
public void decodeApicFrame_utf16DescriptionEvenOffset() {
byte[] rawId3 =
buildSingleFrameTag(
"APIC",
new byte[] {
@ -268,28 +331,34 @@ public final class Id3DecoderTest {
108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100, 0, 0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 0
});
decoder = new Id3Decoder();
metadata = decoder.decode(rawId3, rawId3.length);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
apicFrame = (ApicFrame) metadata.get(0);
ApicFrame apicFrame = (ApicFrame) metadata.get(0);
assertThat(apicFrame.mimeType).isEqualTo("image/jpeg");
assertThat(apicFrame.pictureType).isEqualTo(16);
assertThat(apicFrame.description).isEqualTo("Hello World");
assertThat(apicFrame.pictureData).hasLength(10);
assertThat(apicFrame.pictureData).isEqualTo(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0});
}
// Test with UTF-16 description at odd offset.
rawId3 =
@Test
public void decodeApicFrame_utf16DescriptionOddOffset() {
byte[] rawId3 =
buildSingleFrameTag(
"APIC",
new byte[] {
1, 105, 109, 97, 103, 101, 47, 112, 110, 103, 0, 16, 0, 72, 0, 101, 0, 108, 0, 108, 0,
111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
});
decoder = new Id3Decoder();
metadata = decoder.decode(rawId3, rawId3.length);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
apicFrame = (ApicFrame) metadata.get(0);
ApicFrame apicFrame = (ApicFrame) metadata.get(0);
assertThat(apicFrame.mimeType).isEqualTo("image/png");
assertThat(apicFrame.pictureType).isEqualTo(16);
assertThat(apicFrame.description).isEqualTo("Hello World");
@ -332,17 +401,28 @@ public final class Id3DecoderTest {
assertThat(commentFrame.language).isEqualTo("eng");
assertThat(commentFrame.description).isEqualTo("description");
assertThat(commentFrame.text).isEqualTo("text");
}
@Test
public void decodeCommentFrame_empty() {
byte[] rawId3 = buildSingleFrameTag("COMM", new byte[0]);
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test empty.
rawId3 = buildSingleFrameTag("COMM", new byte[0]);
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(0);
}
@Test
public void decodeCommentFrame_languageOnly() {
byte[] rawId3 =
buildSingleFrameTag("COMM", new byte[] {ID3_TEXT_ENCODING_UTF_8, 101, 110, 103});
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
// Test language only.
rawId3 = buildSingleFrameTag("COMM", new byte[] {ID3_TEXT_ENCODING_UTF_8, 101, 110, 103});
metadata = decoder.decode(rawId3, rawId3.length);
assertThat(metadata.length()).isEqualTo(1);
commentFrame = (CommentFrame) metadata.get(0);
CommentFrame commentFrame = (CommentFrame) metadata.get(0);
assertThat(commentFrame.language).isEqualTo("eng");
assertThat(commentFrame.description).isEmpty();
assertThat(commentFrame.text).isEmpty();