Updated Branches:
  refs/heads/master 767700827 -> fcc17fc0a

ACCUMULO-2326 Simplify ConstraintViolationSummary.toString and add unit test

Signed-off-by: Eric Newton <eric.new...@gmail.com>


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

Branch: refs/heads/master
Commit: fcc17fc0aa6f6a3a60de94786db02d7c4b68dfea
Parents: 7677008
Author: Vikram Srivastava <vikr...@cloudera.com>
Authored: Wed Feb 5 01:45:14 2014 -0800
Committer: Eric Newton <eric.new...@gmail.com>
Committed: Wed Feb 5 12:33:14 2014 -0500

----------------------------------------------------------------------
 .../core/data/ConstraintViolationSummary.java   | 34 ++----------------
 .../data/ConstraintViolationSummaryTest.java    | 37 ++++++++++++++++++++
 2 files changed, 40 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/fcc17fc0/core/src/main/java/org/apache/accumulo/core/data/ConstraintViolationSummary.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/accumulo/core/data/ConstraintViolationSummary.java
 
b/core/src/main/java/org/apache/accumulo/core/data/ConstraintViolationSummary.java
index 63c85a4..f84d1f6 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/data/ConstraintViolationSummary.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/data/ConstraintViolationSummary.java
@@ -71,37 +71,9 @@ public class ConstraintViolationSummary {
   
   @Override
   public String toString() {
-    StringBuilder sb = new StringBuilder("ConstraintViolationSummary(");
-    boolean first = true;
-    
-    sb.append("constrainClass:");
-    if (this.constrainClass == null) {
-      sb.append("null");
-    } else {
-      sb.append(this.constrainClass);
-    }
-    first = false;
-    if (!first)
-      sb.append(", ");
-    sb.append("violationCode:");
-    sb.append(this.violationCode);
-    first = false;
-    if (!first)
-      sb.append(", ");
-    sb.append("violationDescription:");
-    if (this.violationDescription == null) {
-      sb.append("null");
-    } else {
-      sb.append(this.violationDescription);
-    }
-    first = false;
-    if (!first)
-      sb.append(", ");
-    sb.append("numberOfViolatingMutations:");
-    sb.append(this.numberOfViolatingMutations);
-    first = false;
-    sb.append(")");
-    return sb.toString();
+    return String.format(
+        "ConstraintViolationSummary(constrainClass:%s, violationCode:%d, 
violationDescription:%s, numberOfViolatingMutations:%d)",
+        constrainClass, violationCode, violationDescription, 
numberOfViolatingMutations);
   }
   
   /**

http://git-wip-us.apache.org/repos/asf/accumulo/blob/fcc17fc0/core/src/test/java/org/apache/accumulo/core/data/ConstraintViolationSummaryTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/accumulo/core/data/ConstraintViolationSummaryTest.java
 
b/core/src/test/java/org/apache/accumulo/core/data/ConstraintViolationSummaryTest.java
new file mode 100644
index 0000000..ec2110e
--- /dev/null
+++ 
b/core/src/test/java/org/apache/accumulo/core/data/ConstraintViolationSummaryTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.accumulo.core.data;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ConstraintViolationSummaryTest {
+
+  @Test
+  public void testToString() {
+    ConstraintViolationSummary cvs = new ConstraintViolationSummary(
+        "fooClass", (short) 1, "fooDescription", 100L);
+    assertEquals("ConstraintViolationSummary(constrainClass:fooClass, 
violationCode:1, violationDescription:fooDescription, 
numberOfViolatingMutations:100)", 
+        cvs.toString());
+    
+    cvs = new ConstraintViolationSummary(
+        null, (short) 2, null, 101L);
+    assertEquals("ConstraintViolationSummary(constrainClass:null, 
violationCode:2, violationDescription:null, numberOfViolatingMutations:101)", 
+        cvs.toString());
+  }
+}

Reply via email to