You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/08/17 21:48:11 UTC
[04/38] usergrid git commit: Add null checks and tests confirming
NPEs are thrown.
Add null checks and tests confirming NPEs are thrown.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/ad4a3371
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/ad4a3371
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/ad4a3371
Branch: refs/heads/master
Commit: ad4a33713e8280a4d3637bf1395937bd32aa5fca
Parents: a62fb0a
Author: Michael Russo <mi...@gmail.com>
Authored: Tue Feb 9 17:36:49 2016 -0800
Committer: Michael Russo <mi...@gmail.com>
Committed: Tue Feb 9 17:36:49 2016 -0800
----------------------------------------------------------------------
.../core/datastax/TableDefinition.java | 8 ++
.../core/datastax/TableDefinitionTest.java | 81 ++++++++++++++++++++
2 files changed, 89 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/ad4a3371/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java
index 58d43a5..801eaa7 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/datastax/TableDefinition.java
@@ -22,6 +22,8 @@
package org.apache.usergrid.persistence.core.datastax;
+import com.google.common.base.Preconditions;
+
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -65,6 +67,12 @@ public class TableDefinition {
final Map<String, String> columns, final CacheOption cacheOption,
final Map<String, String> clusteringOrder){
+ Preconditions.checkNotNull(tableName, "Table name cannot be null");
+ Preconditions.checkNotNull(primaryKeys, "Primary Key(s) cannot be null");
+ Preconditions.checkNotNull(columns, "Columns cannot be null");
+ Preconditions.checkNotNull(cacheOption, "CacheOption cannot be null");
+
+
this.tableName = tableName;
this.primaryKeys = primaryKeys;
this.columns = columns;
http://git-wip-us.apache.org/repos/asf/usergrid/blob/ad4a3371/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/TableDefinitionTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/TableDefinitionTest.java b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/TableDefinitionTest.java
new file mode 100644
index 0000000..792864b
--- /dev/null
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/datastax/TableDefinitionTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.usergrid.persistence.core.datastax;
+
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import static org.junit.Assert.assertEquals;
+
+public class TableDefinitionTest {
+
+ @Test
+ public void testNullTableName(){
+
+ try{
+ TableDefinition table1 = new TableDefinition(null, null, null, null, null);
+ } catch (NullPointerException npe){
+ assertEquals("Table name cannot be null", npe.getMessage());
+ }
+
+
+ }
+
+ @Test
+ public void testNullPrimaryKeys(){
+
+ try{
+ TableDefinition table1 = new TableDefinition("table1", null, null, null, null);
+ } catch (NullPointerException npe){
+ assertEquals("Primary Key(s) cannot be null", npe.getMessage());
+ }
+
+
+ }
+
+ @Test
+ public void testNullColumns(){
+
+ try{
+ TableDefinition table1 = new TableDefinition("table1",
+ new ArrayList<>(), null, null, null);
+ } catch (NullPointerException npe){
+ assertEquals("Columns cannot be null", npe.getMessage());
+ }
+
+
+ }
+
+ @Test
+ public void testNullCacheOption(){
+
+ try{
+ TableDefinition table1 = new TableDefinition("table1",
+ new ArrayList<>(),
+ new HashMap<>(), null, null);
+ } catch (NullPointerException npe){
+ assertEquals("CacheOption cannot be null", npe.getMessage());
+ }
+
+
+ }
+}