<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.context.internal;

import java.util.Arrays;
import java.util.List;

import org.xwiki.context.Execution;
import org.xwiki.context.ExecutionContext;
import org.xwiki.context.ExecutionContextException;
import org.xwiki.context.ExecutionContextInitializer;

import junit.framework.TestCase;

/**
 * Unit tests for {@link ExecutionContext}.
 * 
 * @version $Id$
 * @since 1.8RC3
 */
public class DefaultExecutionContextManagerTest extends TestCase
{
    /**
     * Verify we have different objects in the Execution Context after the clone.
     */
    public void testClone() throws Exception
    {
        Execution execution = new DefaultExecution();
        ExecutionContext context = new ExecutionContext();
        execution.setContext(context);
        
        DefaultExecutionContextManager contextManager = new DefaultExecutionContextManager(execution);
        contextManager.addExecutionContextInitializer(new ExecutionContextInitializer() {
            public void initialize(ExecutionContext context) throws ExecutionContextException
            {
                context.setProperty("key", Arrays.asList("value"));
            }
        });
        
        ExecutionContext clonedContext = contextManager.clone(context);
        
        assertSame(context, execution.getContext());
        assertEquals("value", ((List<String>) clonedContext.getProperty("key")).get(0));
        assertNotSame(context.getProperty("key"), clonedContext.getProperty("key"));
    }
}<commit_msg>Add unit test<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.context.internal;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.xwiki.context.Execution;
import org.xwiki.context.ExecutionContext;
import org.xwiki.context.ExecutionContextException;
import org.xwiki.context.ExecutionContextInitializer;

import junit.framework.TestCase;

/**
 * Unit tests for {@link ExecutionContext}.
 * 
 * @version $Id$
 * @since 1.8RC3
 */
public class DefaultExecutionContextManagerTest extends TestCase
{
    /**
     * Verify we have different objects in the Execution Context after the clone.
     */
    public void testClone() throws Exception
    {
        Execution execution = new DefaultExecution();
        ExecutionContext context = new ExecutionContext();
        execution.setContext(context);

        Map xwikicontext = new HashMap();
        context.setProperty("xwikicontext", xwikicontext);
        Map velocitycontext = new HashMap();
        context.setProperty("velocitycontext", velocitycontext);

        DefaultExecutionContextManager contextManager = new DefaultExecutionContextManager(execution);
        contextManager.addExecutionContextInitializer(new ExecutionContextInitializer() {
            public void initialize(ExecutionContext context) throws ExecutionContextException
            {
                context.setProperty("key", Arrays.asList("value"));
            }
        });
        
        ExecutionContext clonedContext = contextManager.clone(context);
        
        assertSame(context, execution.getContext());
        assertEquals("value", ((List<String>) clonedContext.getProperty("key")).get(0));
        assertNotSame(context.getProperty("key"), clonedContext.getProperty("key"));
        assertSame(xwikicontext, clonedContext.getProperty("xwikicontext"));
        assertNotSame(xwikicontext, clonedContext.getProperty("velocitycontext"));
    }
}
{'fraction_non_alphanumeric': 0.08514700267277586, 'fraction_numerical': 0.006491027109583811, 'mean_word_length': 3.702872531418312, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1226119', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1263, 'n_words': 454}