Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3feb263c
authored
Jan 14, 2020
by
olly
Committed by
Oliver Woodman
Jan 16, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Fix nullability issues for testutil.truth
PiperOrigin-RevId: 289658098
parent
4c74f3cf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
4 deletions
testutils/build.gradle
testutils/src/main/java/com/google/android/exoplayer2/testutil/truth/SpannedSubject.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/truth/package-info.java
testutils/build.gradle
View file @
3feb263c
...
@@ -36,6 +36,8 @@ dependencies {
...
@@ -36,6 +36,8 @@ dependencies {
api
'androidx.test.ext:junit:'
+
androidxTestJUnitVersion
api
'androidx.test.ext:junit:'
+
androidxTestJUnitVersion
api
'junit:junit:'
+
junitVersion
api
'junit:junit:'
+
junitVersion
api
'com.google.truth:truth:'
+
truthVersion
api
'com.google.truth:truth:'
+
truthVersion
compileOnly
'org.checkerframework:checker-qual:'
+
checkerframeworkVersion
compileOnly
'org.checkerframework:checker-compat-qual:'
+
checkerframeworkVersion
implementation
'androidx.annotation:annotation:'
+
androidxAnnotationVersion
implementation
'androidx.annotation:annotation:'
+
androidxAnnotationVersion
implementation
project
(
modulePrefix
+
'library-core'
)
implementation
project
(
modulePrefix
+
'library-core'
)
testImplementation
project
(
modulePrefix
+
'testutils'
)
testImplementation
project
(
modulePrefix
+
'testutils'
)
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/truth/SpannedSubject.java
View file @
3feb263c
...
@@ -45,6 +45,8 @@ import java.util.ArrayList;
...
@@ -45,6 +45,8 @@ import java.util.ArrayList;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
org.checkerframework.checker.nullness.compatqual.NullableType
;
import
org.checkerframework.checker.nullness.qual.RequiresNonNull
;
/** A Truth {@link Subject} for assertions on {@link Spanned} instances containing text styling. */
/** A Truth {@link Subject} for assertions on {@link Spanned} instances containing text styling. */
// TODO: add support for more Spans i.e. all those used in com.google.android.exoplayer2.text.
// TODO: add support for more Spans i.e. all those used in com.google.android.exoplayer2.text.
...
@@ -74,6 +76,11 @@ public final class SpannedSubject extends Subject {
...
@@ -74,6 +76,11 @@ public final class SpannedSubject extends Subject {
}
}
public
void
hasNoSpans
()
{
public
void
hasNoSpans
()
{
if
(
actual
==
null
)
{
failWithoutActual
(
simpleFact
(
"Spanned must not be null"
));
return
;
}
Object
[]
spans
=
actual
.
getSpans
(
0
,
actual
.
length
(),
Object
.
class
);
Object
[]
spans
=
actual
.
getSpans
(
0
,
actual
.
length
(),
Object
.
class
);
if
(
spans
.
length
>
0
)
{
if
(
spans
.
length
>
0
)
{
failWithoutActual
(
failWithoutActual
(
...
@@ -599,7 +606,8 @@ public final class SpannedSubject extends Subject {
...
@@ -599,7 +606,8 @@ public final class SpannedSubject extends Subject {
failWithoutActual
(
simpleFact
(
"Spanned must not be null"
));
failWithoutActual
(
simpleFact
(
"Spanned must not be null"
));
return
;
return
;
}
}
Object
[]
matchingSpans
=
actual
.
getSpans
(
start
,
end
,
spanClazz
);
@NullableType
Object
[]
matchingSpans
=
actual
.
getSpans
(
start
,
end
,
spanClazz
);
if
(
matchingSpans
.
length
!=
0
)
{
if
(
matchingSpans
.
length
!=
0
)
{
failWithoutActual
(
failWithoutActual
(
simpleFact
(
simpleFact
(
...
@@ -612,15 +620,21 @@ public final class SpannedSubject extends Subject {
...
@@ -612,15 +620,21 @@ public final class SpannedSubject extends Subject {
}
}
private
<
T
>
List
<
T
>
findMatchingSpans
(
int
startIndex
,
int
endIndex
,
Class
<
T
>
spanClazz
)
{
private
<
T
>
List
<
T
>
findMatchingSpans
(
int
startIndex
,
int
endIndex
,
Class
<
T
>
spanClazz
)
{
if
(
actual
==
null
)
{
failWithoutActual
(
simpleFact
(
"Spanned must not be null"
));
return
Collections
.
emptyList
();
}
List
<
T
>
spans
=
new
ArrayList
<>();
List
<
T
>
spans
=
new
ArrayList
<>();
for
(
T
span
:
actual
.
getSpans
(
startIndex
,
endIndex
,
spanClazz
))
{
for
(
T
span
:
actual
.
getSpans
(
startIndex
,
endIndex
,
spanClazz
))
{
if
(
actual
.
getSpanStart
(
span
)
==
startIndex
&&
actual
.
getSpanEnd
(
span
)
==
endIndex
)
{
if
(
actual
.
getSpanStart
(
span
)
==
startIndex
&&
actual
.
getSpanEnd
(
span
)
==
endIndex
)
{
spans
.
add
(
span
);
spans
.
add
(
span
);
}
}
}
}
return
spans
;
return
Collections
.
unmodifiableList
(
spans
)
;
}
}
@RequiresNonNull
(
"actual"
)
private
void
failWithExpectedSpan
(
private
void
failWithExpectedSpan
(
int
start
,
int
end
,
Class
<?>
spanType
,
String
spannedSubstring
)
{
int
start
,
int
end
,
Class
<?>
spanType
,
String
spannedSubstring
)
{
failWithoutActual
(
failWithoutActual
(
...
@@ -887,7 +901,7 @@ public final class SpannedSubject extends Subject {
...
@@ -887,7 +901,7 @@ public final class SpannedSubject extends Subject {
@Override
@Override
public
AndSpanFlags
withFamily
(
String
fontFamily
)
{
public
AndSpanFlags
withFamily
(
String
fontFamily
)
{
List
<
Integer
>
matchingSpanFlags
=
new
ArrayList
<>();
List
<
Integer
>
matchingSpanFlags
=
new
ArrayList
<>();
List
<
String
>
spanFontFamilies
=
new
ArrayList
<>();
List
<
@NullableType
String
>
spanFontFamilies
=
new
ArrayList
<>();
for
(
TypefaceSpan
span
:
actualSpans
)
{
for
(
TypefaceSpan
span
:
actualSpans
)
{
spanFontFamilies
.
add
(
span
.
getFamily
());
spanFontFamilies
.
add
(
span
.
getFamily
());
...
@@ -1059,7 +1073,7 @@ public final class SpannedSubject extends Subject {
...
@@ -1059,7 +1073,7 @@ public final class SpannedSubject extends Subject {
}
}
@Override
@Override
public
boolean
equals
(
Object
o
)
{
public
boolean
equals
(
@Nullable
Object
o
)
{
if
(
this
==
o
)
{
if
(
this
==
o
)
{
return
true
;
return
true
;
}
}
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/truth/package-info.java
0 → 100644
View file @
3feb263c
/*
* Copyright (C) 2019 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.
*/
@NonNullApi
package
com
.
google
.
android
.
exoplayer2
.
testutil
.
truth
;
import
com.google.android.exoplayer2.util.NonNullApi
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment