Fix issues reported by checkstyle
Test: builds Change-Id: I41979cc8096a682c6844df0825ee56ab00a828b5
This commit is contained in:
@@ -20,7 +20,6 @@ import android.os.ConditionVariable
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import java.util.concurrent.Executor
|
||||
import kotlin.system.measureTimeMillis
|
||||
import kotlin.test.fail
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,6 +34,11 @@ import java.util.function.Predicate;
|
||||
import kotlin.Lazy;
|
||||
import kotlin.LazyKt;
|
||||
|
||||
/**
|
||||
* A packet reader that runs on a TAP interface.
|
||||
*
|
||||
* It also implements facilities to reply to received packets.
|
||||
*/
|
||||
public class TapPacketReader extends PacketReader {
|
||||
private final FileDescriptor mTapFd;
|
||||
private final ArrayTrackRecord<byte[]> mReceivedPackets = new ArrayTrackRecord<>();
|
||||
@@ -82,6 +87,14 @@ public class TapPacketReader extends PacketReader {
|
||||
return mReceivedPackets;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a response on the TAP interface.
|
||||
*
|
||||
* The passed ByteBuffer is flipped after use.
|
||||
*
|
||||
* @param packet The packet to send.
|
||||
* @throws IOException if the interface can't be written to.
|
||||
*/
|
||||
public void sendResponse(final ByteBuffer packet) throws IOException {
|
||||
try (FileOutputStream out = new FileOutputStream(mTapFd)) {
|
||||
byte[] packetBytes = new byte[packet.limit()];
|
||||
|
||||
@@ -18,6 +18,9 @@ package com.android.testutils;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* A class grouping some utilities to deal with exceptions.
|
||||
*/
|
||||
public class ExceptionUtils {
|
||||
/**
|
||||
* Like a Consumer, but declared to throw an exception.
|
||||
@@ -25,6 +28,7 @@ public class ExceptionUtils {
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ThrowingConsumer<T> {
|
||||
/** @see java.util.function.Consumer */
|
||||
void accept(T t) throws Exception;
|
||||
}
|
||||
|
||||
@@ -34,6 +38,7 @@ public class ExceptionUtils {
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ThrowingSupplier<T> {
|
||||
/** @see java.util.function.Supplier */
|
||||
T get() throws Exception;
|
||||
}
|
||||
|
||||
@@ -42,10 +47,15 @@ public class ExceptionUtils {
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ThrowingRunnable {
|
||||
/** @see java.lang.Runnable */
|
||||
void run() throws Exception;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a supplier that throws into one that doesn't.
|
||||
*
|
||||
* The returned supplier returns null in cases where the source throws.
|
||||
*/
|
||||
public static <T> Supplier<T> ignoreExceptions(ThrowingSupplier<T> func) {
|
||||
return () -> {
|
||||
try {
|
||||
@@ -56,6 +66,11 @@ public class ExceptionUtils {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a runnable that throws into one that doesn't.
|
||||
*
|
||||
* All exceptions are ignored by the returned Runnable.
|
||||
*/
|
||||
public static Runnable ignoreExceptions(ThrowingRunnable r) {
|
||||
return () -> {
|
||||
try {
|
||||
|
||||
@@ -34,7 +34,7 @@ fun <T> assertLength(expected: Int, got: Array<T>) = got.size.let { len ->
|
||||
assertEquals(expected, len, "Expected array of length $expected, but was $len for $got")
|
||||
}
|
||||
|
||||
// Bridge method to help write this in Java. If you're writing Kotlin, consider using native
|
||||
// Bridge method to help write this in Java. If you're writing Kotlin, consider using
|
||||
// kotlin.test.assertFailsWith instead, as that method is reified and inlined.
|
||||
fun <T : Exception> assertThrows(expected: Class<T>, block: ThrowingRunnable): T {
|
||||
return assertFailsWith(expected.kotlin) { block.run() }
|
||||
|
||||
Reference in New Issue
Block a user