Back to Repositories

Testing ICY Metadata Decoder Implementation in SmartTube

This test suite validates the IcyDecoder implementation in ExoPlayer, focusing on parsing ICY metadata from streaming media. It ensures proper handling of stream titles, URLs, and various edge cases in ICY metadata formatting.

Test Coverage Overview

The test suite provides comprehensive coverage of ICY metadata parsing scenarios:

  • Basic metadata parsing with title and URL
  • Title-only metadata handling
  • Edge cases including empty titles, special characters, and malformed data
  • Handling of line terminators and quotes in metadata
  • Processing of extra tags and unrecognized headers

Implementation Analysis

The testing approach uses JUnit with AndroidJUnit4 runner for Android-specific testing context. Tests follow arrange-act-assert pattern with clear separation of test cases. Each test method focuses on a specific aspect of ICY metadata parsing, using the Truth assertion library for precise verification.

Technical Details

Testing tools and configuration:

  • JUnit 4 test framework
  • AndroidJUnit4 test runner
  • Google Truth assertion library
  • IcyDecoder implementation testing
  • Metadata validation through IcyInfo objects

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Clear test method naming reflecting test purpose
  • Isolated test cases with single responsibility
  • Comprehensive edge case coverage
  • Consistent assertion patterns
  • Thorough validation of all metadata components

yuliskov/smarttube

exoplayer-amzn-2.10.6/library/core/src/test/java/com/google/android/exoplayer2/metadata/icy/IcyDecoderTest.java

            
/*
 * Copyright (C) 2018 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.google.android.exoplayer2.metadata.icy;

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

import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.metadata.Metadata;
import org.junit.Test;
import org.junit.runner.RunWith;

/** Test for {@link IcyDecoder}. */
@RunWith(AndroidJUnit4.class)
public final class IcyDecoderTest {

  @Test
  public void decode() {
    IcyDecoder decoder = new IcyDecoder();
    String icyContent = "StreamTitle='test title';StreamURL='test_url';";
    Metadata metadata = decoder.decode(icyContent);

    assertThat(metadata.length()).isEqualTo(1);
    IcyInfo streamInfo = (IcyInfo) metadata.get(0);
    assertThat(streamInfo.rawMetadata).isEqualTo(icyContent);
    assertThat(streamInfo.title).isEqualTo("test title");
    assertThat(streamInfo.url).isEqualTo("test_url");
  }

  @Test
  public void decode_titleOnly() {
    IcyDecoder decoder = new IcyDecoder();
    String icyContent = "StreamTitle='test title';";
    Metadata metadata = decoder.decode(icyContent);

    assertThat(metadata.length()).isEqualTo(1);
    IcyInfo streamInfo = (IcyInfo) metadata.get(0);
    assertThat(streamInfo.rawMetadata).isEqualTo(icyContent);
    assertThat(streamInfo.title).isEqualTo("test title");
    assertThat(streamInfo.url).isNull();
  }

  @Test
  public void decode_extraTags() {
    String icyContent =
        "StreamTitle='test title';StreamURL='test_url';CustomTag|withWeirdSeparator";
    IcyDecoder decoder = new IcyDecoder();
    Metadata metadata = decoder.decode(icyContent);

    assertThat(metadata.length()).isEqualTo(1);
    IcyInfo streamInfo = (IcyInfo) metadata.get(0);
    assertThat(streamInfo.rawMetadata).isEqualTo(icyContent);
    assertThat(streamInfo.title).isEqualTo("test title");
    assertThat(streamInfo.url).isEqualTo("test_url");
  }

  @Test
  public void decode_emptyTitle() {
    IcyDecoder decoder = new IcyDecoder();
    String icyContent = "StreamTitle='';StreamURL='test_url';";
    Metadata metadata = decoder.decode(icyContent);

    assertThat(metadata.length()).isEqualTo(1);
    IcyInfo streamInfo = (IcyInfo) metadata.get(0);
    assertThat(streamInfo.rawMetadata).isEqualTo(icyContent);
    assertThat(streamInfo.title).isEmpty();
    assertThat(streamInfo.url).isEqualTo("test_url");
  }

  @Test
  public void decode_semiColonInTitle() {
    IcyDecoder decoder = new IcyDecoder();
    String icyContent = "StreamTitle='test; title';StreamURL='test_url';";
    Metadata metadata = decoder.decode(icyContent);

    assertThat(metadata.length()).isEqualTo(1);
    IcyInfo streamInfo = (IcyInfo) metadata.get(0);
    assertThat(streamInfo.rawMetadata).isEqualTo(icyContent);
    assertThat(streamInfo.title).isEqualTo("test; title");
    assertThat(streamInfo.url).isEqualTo("test_url");
  }

  @Test
  public void decode_quoteInTitle() {
    IcyDecoder decoder = new IcyDecoder();
    String icyContent = "StreamTitle='test' title';StreamURL='test_url';";
    Metadata metadata = decoder.decode(icyContent);

    assertThat(metadata.length()).isEqualTo(1);
    IcyInfo streamInfo = (IcyInfo) metadata.get(0);
    assertThat(streamInfo.rawMetadata).isEqualTo(icyContent);
    assertThat(streamInfo.title).isEqualTo("test' title");
    assertThat(streamInfo.url).isEqualTo("test_url");
  }

  @Test
  public void decode_lineTerminatorInTitle() {
    IcyDecoder decoder = new IcyDecoder();
    String icyContent = "StreamTitle='test\r\ntitle';StreamURL='test_url';";
    Metadata metadata = decoder.decode(icyContent);

    assertThat(metadata.length()).isEqualTo(1);
    IcyInfo streamInfo = (IcyInfo) metadata.get(0);
    assertThat(streamInfo.rawMetadata).isEqualTo(icyContent);
    assertThat(streamInfo.title).isEqualTo("test\r\ntitle");
    assertThat(streamInfo.url).isEqualTo("test_url");
  }

  @Test
  public void decode_noReconisedHeaders() {
    IcyDecoder decoder = new IcyDecoder();
    Metadata metadata = decoder.decode("NotIcyData");

    assertThat(metadata.length()).isEqualTo(1);
    IcyInfo streamInfo = (IcyInfo) metadata.get(0);
    assertThat(streamInfo.rawMetadata).isEqualTo("NotIcyData");
    assertThat(streamInfo.title).isNull();
    assertThat(streamInfo.url).isNull();
  }
}