Enable lint in lib-common tests

Also move the `lint.xml` config which disables the `NewApi` check from
`lib-session` to the existing top-level file, and limit it to cover all
Robolectric tests by path matching.

Follow-up to 76db936d68

PiperOrigin-RevId: 692913646
This commit is contained in:
ibaker 2024-11-04 04:14:18 -08:00 committed by Copybara-Service
parent a8ed6494c3
commit af1c13524c
5 changed files with 13 additions and 22 deletions

View File

@ -35,6 +35,11 @@ android {
lint {
baseline = file("lint-baseline.xml")
}
lintOptions {
// TODO: b/353490583 - Move this to common_library_config.gradle once it's enabled for all
// libraries.
checkTestSources true
}
publishing {
singleVariant('release') {
withSourcesJar()

View File

@ -557,6 +557,7 @@ public class MediaItemTest {
}
@Test
@SuppressWarnings("Range") // Deliberately testing invalid values
public void clippingConfigurationBuilder_throwsOnInvalidValues() {
MediaItem.ClippingConfiguration.Builder clippingConfigurationBuilder =
new MediaItem.ClippingConfiguration.Builder();
@ -582,7 +583,7 @@ public class MediaItemTest {
}
@Test
@SuppressWarnings("deprecation") // Testing deprecated setter.
@SuppressWarnings({"deprecation", "Range"}) // Testing deprecated setter with invalid value.
public void builderSetStartPositionMs_negativeValue_throws() {
MediaItem.Builder builder = new MediaItem.Builder();

View File

@ -79,6 +79,7 @@ public final class ColorParserTest {
@Test
public void rgbColorParsingRgbValuesOutOfBounds() {
int outOfBounds = ColorParser.parseTtmlColor("rgb(999, 999, 999)");
@SuppressWarnings("Range") // Deliberately testing invalid values
int color = Color.rgb(999, 999, 999);
// Behave like the framework does.
assertThat(outOfBounds).isEqualTo(color);

View File

@ -17,4 +17,9 @@
<issue id="UnsafeOptInUsageError">
<option name="opt-in" value="androidx.media3.common.util.UnstableApi" />
</issue>
<!-- Robolectric tests run at targetApi by default, but the linter doesn't understand this so
generates lots of spurious NewApi failures. -->
<issue id="NewApi">
<ignore path="*/src/test/**" />
</issue>
</lint>

View File

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2024 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
~
~ https://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.
-->
<lint>
<!-- Robolectric tests run at targetApi by default, but the linter doesn't understand this so
generates lots of spurious NewApi failures. -->
<issue id="NewApi" severity="ignore" />
</lint>