<commit_before>package com.armandgray.taap.detail;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;

import com.armandgray.taap.BuildConfig;
import com.armandgray.taap.R;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowDialog;
import org.robolectric.shadows.ShadowToast;

import java.util.Calendar;

import static com.armandgray.taap.detail.DetailSummaryDialog.DIALOG;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class DrillDetailControllerTest {

    private ActivityController<DrillDetailActivity> activityController;
    private DrillDetailActivity activity;
    private DrillDetailController controller;

    @Before
    public void setUp() {
        System.out.println("Running Set Up!");
        activityController = Robolectric.buildActivity(DrillDetailActivity.class);
        activity = activityController.create().start().resume().visible().get();
        controller = activity.controller;
    }

    @Test
    public void activityInstanceOfAppCompatActivity_TestConstructor() throws Exception {
        assertEquals("detail.DrillDetailActivity", controller.activity.getLocalClassName());
    }

    @Test
    public void doesShowTimerDialogOnFabClick() throws Exception {
        controller.views.fab.performClick();
        

        Dialog resultDialog = ShadowDialog.getLatestDialog();
        TimerDialog expectedDialog = new TimerDialog();
        expectedDialog.show(activity.getSupportFragmentManager(), DIALOG);
        assertNotNull(resultDialog);
        assertEquals(expectedDialog.getDialog().findViewById(R.id.timerDialogContainer).getId(),
                resultDialog.findViewById(R.id.timerDialogContainer).getId());
    }

    @Test
    public void doesCreateViewsHandler_TestConstructor() throws Exception {
        assertNotNull(controller.views);
        assertNotNull(controller.views.activity);
    }

    @Test
    public void doesTrackActiveWorkTime() throws Exception {
        controller.views.fab.performClick();
        controller.views.fab.performClick();

        assertNotNull(controller.activeWorkTime);
        assertTrue(controller.activeWorkTime > 0);
    }

    @Test
    public void doesTrackRestTime() throws Exception {
        controller.views.fab.performClick();
        controller.views.fab.performClick();
        controller.views.fab.performClick();

        assertNotNull(controller.restTime);
        assertTrue(controller.restTime > 0);
    }

    @Test
    public void doesToastErrorIfSuccessesGreaterThanReps_OnBtnFinishedClick() throws Exception {
        
        controller.views.npSuccesses.setValue(100);
        Dialog resultDialog = ShadowDialog.getLatestDialog();

        controller.views.fab.performClick();
        controller.views.btnFinished.performClick();

        assertNull(resultDialog);
        assertThat(ShadowToast.getTextOfLatestToast(),
                equalTo(activity.getString(R.string.invalid_successes)));

    }

    @Test
    public void doesAddElapsedTimeToActiveWorkIfDrillActive_OnBtnFinishedClick() throws Exception {
        controller.views.fab.performClick();
        Dialog resultDialog = ShadowDialog.getLatestDialog();
        resultDialog.dismiss();
        controller.views.btnFinished.performClick();

        assertNotNull(controller.activeWorkTime);
        assertTrue(controller.activeWorkTime > 0);
    }

    @Test
    public void doesAssignSessionLogFields_OnBtnFinishedClick() throws Exception {
        controller.views.fab.performClick();
        controller.views.fab.performClick();
        controller.views.fab.performClick();
        controller.views.fab.performClick();
        controller.views.fab.performClick();
        controller.views.btnFinished.performClick();

        Calendar calendar = Calendar.getInstance();
        calendar.set(0, 0, 0, 0, 0, 0);
        assertNotNull(controller.sessionLog);
        assertTrue(controller.sessionLog
                .getSessionLength().getTime() > calendar.getTime().getTime());
    }

    @SuppressLint("InflateParams")
    @Test
    public void doesTogglePlayButtonOnTimerDialogDismiss() {
        controller.views.fab.performClick();

        Dialog resultDialog = ShadowDialog.getLatestDialog();
        View layout = LayoutInflater.from(activity)
                .inflate(R.layout.timer_dialog_layout, null, false);
        resultDialog.dismiss();
<commit_msg>added line <        ShadowDialog.getLatestDialog().dismiss(); > to resolve dialog state exception errors<commit_after>package com.armandgray.taap.detail;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;

import com.armandgray.taap.BuildConfig;
import com.armandgray.taap.R;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowDialog;
import org.robolectric.shadows.ShadowToast;

import java.util.Calendar;

import static com.armandgray.taap.detail.DetailSummaryDialog.DIALOG;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class DrillDetailControllerTest {

    private ActivityController<DrillDetailActivity> activityController;
    private DrillDetailActivity activity;
    private DrillDetailController controller;

    @Before
    public void setUp() {
        System.out.println("Running Set Up!");
        activityController = Robolectric.buildActivity(DrillDetailActivity.class);
        activity = activityController.create().start().resume().visible().get();
        controller = activity.controller;
    }

    @Test
    public void activityInstanceOfAppCompatActivity_TestConstructor() throws Exception {
        assertEquals("detail.DrillDetailActivity", controller.activity.getLocalClassName());
    }

    @Test
    public void doesShowTimerDialogOnFabClick() throws Exception {
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();

        Dialog resultDialog = ShadowDialog.getLatestDialog();
        TimerDialog expectedDialog = new TimerDialog();
        expectedDialog.show(activity.getSupportFragmentManager(), DIALOG);
        assertNotNull(resultDialog);
        assertEquals(expectedDialog.getDialog().findViewById(R.id.timerDialogContainer).getId(),
                resultDialog.findViewById(R.id.timerDialogContainer).getId());
    }

    @Test
    public void doesCreateViewsHandler_TestConstructor() throws Exception {
        assertNotNull(controller.views);
        assertNotNull(controller.views.activity);
    }

    @Test
    public void doesTrackActiveWorkTime() throws Exception {
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();

        assertNotNull(controller.activeWorkTime);
        assertTrue(controller.activeWorkTime > 0);
    }

    @Test
    public void doesTrackRestTime() throws Exception {
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();

        assertNotNull(controller.restTime);
        assertTrue(controller.restTime > 0);
    }

    @Test
    public void doesToastErrorIfSuccessesGreaterThanReps_OnBtnFinishedClick() throws Exception {
        controller.views.npSuccesses.setValue(100);
        Dialog resultDialog = ShadowDialog.getLatestDialog();

        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.btnFinished.performClick();

        assertNull(resultDialog);
        assertThat(ShadowToast.getTextOfLatestToast(),
                equalTo(activity.getString(R.string.invalid_successes)));

    }

    @Test
    public void doesAddElapsedTimeToActiveWorkIfDrillActive_OnBtnFinishedClick() throws Exception {
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.btnFinished.performClick();

        assertNotNull(controller.activeWorkTime);
        assertTrue(controller.activeWorkTime > 0);
    }

    @Test
    public void doesAssignSessionLogFields_OnBtnFinishedClick() throws Exception {
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();
        controller.views.btnFinished.performClick();

        Calendar calendar = Calendar.getInstance();
        calendar.set(0, 0, 0, 0, 0, 0);
        assertNotNull(controller.sessionLog);
        assertTrue(controller.sessionLog
                .getSessionLength().getTime() > calendar.getTime().getTime());
    }

    @SuppressLint("InflateParams")
    @Test
    public void doesTogglePlayButtonOnTimerDialogDismiss() {
        controller.views.fab.performClick();
        ShadowDialog.getLatestDialog().dismiss();

        Dialog resultDialog = ShadowDialog.getLatestDialog();
        View layout = LayoutInflater.from(activity)
                .inflate(R.layout.timer_dialog_layout, null, false);
        resultDialog.dismiss();

{'fraction_non_alphanumeric': 0.09916136761588794, 'fraction_numerical': 0.002211777716339508, 'mean_word_length': 3.8209684584629056, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, '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': '1092348', 'n_tokens_mistral': 2884, 'n_tokens_neox': 2781, 'n_words': 452}