<commit_before>package com.github.kl.webintegration.app.test;

import junit.framework.TestCase;

public class HttpServerHandlerTest extends TestCase {

}<commit_msg>Added HttpServerHandler test<commit_after>package com.github.kl.webintegration.app.test;

import android.content.Context;
import android.content.Intent;

import com.github.kl.webintegration.app.ForApplication;
import com.github.kl.webintegration.app.handlers.HttpServerHandler;

import junit.framework.TestCase;

import org.json.JSONObject;
import org.mockito.ArgumentCaptor;

import javax.inject.Inject;
import javax.inject.Singleton;

import dagger.Module;
import dagger.ObjectGraph;
import dagger.Provides;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class HttpServerHandlerTest extends TestCase {

    // SUT
    @Inject HttpServerHandler httpServerHandler;

    // These objects are injected with @Singleton. Therefore they are they same objects that
    // are injected in to the class under test, and they can be checked in the test methods.
    @Inject @ForApplication
    Context context;

    @Module(
            injects = HttpServerHandlerTest.class
    )
    static class TestModule {

        @Provides @Singleton @ForApplication
        Context provideApplicationContext() {
            return mock(Context.class);
        }
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        TestHelper.setDexCache();

        ObjectGraph.create(new TestModule()).inject(this);
    }

    public void testStartsServerServiceWhenOnResult() {
        httpServerHandler.handleResult(mock(JSONObject.class));

        ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
        verify(context).startService(intent.capture());
        assertEquals(HttpServerHandler.ServerService.class.getName(),
                     intent.getValue().getComponent().getClassName());
    }

}






{'fraction_non_alphanumeric': 0.08918503331624808, 'fraction_numerical': 0.0, 'mean_word_length': 3.658711217183771, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '6083066', 'n_tokens_mistral': 536, 'n_tokens_neox': 527, 'n_words': 119}