[Thread] check too large error code in unit tests

Per CTS review comment in aosp/2949385:
```
You might want to make this a bit larger, otherwise if some new error codes are added in the future in a mainline update, already released CTS test packages will start to fail.

That should be fixed by mCTS, but since mCTS is not in place yet, it's best to be safe
```

This commit moves the too-large error code check into unit test to avoid
potential CTS compatibility issues.

Bug: 323791003
Change-Id: If99191630e1044cb8f5ed189bf79567cd51c3905
This commit is contained in:
Kangping Dong 2024-02-05 15:49:02 +08:00
commit 54d62cee14
2 changed files with 42 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* Copyright (C) 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.
@ -32,7 +32,7 @@ import androidx.test.filters.SmallTest;
import org.junit.Test;
import org.junit.runner.RunWith;
/** Tests for {@link ThreadNetworkException}. */
/** CTS tests for {@link ThreadNetworkException}. */
@SmallTest
@RunWith(AndroidJUnit4.class)
public final class ThreadNetworkExceptionTest {
@ -57,8 +57,9 @@ public final class ThreadNetworkExceptionTest {
}
@Test
public void constructor_invalidErrorCode_throwsIllegalArgumentException() throws Exception {
public void constructor_tooSmallErrorCode_throwsIllegalArgumentException() throws Exception {
assertThrows(IllegalArgumentException.class, () -> new ThreadNetworkException(0, "0"));
assertThrows(IllegalArgumentException.class, () -> new ThreadNetworkException(13, "13"));
// TODO: add argument check for too large error code when mainline CTS is ready. This was
// not added here for CTS forward copatibility.
}
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (C) 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
*
* 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 android.net.thread;
import static org.junit.Assert.assertThrows;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import org.junit.Test;
import org.junit.runner.RunWith;
/** Unit tests for {@link ThreadNetworkException} to cover what is not covered in CTS tests. */
@SmallTest
@RunWith(AndroidJUnit4.class)
public final class ThreadNetworkExceptionTest {
@Test
public void constructor_tooLargeErrorCode_throwsIllegalArgumentException() throws Exception {
// TODO (b/323791003): move this test case to cts/ThreadNetworkExceptionTest when mainline
// CTS is ready.
assertThrows(IllegalArgumentException.class, () -> new ThreadNetworkException(13, "13"));
}
}