Home | History | Annotate | Download | only in data
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.tv.data;
     17 
     18 import static android.media.tv.TvContract.Programs.Genres.COMEDY;
     19 import static android.media.tv.TvContract.Programs.Genres.FAMILY_KIDS;
     20 
     21 import android.test.suitebuilder.annotation.SmallTest;
     22 
     23 import junit.framework.TestCase;
     24 
     25 import java.util.Arrays;
     26 
     27 /**
     28  * Tests for {@link Program}.
     29  */
     30 @SmallTest
     31 public class ProgramTest extends TestCase {
     32 
     33     private static final int NOT_FOUND_GENRE = 987;
     34 
     35     private static final int FAMILY_GENRE_ID = GenreItems.getId(FAMILY_KIDS);
     36 
     37     private static final int COMEDY_GENRE_ID = GenreItems.getId(COMEDY);
     38 
     39     public void testBuild() {
     40         Program program = new Program.Builder().build();
     41         assertEquals("isValid", false, program.isValid());
     42     }
     43 
     44     public void testNoGenres() {
     45         Program program = new Program.Builder()
     46                 .setCanonicalGenres("")
     47                 .build();
     48         assertNullCanonicalGenres(program);
     49         assertHasGenre(program, NOT_FOUND_GENRE, false);
     50         assertHasGenre(program, FAMILY_GENRE_ID, false);
     51         assertHasGenre(program, COMEDY_GENRE_ID, false);
     52         assertHasGenre(program, GenreItems.ID_ALL_CHANNELS, true);
     53     }
     54 
     55     public void testFamilyGenre() {
     56         Program program = new Program.Builder()
     57                 .setCanonicalGenres(FAMILY_KIDS)
     58                 .build();
     59         assertCanonicalGenres(program, FAMILY_KIDS);
     60         assertHasGenre(program, NOT_FOUND_GENRE, false);
     61         assertHasGenre(program, FAMILY_GENRE_ID, true);
     62         assertHasGenre(program, COMEDY_GENRE_ID, false);
     63         assertHasGenre(program, GenreItems.ID_ALL_CHANNELS, true);
     64     }
     65 
     66     public void testFamilyComedyGenre() {
     67         Program program = new Program.Builder()
     68                 .setCanonicalGenres(FAMILY_KIDS + ", " + COMEDY)
     69                 .build();
     70         assertCanonicalGenres(program, FAMILY_KIDS, COMEDY);
     71         assertHasGenre(program, NOT_FOUND_GENRE, false);
     72         assertHasGenre(program, FAMILY_GENRE_ID, true);
     73         assertHasGenre(program, COMEDY_GENRE_ID, true);
     74         assertHasGenre(program, GenreItems.ID_ALL_CHANNELS, true);
     75     }
     76 
     77     public void testOtherGenre() {
     78         Program program = new Program.Builder()
     79                 .setCanonicalGenres("other")
     80                 .build();
     81         assertCanonicalGenres(program);
     82         assertHasGenre(program, NOT_FOUND_GENRE, false);
     83         assertHasGenre(program, FAMILY_GENRE_ID, false);
     84         assertHasGenre(program, COMEDY_GENRE_ID, false);
     85         assertHasGenre(program, GenreItems.ID_ALL_CHANNELS, true);
     86     }
     87 
     88     private static void assertNullCanonicalGenres(Program program) {
     89         String[] actual = program.getCanonicalGenres();
     90         assertNull("Expected null canonical genres but was " + Arrays.toString(actual), actual);
     91     }
     92 
     93     private static void assertCanonicalGenres(Program program, String... expected) {
     94         assertEquals("canonical genres", Arrays.asList(expected),
     95                 Arrays.asList(program.getCanonicalGenres()));
     96     }
     97 
     98     private static void assertHasGenre(Program program, int genreId, boolean expected) {
     99         assertEquals("hasGenre(" + genreId + ")", expected, program.hasGenre(genreId));
    100     }
    101 }
    102