<commit_before>package org.raidenjpa.query.parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import org.junit.Test;
import org.raidenjpa.util.FixMe;

public class WhereClauseTest {

	@Test
	public void testOneExpression() {
		String jpql = "SELECT a FROM A a WHERE a.stringValue = :a";

		QueryParser parser = new QueryParser(jpql);
		WhereClause where = parser.getWhere();

		WhereExpression expression = (WhereExpression) where.nextElement();
		
		ExpressionPath left = (ExpressionPath) expression.getLeft();
		assertEquals(2, left.getPath().size());
		assertEquals("a", left.getPath().get(0));
		assertEquals("stringValue", left.getPath().get(1));

		assertEquals("=", expression.getOperator());

		ExpressionParameter right = (ExpressionParameter) expression.getRight();
		assertEquals("a", right.getParameterName());

		assertFalse(where.hasNextElement());
	}

	@FixMe("Improve this test")
	@Test
	public void testAndExpression() {
		String jpql;
		jpql = "SELECT a FROM A a";
		jpql += " WHERE a.stringValue = :stringValue AND a.intValue = :intValue";

		QueryParser parser = new QueryParser(jpql);
		WhereClause where = parser.getWhere();
		assertEquals(WhereExpression.class, where.nextElement().getClass());
		assertEquals(WhereLogicOperator.class, where.nextElement().getClass());
		assertEquals(WhereExpression.class, where.nextElement().getClass());
	}
}<commit_msg>Where with and<commit_after>package org.raidenjpa.query.parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import org.junit.Test;

public class WhereClauseTest {

	@Test
	public void testOneExpression() {
		String jpql = "SELECT a FROM A a WHERE a.stringValue = :a";

		QueryParser parser = new QueryParser(jpql);
		WhereClause where = parser.getWhere();

		WhereExpression expression = (WhereExpression) where.nextElement();
		assertExpression(expression, "a.stringValue", "=", "a");

		assertFalse(where.hasNextElement());
	}

	@Test
	public void testAndExpression() {
		String jpql;
		jpql = "SELECT a FROM A a";
		jpql += " WHERE a.stringValue = :stringValue AND a.intValue = :intValue";

		QueryParser parser = new QueryParser(jpql);
		WhereClause where = parser.getWhere();
		
		WhereExpression firstExpression = (WhereExpression) where.nextElement();
		assertExpression(firstExpression, "a.stringValue", "=", "stringValue");
		
		WhereLogicOperator logicOperator = (WhereLogicOperator) where.nextElement();
		assertEquals("AND", logicOperator.getOperator());
		
		WhereExpression secondExpression = (WhereExpression) where.nextElement();
		assertExpression(secondExpression, "a.intValue", "=", "intValue");
	}

	private void assertExpression(WhereExpression expression, String leftSide, String operator, String rightSide) {
		ExpressionPath left = (ExpressionPath) expression.getLeft();
		String[] paths = leftSide.split("\\.");
		assertEquals(paths.length, left.getPath().size());
		assertEquals(paths[0], left.getPath().get(0));
		assertEquals(paths[1], left.getPath().get(1));

		assertEquals(operator, expression.getOperator());

		ExpressionParameter right = (ExpressionParameter) expression.getRight();
		assertEquals(rightSide, right.getParameterName());
	}
}
{'fraction_non_alphanumeric': 0.13269704433497537, 'fraction_numerical': 0.0021551724137931034, 'mean_word_length': 5.726708074534161, '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': '1568108', 'n_tokens_mistral': 995, 'n_tokens_neox': 919, 'n_words': 215}