<commit_before>/*
 * Copyright 2006-2007,  Unitils.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dbmaintain.script.impl;

import org.dbmaintain.scriptparser.ScriptParser;
import org.dbmaintain.scriptparser.impl.DefaultScriptParser;
import org.dbmaintain.util.DbMaintainException;
import org.junit.After;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;
import org.apache.commons.io.IOUtils;
import static org.apache.commons.io.IOUtils.closeQuietly;

import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.io.StringReader;

/**
 * Tests the SQL script parser
 *
 * @author <NAME>
 * @author <NAME>
 */
public class DefaultScriptParserTest {

    /* Reader for the test script */
    private Reader testSQLScriptReader;

    /* Reader for the test script with a missing semi colon */
    private Reader testSQLMissingSemiColonScriptReader;

    /* Reader for the test script ending with a comment */
    private Reader testSQLEndingWithCommentScriptReader;

    /* Reader for the test script not ending with a new line */
    private Reader testSQLNotEndingWithNewLineScriptReader;

    /* Reader for the empty script */
    private Reader emptyScriptReader;


    /**
     * Initialize test fixture
     */
    @Before
    public void setUp() throws Exception {
        testSQLScriptReader = new FileReader(new File(getClass().getResource("ScriptParserTest/sql-script.sql").toURI()));
        testSQLMissingSemiColonScriptReader = new FileReader(new File(getClass().getResource("ScriptParserTest/sql-script-missing-semicolon.sql").toURI()));
        testSQLEndingWithCommentScriptReader = new FileReader(new File(getClass().getResource("ScriptParserTest/sql-script-ending-with-comment.sql").toURI()));
        testSQLNotEndingWithNewLineScriptReader = new FileReader(new File(getClass().getResource("ScriptParserTest/sql-script-not-ending-with-new-line.sql").toURI()));
        emptyScriptReader = new StringReader("");
    }


    /**
     * Cleans up the test by closing the streams.
     */
    @After
    public void tearDown() throws Exception {
        closeQuietly(testSQLEndingWithCommentScriptReader);
        closeQuietly(testSQLMissingSemiColonScriptReader);
        closeQuietly(testSQLNotEndingWithNewLineScriptReader);
        closeQuietly(testSQLScriptReader);
        closeQuietly(emptyScriptReader);
    }


    /**
     * Test parsing some statements out of a script.
     * 13 statements should have been found in the script.
     */
    @Test
    public void testParseStatements() throws Exception {
        ScriptParser scriptParser = new DefaultScriptParser(testSQLScriptReader, false);

        for (int i = 0; i < 13; i++) {
            assertNotNull(scriptParser.getNextStatement());
        }
        assertNull(scriptParser.getNextStatement());
    }


    /**
     * Test parsing statements out of a script but statement does not end with a ;.
     * This should raise an exception
     */
    @Test(expected = DbMaintainException.class)
    public void testParseStatements_missingEndingSemiColon() throws Exception {
        ScriptParser scriptParser = new DefaultScriptParser(testSQLMissingSemiColonScriptReader, false);
        scriptParser.getNextStatement();
    }


    /**
     * Test parsing statements out of a script ending with a comment.
     */
    @Test
    public void testParseStatements_endingWithComment() throws Exception {
        ScriptParser scriptParser = new DefaultScriptParser(testSQLEndingWithCommentScriptReader, false);
        scriptParser.getNextStatement();
        scriptParser.getNextStatement();
    }


    /**
     * Test parsing statements out of a script that does not end with a new line.
     */
    @Test
    public void testParseStatements_notEndingWithNewLine() throws Exception {
        ScriptParser scriptParser = new DefaultScriptParser(testSQLNotEndingWithNewLineScriptReader, false);
        scriptParser.getNextStatement();
        scriptParser.getNextStatement();
    }


    /**
     * Test parsing some statements out of an empty script.
     */
    @Test
    public void testParseStatements_emptyScript() throws Exception {
        ScriptParser scriptParser = new DefaultScriptParser(emptyScriptReader, false);

        assertNull(scriptParser.getNextStatement());
    }
}<commit_msg>Fixed warnings<commit_after>/*
 * Copyright 2006-2007,  Unitils.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dbmaintain.script.impl;

import org.dbmaintain.scriptparser.ScriptParser;
import org.dbmaintain.scriptparser.impl.DefaultScriptParser;
import org.dbmaintain.util.DbMaintainException;
import org.junit.After;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;
import static org.apache.commons.io.IOUtils.closeQuietly;

import java.io.*;
import java.net.URISyntaxException;

/**
 * Tests the SQL script parser
 *
 * @author <NAME>
 * @author <NAME>
 */
public class DefaultScriptParserTest {

    /* Reader for the test script */
    private Reader testSQLScriptReader;

    /* Reader for the test script with a missing semi colon */
    private Reader testSQLMissingSemiColonScriptReader;

    /* Reader for the test script ending with a comment */
    private Reader testSQLEndingWithCommentScriptReader;

    /* Reader for the test script not ending with a new line */
    private Reader testSQLNotEndingWithNewLineScriptReader;

    /* Reader for the empty script */
    private Reader emptyScriptReader;


    /**
     * Initialize test fixture
     */
    @Before
    public void setUp() {
        testSQLScriptReader = getScriptReader("ScriptParserTest/sql-script.sql");
        testSQLMissingSemiColonScriptReader = getScriptReader("ScriptParserTest/sql-script-missing-semicolon.sql");
        testSQLEndingWithCommentScriptReader = getScriptReader("ScriptParserTest/sql-script-ending-with-comment.sql");
        testSQLNotEndingWithNewLineScriptReader = getScriptReader("ScriptParserTest/sql-script-not-ending-with-new-line.sql");
        emptyScriptReader = new StringReader("");
    }

    private FileReader getScriptReader(String scriptName) {
        try {
            return new FileReader(new File(getClass().getResource(scriptName).toURI()));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }


    /**
     * Cleans up the test by closing the streams.
     */
    @After
    public void tearDown() {
        closeQuietly(testSQLEndingWithCommentScriptReader);
        closeQuietly(testSQLMissingSemiColonScriptReader);
        closeQuietly(testSQLNotEndingWithNewLineScriptReader);
        closeQuietly(testSQLScriptReader);
        closeQuietly(emptyScriptReader);
    }


    /**
     * Test parsing some statements out of a script.
     * 13 statements should have been found in the script.
     */
    @Test
    public void testParseStatements() {
        ScriptParser scriptParser = new DefaultScriptParser(testSQLScriptReader, false);

        for (int i = 0; i < 13; i++) {
            assertNotNull(scriptParser.getNextStatement());
        }
        assertNull(scriptParser.getNextStatement());
    }


    /**
     * Test parsing statements out of a script but statement does not end with a ;.
     * This should raise an exception
     */
    @Test(expected = DbMaintainException.class)
    public void testParseStatements_missingEndingSemiColon() {
        ScriptParser scriptParser = new DefaultScriptParser(testSQLMissingSemiColonScriptReader, false);
        scriptParser.getNextStatement();
    }


    /**
     * Test parsing statements out of a script ending with a comment.
     */
    @Test
    public void testParseStatements_endingWithComment() {
        ScriptParser scriptParser = new DefaultScriptParser(testSQLEndingWithCommentScriptReader, false);
        scriptParser.getNextStatement();
        scriptParser.getNextStatement();
    }


    /**
     * Test parsing statements out of a script that does not end with a new line.
     */
    @Test
    public void testParseStatements_notEndingWithNewLine() {
        ScriptParser scriptParser = new DefaultScriptParser(testSQLNotEndingWithNewLineScriptReader, false);
        scriptParser.getNextStatement();
        scriptParser.getNextStatement();
    }


    /**
     * Test parsing some statements out of an empty script.
     */
    @Test
    public void testParseStatements_emptyScript() {
        ScriptParser scriptParser = new DefaultScriptParser(emptyScriptReader, false);

        assertNull(scriptParser.getNextStatement());
    }
}
{'fraction_non_alphanumeric': 0.0832569041067971, 'fraction_numerical': 0.0034647916029756447, 'mean_word_length': 3.452813067150635, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '1697801', 'n_tokens_mistral': 2659, 'n_tokens_neox': 2553, 'n_words': 736}