<commit_before>package com.TestStack.White.SWTTestApplication;

/**
 * Created by <NAME> on 2/14/14.
 */

import com.TestStack.White.SWTTestApplication.Controller.MainWindowController;
import com.TestStack.White.SWTTestApplication.Model.MainWindowModel;
import com.TestStack.White.SWTTestApplication.View.MainWindowView;
import org.eclipse.swt.events.MouseEvent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

//TODO: separate this class into several specific ones
@RunWith(JUnit4.class)
public class Tests {
    MainWindowModel model = new MainWindowModel();
    MainWindowView view = new MainWindowView();
    MainWindowController controller = new MainWindowController(model, view);
    MouseEvent mouseEventMock = mock(MouseEvent.class);

    @Test
    public void tabCountTest() {
        Field[] fields = view.getClass().getFields();
        int tabCount = 0;
        for (Field f : fields) {
            if (Modifier.isPublic(f.getModifiers()))
                tabCount++;
        }
        assertEquals("Only TabView fields should be public in MainWindowView", 4, tabCount);
    }

    @Test
    public void Test() {

    }

    @Test
    public void textBoxTest() {
        assertEquals(model.getComboboxItems().length, 3);
        assertEquals(model.getTextBoxTest(), view.inputControlsTab.getTextBox().getText());
        view.inputControlsTab.getTextBox().setText("123123asd");
        assertEquals("123123asd", view.inputControlsTab.getTextBox().getText());
        assertEquals("123123asd", model.getTextBoxTest());
    }

    @Test
    public void comboTest() {
        view.listControlsTab.getCombo().select(1);
        assertEquals(1, view.listControlsTab.getCombo().getSelectionIndex());
    }

    @Test
    public void changeItemsTest() {
        assertEquals(model.getListItems(), view.listControlsTab.getList().getItems());
        when(mouseEventMock.getSource()).thenReturn(view.listControlsTab.getChangeItemButtons());
        controller.changeItemButtonMouseListener.mouseDown(mouseEventMock);
        assertEquals(model.getChangedListItems(), view.listControlsTab.getList().getItems());
    }

    @Test
    public void buttonInToolBarTest() {
        assertEquals("Button in toolbar", view.getToolBarItem().getText());
        when(mouseEventMock.getSource()).thenReturn(view.getToolBar());
        view.getToolBarItem().setSelection(true);
        controller.toolBarMouseListener.mouseUp(mouseEventMock);
        assertEquals("Selected", view.getToolBarItem().getText());
        view.getToolBarItem().setSelection(false);
        controller.toolBarMouseListener.mouseUp(mouseEventMock);
        assertEquals("Unselected", view.getToolBarItem().getText());
    }
}
<commit_msg>added test for field modifiers<commit_after>package com.TestStack.White.SWTTestApplication;

/**
 * Created by <NAME> on 2/14/14.
 */

import com.TestStack.White.SWTTestApplication.Controller.MainWindowController;
import com.TestStack.White.SWTTestApplication.Model.MainWindowModel;
import com.TestStack.White.SWTTestApplication.View.MainWindowView;
import org.eclipse.swt.events.MouseEvent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

//TODO: separate this class into several specific ones
@RunWith(JUnit4.class)
public class Tests {
    MainWindowModel model = new MainWindowModel();
    MainWindowView view = new MainWindowView();
    MainWindowController controller = new MainWindowController(model, view);
    MouseEvent mouseEventMock = mock(MouseEvent.class);

    @Test
    public void tabCountTest() {
        Field[] fields = view.getClass().getFields();
        int tabCount = 0;
        for (Field f : fields) {
            if (Modifier.isPublic(f.getModifiers()))
                tabCount++;
        }
        assertEquals("Only TabView fields should be public in MainWindowView", 4, tabCount);
    }

    @Test
    public void allFieldsInTabViewsShouldBePrivateTest() {
        Field[] fields = view.getClass().getFields();
        for (Field f : fields) {
            System.out.println(f.getType().getName());
            Field[] fields1 = f.getType().getDeclaredFields();
            for (Field f1 : fields1) {
                System.out.println(f1.getName());
                assertEquals(f1.getName() + " in class " + f.getClass().toString() + " is not private",
                        Modifier.isPrivate(f1.getModifiers()), true);
            }
        }
    }

    @Test
    public void textBoxTest() {
        assertEquals(model.getComboboxItems().length, 3);
        assertEquals(model.getTextBoxTest(), view.inputControlsTab.getTextBox().getText());
        view.inputControlsTab.getTextBox().setText("123123asd");
        assertEquals("123123asd", view.inputControlsTab.getTextBox().getText());
        assertEquals("123123asd", model.getTextBoxTest());
    }

    @Test
    public void comboTest() {
        view.listControlsTab.getCombo().select(1);
        assertEquals(1, view.listControlsTab.getCombo().getSelectionIndex());
    }

    @Test
    public void changeItemsTest() {
        assertEquals(model.getListItems(), view.listControlsTab.getList().getItems());
        when(mouseEventMock.getSource()).thenReturn(view.listControlsTab.getChangeItemButtons());
        controller.changeItemButtonMouseListener.mouseDown(mouseEventMock);
        assertEquals(model.getChangedListItems(), view.listControlsTab.getList().getItems());
    }

    @Test
    public void buttonInToolBarTest() {
        assertEquals("Button in toolbar", view.getToolBarItem().getText());
        when(mouseEventMock.getSource()).thenReturn(view.getToolBar());
        view.getToolBarItem().setSelection(true);
        controller.toolBarMouseListener.mouseUp(mouseEventMock);
        assertEquals("Selected", view.getToolBarItem().getText());
        view.getToolBarItem().setSelection(false);
        controller.toolBarMouseListener.mouseUp(mouseEventMock);
        assertEquals("Unselected", view.getToolBarItem().getText());
    }
}

{'fraction_non_alphanumeric': 0.1223155929038282, 'fraction_numerical': 0.01027077497665733, 'mean_word_length': 3.6606236403190717, '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': '7486917', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1759, 'n_words': 309}