1 /*
2  * Copyright (C) 2017 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 
17 package com.android.tv.testing;
18 
19 import static com.google.common.truth.Fact.simpleFact;
20 
21 import android.support.annotation.Nullable;
22 import com.android.tv.data.ChannelNumber;
23 import com.google.common.truth.ComparableSubject;
24 import com.google.common.truth.FailureMetadata;
25 import com.google.common.truth.Subject;
26 import com.google.common.truth.Truth;
27 
28 /** Propositions for {@link ChannelNumber} subjects. */
29 public final class ChannelNumberSubject extends ComparableSubject {
30     private static final Subject.Factory<ChannelNumberSubject, ChannelNumber> FACTORY =
31             ChannelNumberSubject::new;
32 
channelNumbers()33     public static Subject.Factory<ChannelNumberSubject, ChannelNumber> channelNumbers() {
34         return FACTORY;
35     }
36 
assertThat(@ullable ChannelNumber actual)37     public static ChannelNumberSubject assertThat(@Nullable ChannelNumber actual) {
38         return Truth.assertAbout(channelNumbers()).that(actual);
39     }
40 
41   private final ChannelNumber actual;
42 
ChannelNumberSubject(FailureMetadata failureMetadata, @Nullable ChannelNumber subject)43   public ChannelNumberSubject(FailureMetadata failureMetadata, @Nullable ChannelNumber subject) {
44     super(failureMetadata, subject);
45     this.actual = subject;
46     }
47 
displaysAs(int major)48     public void displaysAs(int major) {
49     if (!actual.majorNumber.equals(Integer.toString(major)) || actual.hasDelimiter) {
50             failWithActual("expected to display as", major);
51         }
52     }
53 
displaysAs(int major, int minor)54     public void displaysAs(int major, int minor) {
55     if (!actual.majorNumber.equals(Integer.toString(major))
56         || !actual.minorNumber.equals(Integer.toString(minor))
57         || !actual.hasDelimiter) {
58             failWithActual("expected to display as", major + "-" + minor);
59         }
60     }
61 
isEmpty()62     public void isEmpty() {
63     if (!actual.majorNumber.isEmpty() || !actual.minorNumber.isEmpty() || actual.hasDelimiter) {
64             failWithActual(simpleFact("expected to be empty"));
65         }
66     }
67 }
68