<commit_before>package de.bmoth.typechecker;

import de.bmoth.parser.Parser;
import de.bmoth.parser.ast.TypeErrorException;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class TypeErrorExceptionTest {

    @Test(expected = TypeErrorException.class)
    public void testTypeErrorException() {
        String formula = "a = TRUE & b = 1 & a = b";
        Parser.getFormulaAsSemanticAst(formula);
    }

    @Test(expected = TypeErrorException.class)
    public void testTypeErrorException2() {
        String formula = "a = TRUE & a = 1 + 1";
        Parser.getFormulaAsSemanticAst(formula);
    }

    @Test
    public void testSetEnumeration() {
        String formula = "x = {1,2,(3,4)}";
        String exceptionMessage = getExceptionMessage(formula);
        assertTrue(exceptionMessage != null &&exceptionMessage.contains("Expected INTEGER but found INTEGER*INTEGER"));
    }

    @Test
    public void testSetEnumeration2() {
        String formula = "x = {1,2,{3,4}}";
        String exceptionMessage = getExceptionMessage(formula);
        assertTrue(exceptionMessage != null &&exceptionMessage.contains("found POW"));
    }

    private static String getExceptionMessage(String formula) {
        try {
            Parser.getFormulaAsSemanticAst(formula);
            fail("Expected a type error exception.");
            return "";
        } catch (TypeErrorException e) {
            return e.getMessage();
        }
    }
}
<commit_msg>Revert "fix "NullPionterException could be thrown"-bug, see sonar qube L28, L35"<commit_after>package de.bmoth.typechecker;

import de.bmoth.parser.Parser;
import de.bmoth.parser.ast.TypeErrorException;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class TypeErrorExceptionTest {

    @Test(expected = TypeErrorException.class)
    public void testTypeErrorException() {
        String formula = "a = TRUE & b = 1 & a = b";
        Parser.getFormulaAsSemanticAst(formula);
    }

    @Test(expected = TypeErrorException.class)
    public void testTypeErrorException2() {
        String formula = "a = TRUE & a = 1 + 1";
        Parser.getFormulaAsSemanticAst(formula);
    }

    @Test
    public void testSetEnumeration() {
        String formula = "x = {1,2,(3,4)}";
        String exceptionMessage = getExceptionMessage(formula);
        assertTrue(exceptionMessage.contains("Expected INTEGER but found INTEGER*INTEGER"));
    }

    @Test
    public void testSetEnumeration2() {
        String formula = "x = {1,2,{3,4}}";
        String exceptionMessage = getExceptionMessage(formula);
        assertTrue(exceptionMessage.contains("found POW"));
    }

    private static String getExceptionMessage(String formula) {
        try {
            Parser.getFormulaAsSemanticAst(formula);
            fail("Expected a type error exception.");
            return "";
        } catch (TypeErrorException e) {
            return e.getMessage();
        }
    }
}

{'fraction_non_alphanumeric': 0.10825929582099375, 'fraction_numerical': 0.009871668311944718, 'mean_word_length': 3.0211640211640214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2559931', 'n_tokens_mistral': 885, 'n_tokens_neox': 841, 'n_words': 196}