<commit_before>package falgout.jrepl;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Set;

import org.jukito.JukitoRunner;
import org.jukito.UseModules;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.google.inject.Inject;

import falgout.jrepl.guice.TestEnvironment;
import falgout.jrepl.guice.TestModule;
import falgout.jrepl.reflection.Types;

@RunWith(JukitoRunner.class)
@UseModules(TestModule.class)
public class EnvironmentTest {
    @Inject @Rule public TestEnvironment env;
    @Inject public Environment e;
    
    @Test
    public void javaLangIsImportedByDefault() throws IOException {
        Set<Import> imports = e.getImports();
        assertThat(imports, contains(Import.create(false, "java.lang", true)));
    }
    
    @Test
    public void canAddImports() throws IOException {
        Import i = Import.create(false, "java.util", true);
        e.getImports().add(i);
        assertThat(e.getImports(), hasItem(i));
    }

    @Test
    public void cannotHaveDuplicateVariables() {
        Variable<?> var1 = new Variable<>(Types.OBJECT, "foo", new Object());
        Variable<?> var2 = new Variable<>(Types.OBJECT, "foo", new Object());

        assertTrue(e.addVariable(var1));
        assertFalse(e.addVariable(var2));

        assertSame(var1.get(), e.getVariable("foo").get());
    }
}<commit_msg>Environment.getImportClassLoader() is the Thread's context ClassLoader<commit_after>package falgout.jrepl;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Set;

import org.jukito.JukitoRunner;
import org.jukito.UseModules;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.google.inject.Inject;

import falgout.jrepl.guice.TestEnvironment;
import falgout.jrepl.guice.TestModule;
import falgout.jrepl.reflection.Types;

@RunWith(JukitoRunner.class)
@UseModules(TestModule.class)
public class EnvironmentTest {
    @Inject @Rule public TestEnvironment env;
    @Inject public Environment e;

    @Test
    public void javaLangIsImportedByDefault() throws IOException {
        Set<Import> imports = e.getImports();
        assertThat(imports, contains(Import.create(false, "java.lang", true)));
    }

    @Test
    public void canAddImports() throws IOException {
        Import i = Import.create(false, "java.util", true);
        e.getImports().add(i);
        assertThat(e.getImports(), hasItem(i));
    }
    
    @Test
    public void cannotHaveDuplicateVariables() {
        Variable<?> var1 = new Variable<>(Types.OBJECT, "foo", new Object());
        Variable<?> var2 = new Variable<>(Types.OBJECT, "foo", new Object());
        
        assertTrue(e.addVariable(var1));
        assertFalse(e.addVariable(var2));
        
        assertSame(var1.get(), e.getVariable("foo").get());
    }

    @Test
    public void EnvironmentClassLoaderIsThreadContextClassLoader() {
        assertSame(e.getImportClassLoader(), Thread.currentThread().getContextClassLoader());
    }
}
{'fraction_non_alphanumeric': 0.1219025918541726, 'fraction_numerical': 0.0028481913984619764, 'mean_word_length': 4.053237410071943, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4662676', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1083, 'n_words': 221}