cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject cayenne git commit: cleanup of unit tests; proper test class allocation
Date Sun, 13 Sep 2015 18:02:36 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 2ee597913 -> f33969143


cleanup of unit tests; proper test class allocation


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/f3396914
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/f3396914
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/f3396914

Branch: refs/heads/master
Commit: f339691436656bf623787ef12400aeda1d145199
Parents: 2ee5979
Author: aadamchik <aadamchik@apache.org>
Authored: Sun Sep 13 13:48:24 2015 -0400
Committer: aadamchik <aadamchik@apache.org>
Committed: Sun Sep 13 14:02:00 2015 -0400

----------------------------------------------------------------------
 .../org/apache/cayenne/exp/ExpressionTest.java  | 107 ++++---------------
 .../apache/cayenne/exp/parser/ASTEqualTest.java |  30 +++++-
 .../apache/cayenne/exp/parser/ASTInTest.java    |   8 ++
 .../exp/parser/ASTLikeIgnoreCaseTest.java       |  21 ++--
 .../apache/cayenne/exp/parser/ASTLikeTest.java  |   9 ++
 .../exp/parser/ASTNamedParameterTest.java       |  42 ++++++++
 .../cayenne/exp/parser/ASTObjPathTest.java      |   2 +-
 7 files changed, 116 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3396914/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
index b6616c4..e0e306b 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
@@ -33,89 +33,31 @@ import org.junit.Test;
 public class ExpressionTest {
 
 	@Test
-	public void testToEJBQL1() {
-
-		Expression e = ExpressionFactory.exp("artistName = \"bla\"");
-
-		// note single quotes - EJBQL does not support doublequotes...
-		assertEquals("x.artistName = 'bla'", e.toEJBQL("x"));
-	}
-
-	@Test
-	public void testEncodeAsEJBQL1() throws IOException {
-
-		Expression e = ExpressionFactory.exp("artistName = 'bla'");
-
-		StringBuilder buffer = new StringBuilder();
-
-		e.appendAsEJBQL(buffer, "x");
-
-		String ejbql = buffer.toString();
-
-		assertEquals("x.artistName = 'bla'", ejbql);
-	}
-
-	@Test
-	public void testEncodeAsEJBQL2() throws IOException {
-
-		Expression e = ExpressionFactory.exp("artistName.stuff = $name");
-
-		StringBuilder buffer = new StringBuilder();
-
-		e.appendAsEJBQL(buffer, "x");
-		String ejbql = buffer.toString();
-
-		assertEquals("x.artistName.stuff = :name", ejbql);
-	}
-
-	@Test
-	public void testEncodeAsEJBQL_likeEscape() throws IOException {
-		Expression e = ExpressionFactory.likeExp("mainName", "|%|%?|_title|%",
-				'|');
-		assertEquals("x.mainName like '|%|%?|_title|%' escape '|'",
-				e.toEJBQL("x"));
-	}
-
-	@Test
-	public void testEncodeAsEJBQL_numericType_integer() throws IOException {
-		Expression e = ExpressionFactory.matchExp("consignment.parts",
-				new Integer(123));
+	public void testToEJBQL_numericType_integer() throws IOException {
+		Expression e = ExpressionFactory.matchExp("consignment.parts", new Integer(123));
 		assertEquals("x.consignment.parts = 123", e.toEJBQL("x"));
 	}
 
 	@Test
-	public void testEncodeAsEJBQL_numericType_long() throws IOException {
-		Expression e = ExpressionFactory.matchExp("consignment.parts",
-				new Long(1418342400));
+	public void testToEJBQL_numericType_long() throws IOException {
+		Expression e = ExpressionFactory.matchExp("consignment.parts", new Long(1418342400));
 		assertEquals("x.consignment.parts = 1418342400", e.toEJBQL("x"));
 	}
 
 	@Test
-	public void testEncodeAsEJBQL_numericType_float() throws IOException {
-		Expression e = ExpressionFactory.greaterOrEqualExp("consignment.parts",
-				new Float("3.145"));
+	public void testToEJBQL_numericType_float() throws IOException {
+		Expression e = ExpressionFactory.greaterOrEqualExp("consignment.parts", new Float("3.145"));
 		assertEquals("x.consignment.parts >= 3.145", e.toEJBQL("x"));
 	}
 
 	@Test
-	public void testEncodeAsEJBQL_numericType_double() throws IOException {
-		Expression e = ExpressionFactory.greaterOrEqualExp("consignment.parts",
-				new Double(3.14));
+	public void testToEJBQL_numericType_double() throws IOException {
+		Expression e = ExpressionFactory.greaterOrEqualExp("consignment.parts", new Double(3.14));
 		assertEquals("x.consignment.parts >= 3.14", e.toEJBQL("x"));
 	}
 
 	@Test
-	public void testEncodeAsEJBQL_in() throws IOException {
-		List<Integer> valuesIn = new ArrayList<Integer>();
-		valuesIn.add(91);
-		valuesIn.add(23);
-		Expression e = ExpressionFactory.inExp("consignment.parts", valuesIn);
-		assertEquals("x.consignment.parts in (91, 23)", e.toEJBQL("x"));
-	}
-
-	@Test
-	public void testEncodeAsEJBQL_Timestamp_ParameterCapture()
-			throws IOException {
+	public void testAppendAsEJBQL_Timestamp_ParameterCapture() throws IOException {
 		Date now = new Date();
 
 		Expression e = ExpressionFactory.greaterOrEqualExp("dateOfBirth", now);
@@ -134,8 +76,7 @@ public class ExpressionTest {
 	}
 
 	@Test
-	public void testEncodeAsEJBQL3_EncodeListOfParameters_ParameterCapture()
-			throws IOException {
+	public void testAppendAsEJBQL_in_EncodeListOfParameters_ParameterCapture() throws IOException
{
 
 		Expression e = ExpressionFactory.inExp("artistName", "a", "b", "c");
 
@@ -155,7 +96,7 @@ public class ExpressionTest {
 	}
 
 	@Test
-	public void testEncodeAsEJBQL3_EncodeListOfParameters() throws IOException {
+	public void testAppendAsEJBQL_in_EncodeListOfParameters() throws IOException {
 
 		Expression e = ExpressionFactory.inExp("artistName", "a", "b", "c");
 
@@ -169,7 +110,7 @@ public class ExpressionTest {
 	}
 
 	@Test
-	public void testEncodeAsEJBQL_PersistentParamater() throws IOException {
+	public void testAppendAsEJBQL_PersistentParamater() throws IOException {
 
 		Artist a = new Artist();
 		ObjectId aId = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 1);
@@ -385,8 +326,7 @@ public class ExpressionTest {
 	 */
 	@Test
 	public void testBitwiseHuntingtonEquation() {
-		Expression theHuntingEquation = ExpressionFactory
-				.exp("~(~3748 | 4095) | ~(~3748 | ~4095)");
+		Expression theHuntingEquation = ExpressionFactory.exp("~(~3748 | 4095) | ~(~3748 | ~4095)");
 
 		assertEquals(new Long(3748), theHuntingEquation.evaluate(new Object()));
 	}
@@ -399,8 +339,7 @@ public class ExpressionTest {
 	 */
 	@Test
 	public void testBitwiseRobbinsEquation() {
-		Expression theRobbinsEquation = ExpressionFactory
-				.exp("~(~(5111 | 4095) | ~(5111 | ~4095))");
+		Expression theRobbinsEquation = ExpressionFactory.exp("~(~(5111 | 4095) | ~(5111 | ~4095))");
 
 		assertEquals(new Long(5111), theRobbinsEquation.evaluate(new Object()));
 	}
@@ -443,8 +382,7 @@ public class ExpressionTest {
 	}
 
 	@Test
-	public void testAppendAsEJBQLNotEquals_ParameterCapture()
-			throws IOException {
+	public void testAppendAsEJBQL_NotEquals_ParameterCapture() throws IOException {
 		Expression e = ExpressionFactory.exp("artistName != 'bla'");
 
 		StringBuilder buffer = new StringBuilder();
@@ -458,10 +396,9 @@ public class ExpressionTest {
 	}
 
 	@Test
-	public void testEncodeAsEJBQL_Enum() throws IOException {
+	public void testAppendAsEJBQL_Enum() throws IOException {
 
-		Expression e = ExpressionFactory
-				.exp("a = enum:org.apache.cayenne.exp.ExpEnum1.THREE");
+		Expression e = ExpressionFactory.exp("a = enum:org.apache.cayenne.exp.ExpEnum1.THREE");
 
 		StringBuilder buffer = new StringBuilder();
 		e.appendAsEJBQL(buffer, "x");
@@ -472,7 +409,7 @@ public class ExpressionTest {
 	}
 
 	@Test
-	public void testEncodeAsString_StringLiteral() throws IOException {
+	public void testAppendAsString_StringLiteral() throws IOException {
 		Expression e1 = ExpressionFactory.exp("a = 'abc'");
 
 		StringBuilder buffer = new StringBuilder();
@@ -483,15 +420,13 @@ public class ExpressionTest {
 	}
 
 	@Test
-	public void testEncodeAsString_Enum() throws IOException {
-		Expression e1 = ExpressionFactory
-				.exp("a = enum:org.apache.cayenne.exp.ExpEnum1.TWO");
+	public void testAppendAsString_Enum() throws IOException {
+		Expression e1 = ExpressionFactory.exp("a = enum:org.apache.cayenne.exp.ExpEnum1.TWO");
 
 		StringBuilder buffer = new StringBuilder();
 
 		e1.appendAsString(buffer);
-		assertEquals("a = enum:org.apache.cayenne.exp.ExpEnum1.TWO",
-				buffer.toString());
+		assertEquals("a = enum:org.apache.cayenne.exp.ExpEnum1.TWO", buffer.toString());
 	}
 
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3396914/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
index 0b2c1a7..5579dd5 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTEqualTest.java
@@ -18,12 +18,13 @@
  ****************************************************************/
 package org.apache.cayenne.exp.parser;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
 import java.math.BigDecimal;
 
-import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
 import org.junit.Test;
@@ -31,8 +32,27 @@ import org.junit.Test;
 public class ASTEqualTest {
 
 	@Test
+	public void testToEJBQL() {
+		ASTEqual e = new ASTEqual(new ASTObjPath("artistName"), "bla");
+
+		// note single quotes - EJBQL does not support doublequotes...
+		assertEquals("x.artistName = 'bla'", e.toEJBQL("x"));
+	}
+
+	@Test
+	public void testAppendAsEJBQL() throws IOException {
+
+		ASTEqual e = new ASTEqual(new ASTObjPath("artistName"), "bla");
+
+		StringBuilder buffer = new StringBuilder();
+		e.appendAsEJBQL(buffer, "x");
+		String ejbql = buffer.toString();
+		assertEquals("x.artistName = 'bla'", ejbql);
+	}
+
+	@Test
 	public void testEvaluate() {
-		Expression equalTo = new ASTEqual(new ASTObjPath("artistName"), "abc");
+		ASTEqual equalTo = new ASTEqual(new ASTObjPath("artistName"), "abc");
 
 		Artist match = new Artist();
 		match.setArtistName("abc");
@@ -45,8 +65,8 @@ public class ASTEqualTest {
 
 	@Test
 	public void testEvaluate_Null() {
-		Expression equalToNull = new ASTEqual(new ASTObjPath("artistName"), null);
-		Expression equalToNotNull = new ASTEqual(new ASTObjPath("artistName"), "abc");
+		ASTEqual equalToNull = new ASTEqual(new ASTObjPath("artistName"), null);
+		ASTEqual equalToNotNull = new ASTEqual(new ASTObjPath("artistName"), "abc");
 
 		Artist match = new Artist();
 		assertTrue(equalToNull.match(match));
@@ -64,7 +84,7 @@ public class ASTEqualTest {
 		BigDecimal bd3 = new BigDecimal("2.00");
 		BigDecimal bd4 = new BigDecimal("2.01");
 
-		Expression equalTo = new ASTEqual(new ASTObjPath(Painting.ESTIMATED_PRICE.getName()), bd1);
+		ASTEqual equalTo = new ASTEqual(new ASTObjPath(Painting.ESTIMATED_PRICE.getName()), bd1);
 
 		Painting p = new Painting();
 		p.setEstimatedPrice(bd2);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3396914/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTInTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTInTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTInTest.java
index fc5edb4..d7f429c 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTInTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTInTest.java
@@ -18,9 +18,11 @@
  ****************************************************************/
 package org.apache.cayenne.exp.parser;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
 import java.math.BigDecimal;
 
 import org.apache.cayenne.exp.Expression;
@@ -30,6 +32,12 @@ import org.junit.Test;
 public class ASTInTest {
 
 	@Test
+	public void testToEJBQL_in() throws IOException {
+		ASTIn e = new ASTIn(new ASTObjPath("consignment.parts"), new ASTList(new Object[] { 91,
23 }));
+		assertEquals("x.consignment.parts in (91, 23)", e.toEJBQL("x"));
+	}
+
+	@Test
 	public void testEvaluate() {
 		Expression in = new ASTIn(new ASTObjPath("estimatedPrice"), new ASTList(new Object[] {
new BigDecimal("10"),
 				new BigDecimal("20") }));

http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3396914/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
index a01b95a..9453a2f 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
@@ -18,23 +18,22 @@
  ****************************************************************/
 package org.apache.cayenne.exp.parser;
 
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.junit.Test;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.junit.Test;
+
 public class ASTLikeIgnoreCaseTest {
 
-    @Test
-    public void testToEJBQL() {
-        Expression like = ExpressionFactory.likeIgnoreCaseExp("a", "%b%");
-        assertEquals(like.toEJBQL("p"), "upper(p.a) like '%B%'");
-    }
-    
+	@Test
+	public void testToEJBQL() {
+		Expression like = new ASTLikeIgnoreCase(new ASTObjPath("a"), "%b%");
+		assertEquals(like.toEJBQL("p"), "upper(p.a) like '%B%'");
+	}
+
 	@Test
 	public void testEvaluate() {
 		Expression like = new ASTLikeIgnoreCase(new ASTObjPath("artistName"), "aBcD");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3396914/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java
index 8f50973..48d6890 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLikeTest.java
@@ -18,9 +18,12 @@
  ****************************************************************/
 package org.apache.cayenne.exp.parser;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
+
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.junit.Test;
@@ -28,6 +31,12 @@ import org.junit.Test;
 public class ASTLikeTest {
 
 	@Test
+	public void testToEJBQL_likeEscape() throws IOException {
+		Expression like = new ASTLike(new ASTObjPath("mainName"), "|%|%?|_title|%", '|');
+		assertEquals("x.mainName like '|%|%?|_title|%' escape '|'", like.toEJBQL("x"));
+	}
+
+	@Test
 	public void testEvaluate_MultiCharMatch() {
 		Expression like = new ASTLike(new ASTObjPath("artistName"), "abc%d");
 		Expression notLike = new ASTNotLike(new ASTObjPath("artistName"), "abc%d");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3396914/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTNamedParameterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTNamedParameterTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTNamedParameterTest.java
new file mode 100644
index 0000000..9e32464
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTNamedParameterTest.java
@@ -0,0 +1,42 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.cayenne.exp.parser;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class ASTNamedParameterTest {
+
+	@Test
+	public void testAppendAsEJBQL() throws IOException {
+
+		ASTNamedParameter e = new ASTNamedParameter("name");
+
+		StringBuilder buffer = new StringBuilder();
+
+		e.appendAsEJBQL(buffer, "x");
+		String ejbql = buffer.toString();
+
+		assertEquals(":name", ejbql);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/f3396914/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathTest.java
index 5e4e717..d360767 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathTest.java
@@ -34,7 +34,7 @@ public class ASTObjPathTest {
 	}
 
 	@Test
-	public void testEncodeAsString() throws IOException {
+	public void testAppendAsString() throws IOException {
 		StringBuilder buffer = new StringBuilder();
 		new ASTObjPath("x.y").appendAsString(buffer);
 		assertEquals("x.y", buffer.toString());


Mime
View raw message