<commit_before>package org.codingmatters.tests.compile;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.File;
import java.io.FileWriter;
import java.util.UUID;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

/**
 * Created by nelt on 9/6/16.
 */
public class ClassMatchersTest {

    @Rule
    public ExpectedException exception = ExpectedException.none();

    private File dir;
    private CompiledCode compiled;

    @Before
    public void setUp() throws Exception {
        this.dir = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
        dir.mkdirs();
        File packageDir = new File(this.dir, "org/codingmatters");
        packageDir.mkdirs();
        File helloWorld = new File(packageDir, "HelloWorld.java");

        try(FileWriter writer = new FileWriter(helloWorld)) {
            writer.write(
                    "package org.codingmatters;\n" +
                    "\n" +
                    "public class HelloWorld {\n" +
                    "    public HelloWorld() {}\n" +
                    "\n" +
                    "    public String sayHello() {return \"Hello, World\";}\n" +
                    "\n" +
                    "    public static void main(String[] args) {\n" +
                    "        System.out.println(new HelloWorld().sayHello());\n" +
                    "    }\n" +
                    "}"
            );
            writer.flush();
        }

        this.compiled = CompiledCode.compile(this.dir);
    }

    @After
    public void tearDown() throws Exception {
        this.delete(this.dir);
    }

    private void delete(File file) {
        if(file.isDirectory()) {
            for (File child : file.listFiles()) {
                this.delete(child);
            }
        }
        file.delete();
    }

    @Test
    public void aClass() throws Exception {
        assertThat(String.class, is(ClassMatchers.isAClass()));
    }

    @Test
    public void classWithName() throws Exception {
        assertThat(String.class, is(ClassMatchers.isAClass().withName("java.lang.String")));
    }

    @Test
    public void classHasNotName() throws Exception {
        exception.expect(AssertionError.class);
        exception.expectMessage(
                "Expected: (classname is \"NotThisName\")\n" +
                "     but: classname is \"NotThisName\" <class java.lang.String> classname was \"java.lang.String\""
        );

        assertThat(String.class, ClassMatchers.isAClass().withName("NotThisName"));
    }


}<commit_msg>small refactoring<commit_after>package org.codingmatters.tests.compile;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.File;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

/**
 * Created by nelt on 9/6/16.
 */
public class ClassMatchersTest {

    @Rule
    public ExpectedException exception = ExpectedException.none();

    private void delete(File file) {
        if(file.isDirectory()) {
            for (File child : file.listFiles()) {
                this.delete(child);
            }
        }
        file.delete();
    }

    @Test
    public void aClass() throws Exception {
        assertThat(String.class, is(ClassMatchers.isAClass()));
    }

    @Test
    public void classWithName() throws Exception {
        assertThat(String.class, ClassMatchers.isAClass().withName("java.lang.String"));
    }

    @Test
    public void classHasNotName() throws Exception {
        exception.expect(AssertionError.class);
        exception.expectMessage(
                "Expected: (classname is \"NotThisName\")\n" +
                "     but: classname is \"NotThisName\" <class java.lang.String> classname was \"java.lang.String\""
        );

        assertThat(String.class, ClassMatchers.isAClass().withName("NotThisName"));
    }


}
{'fraction_non_alphanumeric': 0.12412587412587413, 'fraction_numerical': 0.001998001998001998, 'mean_word_length': 2.1635071090047395, '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': '5633599', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1120, 'n_words': 237}