<commit_before>package com.openxc.sources;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Matchers;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import com.openxc.TestUtils;
import com.openxc.messages.SerializationException;
import com.openxc.messages.SimpleVehicleMessage;
import com.openxc.messages.VehicleMessage;
import com.openxc.messages.streamers.BinaryStreamer;
import com.openxc.messages.streamers.JsonStreamer;

@Config(emulateSdk = 18, manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class BytestreamDataSourceTest {
    TestBytestreamSource source;
    SourceCallback callback = mock(SourceCallback.class);

    @Before
    public void setup() {
        source = new TestBytestreamSource(callback);
    }

    @After
    public void teardown() {
        source.stop();
    }

    @Test
    public void startedIsRunning() {
        source.start();
        assertTrue(source.isRunning());
    }

    @Test
    public void initializedNotRunning() {
        assertFalse(source.isRunning());
    }

    @Test
    public void stoppedNotRunning() {
        source.start();
        source.stop();
        assertFalse(source.isRunning());
    }

    @Test
    public void errorOnReadDisconnects() {
        source.start();
        source.connect();
        source.nextReadIsError = true;
        source.inject(new byte[] {1,2,3,4});
        TestUtils.pause(20);
        assertTrue(source.isRunning());
        assertFalse(source.isConnected());
    }

    @Test
    public void exceptionOnReadDisconnects() {
        source.start();
        source.connect();
        source.nextReadThrowsException = true;
        source.inject(new byte[] {1,2,3,4});
        TestUtils.pause(20);
        assertTrue(source.isRunning());
        assertFalse(source.isConnected());
    }
<commit_msg>Increase delay in a time-dependent test to make more reliable.<commit_after>package com.openxc.sources;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Matchers;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import com.openxc.TestUtils;
import com.openxc.messages.SerializationException;
import com.openxc.messages.SimpleVehicleMessage;
import com.openxc.messages.VehicleMessage;
import com.openxc.messages.streamers.BinaryStreamer;
import com.openxc.messages.streamers.JsonStreamer;

@Config(emulateSdk = 18, manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class BytestreamDataSourceTest {
    TestBytestreamSource source;
    SourceCallback callback = mock(SourceCallback.class);

    @Before
    public void setup() {
        source = new TestBytestreamSource(callback);
    }

    @After
    public void teardown() {
        source.stop();
    }

    @Test
    public void startedIsRunning() {
        source.start();
        assertTrue(source.isRunning());
    }

    @Test
    public void initializedNotRunning() {
        assertFalse(source.isRunning());
    }

    @Test
    public void stoppedNotRunning() {
        source.start();
        source.stop();
        assertFalse(source.isRunning());
    }

    @Test
    public void errorOnReadDisconnects() {
        source.start();
        source.connect();
        source.nextReadIsError = true;
        source.inject(new byte[] {1,2,3,4});
        TestUtils.pause(20);
        assertTrue(source.isRunning());
        assertFalse(source.isConnected());
    }

    @Test
    public void exceptionOnReadDisconnects() {
        source.start();
        source.connect();
        source.nextReadThrowsException = true;
        source.inject(new byte[] {1,2,3,4});
        TestUtils.pause(50);
        assertTrue(source.isRunning());
        assertFalse(source.isConnected());
    }

{'fraction_non_alphanumeric': 0.11051904479968423, 'fraction_numerical': 0.005525952239984212, 'mean_word_length': 3.6325411334552102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1692035', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1492, 'n_words': 281}