<commit_before>package com.punchthrough.bean.sdk;

import android.bluetooth.BluetoothDevice;
import android.os.Handler;
import android.content.Context;

import com.punchthrough.bean.sdk.internal.ble.GattClient;
import com.punchthrough.bean.sdk.internal.serial.GattSerialTransportProfile.SerialListener;
import com.punchthrough.bean.sdk.internal.serial.GattSerialTransportProfile;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

public class BeanTest {

    GattClient.ConnectionListener testListener;

    // Mocks
    Context mockContext;
    BluetoothDevice mockDevice;
    Handler mockHandler;
    GattClient mockGattClient;
    GattSerialTransportProfile mockGattSerialTransportProfile;

    // Class under test
    Bean bean;

    @Before
    public void setup() {

        // Instantiate mocks
        mockContext = mock(Context.class);
        mockDevice = mock(BluetoothDevice.class);
        mockHandler = mock(Handler.class);
        mockGattClient = mock(GattClient.class);
        mockGattSerialTransportProfile = mock(GattSerialTransportProfile.class);

        // Customize some behavior
        when(mockGattClient.getSerialProfile()).thenReturn(mockGattSerialTransportProfile);

        doAnswer(new Answer() {
            public Object answer(InvocationOnMock invocation) {
                Object[] args = invocation.getArguments();
                testListener = (GattClient.ConnectionListener) args[0];
                return null;
            }
        }).when(mockGattClient).setListener(any(GattClient.ConnectionListener.class));

        // Instantiate class under test
        bean = new Bean(mockDevice, mockGattClient, mockHandler);
    }

    @Test
    public void testBeanConnection() {
        // It should start disconnected
        assertThat(bean.isConnected()).isFalse();

        // Issue connection
        bean.connect(mockContext, mock(BeanListener.class));
        testListener.onConnected();

        // Connected!
        assertThat(bean.isConnected()).isTrue();

    }

}<commit_msg>test: fix bean connection unit test<commit_after>package com.punchthrough.bean.sdk;

import android.bluetooth.BluetoothDevice;
import android.os.Handler;
import android.content.Context;

import com.punchthrough.bean.sdk.internal.ble.GattClient;
import com.punchthrough.bean.sdk.internal.serial.GattSerialTransportProfile.SerialListener;
import com.punchthrough.bean.sdk.internal.serial.GattSerialTransportProfile;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.util.ArrayList;
import java.util.List;

public class BeanTest {

    GattClient.ConnectionListener testListener;
    List<Runnable> handlerRunnables = new ArrayList<>();

    // Mocks
    Context mockContext;
    BluetoothDevice mockDevice;
    Handler mockHandler;
    GattClient mockGattClient;
    GattSerialTransportProfile mockGattSerialTransportProfile;

    // Class under test
    Bean bean;

    @Before
    public void setup() {

        // Instantiate mocks
        mockContext = mock(Context.class);
        mockDevice = mock(BluetoothDevice.class);
        mockHandler = mock(Handler.class);
        mockGattClient = mock(GattClient.class);
        mockGattSerialTransportProfile = mock(GattSerialTransportProfile.class);

        // Customize some behavior
        when(mockGattClient.getSerialProfile()).thenReturn(mockGattSerialTransportProfile);

        doAnswer(new Answer() {
            public Object answer(InvocationOnMock invocation) {
                Object[] args = invocation.getArguments();
                testListener = (GattClient.ConnectionListener) args[0];
                return null;
            }
        }).when(mockGattClient).setListener(any(GattClient.ConnectionListener.class));

        doAnswer(new Answer() {
            public Object answer(InvocationOnMock invocation) {
                Object[] args = invocation.getArguments();
                handlerRunnables.add((Runnable) args[0]);
                return null;
            }
        }).when(mockHandler).post(any(Runnable.class));

        // Instantiate class under test
        bean = new Bean(mockDevice, mockGattClient, mockHandler);
    }

    @Test
    public void testBeanConnection() {
        BeanListener mockListener = mock(BeanListener.class);
        bean.connect(mockContext, mockListener);
        testListener.onConnected();
        for (Runnable r : handlerRunnables) {
            r.run();
        }
        verify(mockListener).onConnected();
    }

}
{'fraction_non_alphanumeric': 0.09410548086866598, 'fraction_numerical': 0.0006204756980351603, 'mean_word_length': 3.1475128644939967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5625948', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1281, 'n_words': 245}