<commit_before>/*******************************************************************************
 * Copyright (c) 2012 O<NAME> National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.csstudio.perspectives;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;

import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.ui.MSnippetContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.emf.common.util.URI;
import org.eclipse.osgi.service.datalocation.Location;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.osgi.service.event.Event;

@RunWith(MockitoJUnitRunner.class)
public class PerspectiveSaverUnitTest
{
    @Mock
    private Location instanceLocation;

    @Mock
    private IEclipsePreferences preferences;

    @Mock
    private IEventBroker mockBroker;

    @Mock
    private EModelService mockModelService;

    @Mock
    private PerspectiveUtils perspectiveUtils;

    @InjectMocks
    private PerspectiveSaver saver;

    private String workspaceLocation = "/dummy";

    @Before
    public void setUp() {
        try {
            URL workspaceUrl = new URL("file:" + workspaceLocation);
            when(instanceLocation.getDataArea(any(String.class))).thenReturn(workspaceUrl);
            doNothing().when(preferences).put(any(String.class), any(String.class));
            // Return first argument if cloneElement() is called on mockModelService.
            when(mockModelService.cloneElement(any(MUIElement.class), any(MSnippetContainer.class))).thenAnswer(new Answer<MUIElement>() {
                @Override
                public MUIElement answer(InvocationOnMock invocation) {
                    Object[] args = invocation.getArguments();
                    return (MUIElement) args[0];
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test<commit_msg>Fix unit tests by providing genuine FileUtils object.<commit_after>/*******************************************************************************
 * Copyright (c) 2012 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.csstudio.perspectives;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;

import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.ui.MSnippetContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.emf.common.util.URI;
import org.eclipse.osgi.service.datalocation.Location;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.osgi.service.event.Event;

@RunWith(MockitoJUnitRunner.class)
public class PerspectiveSaverUnitTest
{
    @Mock
    private Location instanceLocation;

    @Mock
    private IEclipsePreferences preferences;

    @Mock
    private IEventBroker mockBroker;

    @Mock
    private EModelService mockModelService;

    @Mock
    private PerspectiveUtils perspectiveUtils;

    @Spy
    private IFileUtils fileUtils = new FileUtils();

    @InjectMocks
    private PerspectiveSaver saver;

    private String workspaceLocation = "/dummy";

    @Before
    public void setUp() {
        try {
            URL workspaceUrl = new URL("file:" + workspaceLocation);
            when(instanceLocation.getDataArea(any(String.class))).thenReturn(workspaceUrl);
            doNothing().when(preferences).put(any(String.class), any(String.class));
            // Return first argument if cloneElement() is called on mockModelService.
            when(mockModelService.cloneElement(any(MUIElement.class), any(MSnippetContainer.class))).thenAnswer(new Answer<MUIElement>() {
                @Override
                public MUIElement answer(InvocationOnMock invocation) {
                    Object[] args = invocation.getArguments();
                    return (MUIElement) args[0];
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
{'fraction_non_alphanumeric': 0.14164611590628853, 'fraction_numerical': 0.004932182490752158, 'mean_word_length': 3.968606431852986, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3234552', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1778, 'n_words': 381}