package com.github.jinahya.bit.io;

/*-
 * #%L
 * bit-io
 * %%
 * Copyright (C) 2014 - 2019 Jinahya, Inc.
 * %%
 * 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.
 * #L%
 */

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.invoke.MethodHandles;

import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

@ExtendWith({MockitoExtension.class})
public class AbstractBitInputSpyTest {

    // -----------------------------------------------------------------------------------------------------------------
    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    // -----------------------------------------------------------------------------------------------------------------
    @BeforeEach
    void stubRead() throws IOException {
        when(bitInput.read()).thenReturn(current().nextInt(0, 256));
    }

    // -----------------------------------------------------------------------------------------------------------------

    /**
     * Tests {@link BitInput#readByte(boolean, int)}.
     *
     * @throws IOException if an I/O error occurs.
     */
    @Test
    public void testReadByte() throws IOException {
        final boolean unsigned = current().nextBoolean();
        final int size = current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1));
        final byte value = bitInput.readByte(unsigned, size);
        if (unsigned) {
            assertTrue(value >= 0);
        }
    }

    // -----------------------------------------------------------------------------------------------------------------
    @Spy
    private AbstractBitInput bitInput;
}

@@ -673,16 +673,50 @@
 L%25%0A */%0A%0A
+import lombok.extern.slf4j.Slf4j;%0A
 import o
@@ -777,16 +777,24 @@
 ter.api.
+Repeated
 Test;%0Aim
@@ -921,131 +921,35 @@
 on;%0A
-import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.IOException;%0Aimport java.lang.invoke.MethodHandles
+%0Aimport java.io.IOException
 ;%0A%0Ai
@@ -1009,16 +1009,77 @@
 urrent;%0A
+import static org.junit.jupiter.api.Assertions.assertEquals;%0A
 import s
@@ -1208,16 +1208,23 @@
 class%7D)%0A
+@Slf4j%0A
 public c
@@ -1259,234 +1259,8 @@
  %7B%0A%0A
-    // -----------------------------------------------------------------------------------------------------------------%0A    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());%0A%0A
     
@@ -1691,16 +1691,23 @@
 n, int)%7D
+ method
 .%0A     *
@@ -1771,20 +1771,31 @@
 */%0A    @
+Repeated
 Test
+(8)
 %0A    pub
@@ -2107,32 +2107,521 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Tests %7B@link BitInput#readShort(boolean, int)%7D method.%0A     *%0A     * @throws IOException if an I/O error occurs.%0A     */%0A    @RepeatedTest(8)%0A    public void testReadShort() throws IOException %7B%0A        final boolean unsigned = current().nextBoolean();%0A        final int size = current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1));%0A        final short value = bitInput.readShort(unsigned, size);%0A        if (unsigned) %7B%0A            assertTrue(value %3E= 0);%0A        %7D%0A    %7D%0A%0A
     // ---------

Add a test case