package com.googlecode.jslint4java;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import java.io.File;
import java.io.StringReader;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

public class JSLintBuilderTest {

    // This jslint will return true for any file.
    private static final String STUB_JSLINT = "com/googlecode/jslint4java/stubjslint.js";

    private JSLintBuilder builder;

    /**
     * A minimal test that a JSLint looks OK. Just tests we can lint an empty
     * string.
     */
    private void assertJSLintOK(JSLint lint) {
        assertThat(lint, is(notNullValue()));
        // Check it can lint OK.
        List<Issue> issues = lint.lint("-", "").getIssues();
        assertThat(issues.isEmpty(), is(true));
    }

    @Before
    public void setUp() throws Exception {
        builder = new JSLintBuilder();
    }

    @Test
    public void testFromClasspathResource() throws Exception {
        assertJSLintOK(builder.fromClasspathResource(STUB_JSLINT));
    }

    @Test
    public void testFromDefault() throws Exception {
        assertJSLintOK(builder.fromDefault());
    }

    @Test
    public void testFromFile() throws Exception {
        File f = new File(getClass().getClassLoader().getResource(STUB_JSLINT).toURI());
        assertJSLintOK(builder.fromFile(f));
    }

    @Test
    public void testFromReader() throws Exception {
        // Same as stubjslint.js.
        String jslint = "function JSLINT() {JSLINT.errors=[];return true}";
        StringReader reader = new StringReader(jslint);
        assertJSLintOK(builder.fromReader(reader, "stubjslint.js"));
    }
}

@@ -186,33 +186,8 @@
 t;%0A%0A
-import org.junit.Before;%0A
 impo
@@ -393,16 +393,22 @@
 private 
+final 
 JSLintBu
@@ -420,16 +420,38 @@
  builder
+ = new JSLintBuilder()
 ;%0A%0A    /
@@ -800,109 +800,8 @@
  %7D%0A%0A
-    @Before%0A    public void setUp() throws Exception %7B%0A        builder = new JSLintBuilder();%0A    %7D%0A%0A
     

Initialize builder on construction.