// Path: testingutils/src/main/java/com/google/android/things/contrib/driver/testutils/BitsMatcher.java
// public static BitsMatcher<Byte> hasBitsNotSet(byte mask) {
//     return new BitsMatcher<>(mask, true);
// }
// 
// Path: testingutils/src/main/java/com/google/android/things/contrib/driver/testutils/BitsMatcher.java
// public static BitsMatcher<Byte> hasBitsSet(byte mask) {
//     return new BitsMatcher<>(mask, false);
// }
// 
// Path: cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java
// @VisibleForTesting
// /*package*/ class AlertCallback implements GpioCallback {
//     @Override
//     public boolean onGpioEdge(Gpio gpio) {
//         handleInterrupt();
//         return true;
//     }
// 
//     @Override
//     public void onGpioError(Gpio gpio, int error) {
//         Log.w(TAG, "Error handling GPIO interrupt: " + error);
//     }
// };
// 
// Path: cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java
// public enum Configuration {
//     // Channel Count, Max Touch Inputs, LED Count
//     CAP1203(3,3,0),
//     CAP1293(3,3,0),
//     CAP1206(6,4,0),
//     CAP1296(6,4,0),
//     CAP1208(8,4,0),
//     CAP1298(8,4,0),
//     CAP1105(5,3,0),
//     CAP1106(6,4,0),
//     CAP1126(6,4,2),
//     CAP1128(8,4,2),
//     CAP1133(3,3,3),
//     CAP1166(6,4,6),
//     CAP1188(8,4,8);
// 
//     final int channelCount;
//     final int maxTouch;
//     final int ledCount;
//     Configuration(int channelCount, int maxTouch, int ledCount) {
//         this.channelCount = channelCount;
//         this.maxTouch = maxTouch;
//         this.ledCount = ledCount;
//     }
// }
// 
// Path: cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java
// public interface OnCapTouchListener {
//     /**
//      * Called when a touch event occurs on any of the
//      * controller's input channels.
//      *
//      * @param controller the touch controller triggering the event
//      * @param inputStatus array of input states. An input will report
//      *                    true when touched, false otherwise
//      */
//     void onCapTouchEvent(Cap1xxx controller, boolean[] inputStatus);
// }


import static com.google.android.things.contrib.driver.testutils.BitsMatcher.hasBitsNotSet;
import static com.google.android.things.contrib.driver.testutils.BitsMatcher.hasBitsSet;
import static junit.framework.Assert.assertEquals;
import static org.mockito.AdditionalMatchers.aryEq;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyByte;
import static org.mockito.Matchers.byteThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.os.Handler;
import com.google.android.things.contrib.driver.cap1xxx.Cap1xxx.AlertCallback;
import com.google.android.things.contrib.driver.cap1xxx.Cap1xxx.Configuration;
import com.google.android.things.contrib.driver.cap1xxx.Cap1xxx.OnCapTouchListener;
import com.google.android.things.pio.Gpio;
import com.google.android.things.pio.GpioCallback;
import com.google.android.things.pio.I2cDevice;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.io.IOException;
    }

    @Test
    public void setLedBrightness_throwsIfTooLarge() throws IOException {
        mExpectedException.expect(IllegalArgumentException.class);
        mDriver.setLedBrightness(1.1f);
    }

    @Test
    public void setOnCapTouchListener() throws IOException {
        // Setup expected values
        final boolean[] expectedStatus = new boolean[CONFIGURATION.channelCount];
        int activeChannels = 0;
        // alternating true/false values
        for (int i = 0; i < expectedStatus.length; i += 2) {
            expectedStatus[i] = true;
            activeChannels |= (1 << i);
        }
        // Stub I2cDevice
        Mockito.when(mI2c.readRegByte(0x03)).thenReturn((byte) activeChannels);
        Mockito.when(mI2c.readRegByte(0x00)).thenReturn((byte) 0b00000001); // interrupt
        // Make input deltas exceed threshold readings
        Mockito.doAnswer(new ArrayFillingAnswer((byte) 10)) // input deltas
                .when(mI2c)
                .readRegBuffer(eq(0x10), any(byte[].class), eq(CONFIGURATION.channelCount));
        Mockito.doAnswer(new ArrayFillingAnswer((byte) 5)) // input thresholds
                .when(mI2c)
                .readRegBuffer(eq(0x30), any(byte[].class), eq(CONFIGURATION.channelCount));

        // Add a listener
// Path: testingutils/src/main/java/com/google/android/things/contrib/driver/testutils/BitsMatcher.java
// public static BitsMatcher<Byte> hasBitsNotSet(byte mask) {
//     return new BitsMatcher<>(mask, true);
// }
// 
// Path: testingutils/src/main/java/com/google/android/things/contrib/driver/testutils/BitsMatcher.java
// public static BitsMatcher<Byte> hasBitsSet(byte mask) {
//     return new BitsMatcher<>(mask, false);
// }
// 
// Path: cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java
// @VisibleForTesting
// /*package*/ class AlertCallback implements GpioCallback {
//     @Override
//     public boolean onGpioEdge(Gpio gpio) {
//         handleInterrupt();
//         return true;
//     }
// 
//     @Override
//     public void onGpioError(Gpio gpio, int error) {
//         Log.w(TAG, "Error handling GPIO interrupt: " + error);
//     }
// };
// 
// Path: cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java
// public enum Configuration {
//     // Channel Count, Max Touch Inputs, LED Count
//     CAP1203(3,3,0),
//     CAP1293(3,3,0),
//     CAP1206(6,4,0),
//     CAP1296(6,4,0),
//     CAP1208(8,4,0),
//     CAP1298(8,4,0),
//     CAP1105(5,3,0),
//     CAP1106(6,4,0),
//     CAP1126(6,4,2),
//     CAP1128(8,4,2),
//     CAP1133(3,3,3),
//     CAP1166(6,4,6),
//     CAP1188(8,4,8);
// 
//     final int channelCount;
//     final int maxTouch;
//     final int ledCount;
//     Configuration(int channelCount, int maxTouch, int ledCount) {
//         this.channelCount = channelCount;
//         this.maxTouch = maxTouch;
//         this.ledCount = ledCount;
//     }
// }
// 
// Path: cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java
// public interface OnCapTouchListener {
//     /**
//      * Called when a touch event occurs on any of the
//      * controller's input channels.
//      *
//      * @param controller the touch controller triggering the event
//      * @param inputStatus array of input states. An input will report
//      *                    true when touched, false otherwise
//      */
//     void onCapTouchEvent(Cap1xxx controller, boolean[] inputStatus);
// }


// Path: cap1xxx/src/test/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxxTest.java
import static com.google.android.things.contrib.driver.testutils.BitsMatcher.hasBitsNotSet;
import static com.google.android.things.contrib.driver.testutils.BitsMatcher.hasBitsSet;
import static junit.framework.Assert.assertEquals;
import static org.mockito.AdditionalMatchers.aryEq;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyByte;
import static org.mockito.Matchers.byteThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.os.Handler;
import com.google.android.things.contrib.driver.cap1xxx.Cap1xxx.AlertCallback;
import com.google.android.things.contrib.driver.cap1xxx.Cap1xxx.Configuration;
import com.google.android.things.contrib.driver.cap1xxx.Cap1xxx.OnCapTouchListener;
import com.google.android.things.pio.Gpio;
import com.google.android.things.pio.GpioCallback;
import com.google.android.things.pio.I2cDevice;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.io.IOException;

    }

    @Test
    public void setLedBrightness_throwsIfTooLarge() throws IOException {
        mExpectedException.expect(IllegalArgumentException.class);
        mDriver.setLedBrightness(1.1f);
    }

    @Test
    public void setOnCapTouchListener() throws IOException {
        // Setup expected values
        final boolean[] expectedStatus = new boolean[CONFIGURATION.channelCount];
        int activeChannels = 0;
        // alternating true/false values
        for (int i = 0; i < expectedStatus.length; i += 2) {
            expectedStatus[i] = true;
            activeChannels |= (1 << i);
        }
        // Stub I2cDevice
        Mockito.when(mI2c.readRegByte(0x03)).thenReturn((byte) activeChannels);
        Mockito.when(mI2c.readRegByte(0x00)).thenReturn((byte) 0b00000001); // interrupt
        // Make input deltas exceed threshold readings
        Mockito.doAnswer(new ArrayFillingAnswer((byte) 10)) // input deltas
                .when(mI2c)
                .readRegBuffer(eq(0x10), any(byte[].class), eq(CONFIGURATION.channelCount));
        Mockito.doAnswer(new ArrayFillingAnswer((byte) 5)) // input thresholds
                .when(mI2c)
                .readRegBuffer(eq(0x30), any(byte[].class), eq(CONFIGURATION.channelCount));

        // Add a listener
        OnCapTouchListener mockListener = Mockito.mock(OnCapTouchListener.class);