// 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: vcnl4200/src/main/java/com/google/android/things/contrib/driver/vcnl4200/Vcnl4200.java
// public static class InterruptStatus {
//     public final boolean FLAG_PS_UPFLAG;
//     public final boolean FLAG_PS_SPFLAG;
//     public final boolean FLAG_ALS_IF_L;
//     public final boolean FLAG_ALS_IF_H;
//     public final boolean FLAG_PS_IF_CLOSE;
//     public final boolean FLAG_PS_IF_AWAY;
// 
//     private InterruptStatus(short status) {
//         status = (short)((status >> 8) & 0xFF);
//         FLAG_PS_IF_AWAY = isBitSet(status, 0);
//         FLAG_PS_IF_CLOSE = isBitSet(status, 1);
//         FLAG_ALS_IF_H = isBitSet(status, 4);
//         FLAG_ALS_IF_L = isBitSet(status, 5);
//         FLAG_PS_SPFLAG = isBitSet(status, 6);
//         FLAG_PS_UPFLAG = isBitSet(status, 7);
//     }
// 
//     private boolean isBitSet(short word, int bitIndex) {
//         return ((word >> bitIndex) & 1) != 0;
//     }
// 
//     static InterruptStatus fromStatus(short status) {
//         return new InterruptStatus(status);
//     }
// }


import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static com.google.android.things.contrib.driver.testutils.BitsMatcher.hasBitsSet;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.shortThat;
import static org.mockito.Mockito.times;
import com.google.android.things.contrib.driver.vcnl4200.Vcnl4200.InterruptStatus;
import com.google.android.things.pio.I2cDevice;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

    @Test
    public void validateInterruptStatus() throws IOException {
        /**
         * Interrupt Status Register, High Byte (details from documentation):
         * 7 | PS_UPFLAG PS code saturation flag
         * 6 | PS_SPFLAG PS enter sunlight protection flag
         * 5 | ALS_IF_L, ALS crossing low THD INT trigger event
         * 4 | ALS_IF_H, ALS crossing high THD INT trigger event
         * 3 | Default = 0, reserved
         * 2 | Default = 0, reserved
         * 1 | PS_IF_CLOSE, PS rise above PS_THDH INT trigger event
         * 0 | PS_IF_AWAY, PS drop below PS_THDL INT trigger event
         */
        InterruptStatus interruptStatus = InterruptStatus.fromStatus((short) (0b10100010 << 8));
        assertTrue(interruptStatus.FLAG_PS_UPFLAG);
        assertFalse(interruptStatus.FLAG_PS_SPFLAG);
        assertTrue(interruptStatus.FLAG_ALS_IF_L);
        assertFalse(interruptStatus.FLAG_ALS_IF_H);
        assertTrue(interruptStatus.FLAG_PS_IF_CLOSE);
        assertFalse(interruptStatus.FLAG_PS_IF_AWAY);
    }

    @Test
    public void setAlsIntegrationTime() throws IOException {
        Vcnl4200 vcnl4200 = new Vcnl4200(mI2c);
        Mockito.reset(mI2c);

        vcnl4200.setAlsIntegrationTime(Vcnl4200.ALS_IT_TIME_50MS);
        Mockito.verify(mI2c).writeRegWord(eq(Vcnl4200.REGISTER_ALS_CONF),
// 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: vcnl4200/src/main/java/com/google/android/things/contrib/driver/vcnl4200/Vcnl4200.java
// public static class InterruptStatus {
//     public final boolean FLAG_PS_UPFLAG;
//     public final boolean FLAG_PS_SPFLAG;
//     public final boolean FLAG_ALS_IF_L;
//     public final boolean FLAG_ALS_IF_H;
//     public final boolean FLAG_PS_IF_CLOSE;
//     public final boolean FLAG_PS_IF_AWAY;
// 
//     private InterruptStatus(short status) {
//         status = (short)((status >> 8) & 0xFF);
//         FLAG_PS_IF_AWAY = isBitSet(status, 0);
//         FLAG_PS_IF_CLOSE = isBitSet(status, 1);
//         FLAG_ALS_IF_H = isBitSet(status, 4);
//         FLAG_ALS_IF_L = isBitSet(status, 5);
//         FLAG_PS_SPFLAG = isBitSet(status, 6);
//         FLAG_PS_UPFLAG = isBitSet(status, 7);
//     }
// 
//     private boolean isBitSet(short word, int bitIndex) {
//         return ((word >> bitIndex) & 1) != 0;
//     }
// 
//     static InterruptStatus fromStatus(short status) {
//         return new InterruptStatus(status);
//     }
// }


// Path: vcnl4200/src/test/java/com/google/android/things/contrib/driver/vcnl4200/Vcnl4200Test.java
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static com.google.android.things.contrib.driver.testutils.BitsMatcher.hasBitsSet;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.shortThat;
import static org.mockito.Mockito.times;
import com.google.android.things.contrib.driver.vcnl4200.Vcnl4200.InterruptStatus;
import com.google.android.things.pio.I2cDevice;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;


    @Test
    public void validateInterruptStatus() throws IOException {
        /**
         * Interrupt Status Register, High Byte (details from documentation):
         * 7 | PS_UPFLAG PS code saturation flag
         * 6 | PS_SPFLAG PS enter sunlight protection flag
         * 5 | ALS_IF_L, ALS crossing low THD INT trigger event
         * 4 | ALS_IF_H, ALS crossing high THD INT trigger event
         * 3 | Default = 0, reserved
         * 2 | Default = 0, reserved
         * 1 | PS_IF_CLOSE, PS rise above PS_THDH INT trigger event
         * 0 | PS_IF_AWAY, PS drop below PS_THDL INT trigger event
         */
        InterruptStatus interruptStatus = InterruptStatus.fromStatus((short) (0b10100010 << 8));
        assertTrue(interruptStatus.FLAG_PS_UPFLAG);
        assertFalse(interruptStatus.FLAG_PS_SPFLAG);
        assertTrue(interruptStatus.FLAG_ALS_IF_L);
        assertFalse(interruptStatus.FLAG_ALS_IF_H);
        assertTrue(interruptStatus.FLAG_PS_IF_CLOSE);
        assertFalse(interruptStatus.FLAG_PS_IF_AWAY);
    }

    @Test
    public void setAlsIntegrationTime() throws IOException {
        Vcnl4200 vcnl4200 = new Vcnl4200(mI2c);
        Mockito.reset(mI2c);

        vcnl4200.setAlsIntegrationTime(Vcnl4200.ALS_IT_TIME_50MS);
        Mockito.verify(mI2c).writeRegWord(eq(Vcnl4200.REGISTER_ALS_CONF),
                shortThat(hasBitsSet((short) Vcnl4200.ALS_IT_TIME_50MS)));