You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by il...@apache.org on 2018/06/13 06:33:38 UTC
[incubator-dubbo] branch master updated: #1689: Enhance the test
coverage part-10 : dubbo-plugin module, unit (#1936)
This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new d2e5652 #1689: Enhance the test coverage part-10 : dubbo-plugin module, unit (#1936)
d2e5652 is described below
commit d2e5652cb057bd08bcd39d579bbde32f3f4823a9
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Wed Jun 13 14:33:24 2018 +0800
#1689: Enhance the test coverage part-10 : dubbo-plugin module, unit (#1936)
test for textui
---
.../java/com/alibaba/dubbo/qos/textui/TKvTest.java | 33 ++++++++++---
.../qos/textui/TLadderTest.java} | 26 +++++++---
.../com/alibaba/dubbo/qos/textui/TTableTest.java | 55 ++++++++++++++++++++++
.../qos/textui/{TKvTest.java => TTreeTest.java} | 37 ++++++++-------
4 files changed, 122 insertions(+), 29 deletions(-)
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java
index d0159e6..b23595b 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java
@@ -18,22 +18,43 @@ package com.alibaba.dubbo.qos.textui;
import org.junit.Test;
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertThat;
+
public class TKvTest {
@Test
- public void outPutTest() {
-
- final TKv tKv = new TKv(new TTable.ColumnDefine(TTable.Align.RIGHT), new TTable.ColumnDefine(10, false, TTable.Align.LEFT));
+ public void test1() {
+ TKv tKv = new TKv(new TTable.ColumnDefine(TTable.Align.RIGHT), new TTable.ColumnDefine(10, false, TTable.Align.LEFT));
tKv.add("KEY-1", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
tKv.add("KEY-2", "1234567890");
tKv.add("KEY-3", "1234567890");
- final TTable tTable = new TTable(new TTable.ColumnDefine[]{
+ TTable tTable = new TTable(new TTable.ColumnDefine[]{
new TTable.ColumnDefine(),
new TTable.ColumnDefine(20, false, TTable.Align.LEFT)
});
- tTable.addRow("OPTIONS", tKv.rendering());
+ String kv = tKv.rendering();
+ assertThat(kv, containsString("ABCDEFGHIJ\n"));
+ assertThat(kv, containsString("KLMNOPQRST\n"));
+ assertThat(kv, containsString("UVWXYZ\n"));
+
+ tTable.addRow("OPTIONS", kv);
+ String table = tTable.rendering();
+ assertThat(table, containsString("|OPTIONS|"));
+ assertThat(table, containsString("|KEY-3"));
+
+ System.out.println(table);
+ }
- System.out.println(tTable.rendering());
+ @Test
+ public void test2() throws Exception {
+ TKv tKv = new TKv();
+ tKv.add("KEY-1", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+ tKv.add("KEY-2", "1234567890");
+ tKv.add("KEY-3", "1234567890");
+ String kv = tKv.rendering();
+ assertThat(kv, containsString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
+ System.out.println(kv);
}
}
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/StringSplitTest.java b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TLadderTest.java
similarity index 54%
rename from dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/StringSplitTest.java
rename to dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TLadderTest.java
index 499e091..36f1101 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/StringSplitTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TLadderTest.java
@@ -6,7 +6,7 @@
* (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
+ * 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,
@@ -14,14 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.alibaba;
+package com.alibaba.dubbo.qos.textui;
import org.junit.Test;
-public class StringSplitTest {
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class TLadderTest {
@Test
- public void stringSplitTest(){
- String str = new String("?\\\\ helloworld ac");
- String[] result = str.split("(?<![\\\\]) ");
+ public void testRendering() throws Exception {
+ TLadder ladder = new TLadder();
+ ladder.addItem("1");
+ ladder.addItem("2");
+ ladder.addItem("3");
+ ladder.addItem("4");
+ String result = ladder.rendering();
+ String expected = "1\n" +
+ " `-2\n" +
+ " `-3\n" +
+ " `-4\n";
+ assertThat(result, equalTo(expected));
+ System.out.println(result);
}
}
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TTableTest.java b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TTableTest.java
new file mode 100644
index 0000000..597b77b
--- /dev/null
+++ b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TTableTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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 com.alibaba.dubbo.qos.textui;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class TTableTest {
+ @Test
+ public void test1() throws Exception {
+ TTable table = new TTable(4);
+ table.addRow(1, "one", "uno", "un");
+ table.addRow(2, "two", "dos", "deux");
+ String result = table.rendering();
+ String expected = "+-+---+---+----+\n" +
+ "|1|one|uno|un |\n" +
+ "+-+---+---+----+\n" +
+ "|2|two|dos|deux|\n" +
+ "+-+---+---+----+\n";
+ assertThat(result, equalTo(expected));
+ System.out.println(result);
+ }
+
+ @Test
+ public void test2() throws Exception {
+ TTable table = new TTable(new TTable.ColumnDefine[]{
+ new TTable.ColumnDefine(5, true, TTable.Align.LEFT),
+ new TTable.ColumnDefine(10, false, TTable.Align.MIDDLE),
+ new TTable.ColumnDefine(10, false, TTable.Align.RIGHT)
+ });
+ table.addRow(1, "abcde", "ABCDE");
+ String result = table.rendering();
+ String expected = "+-+----------+----------+\n" +
+ "|1| abcde | ABCDE|\n" +
+ "+-+----------+----------+\n";
+ assertThat(result, equalTo(expected));
+ System.out.println(result);
+ }
+}
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TTreeTest.java
similarity index 51%
copy from dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java
copy to dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TTreeTest.java
index d0159e6..ac89477 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TTreeTest.java
@@ -6,7 +6,7 @@
* (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
+ * 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,
@@ -18,22 +18,25 @@ package com.alibaba.dubbo.qos.textui;
import org.junit.Test;
-public class TKvTest {
- @Test
- public void outPutTest() {
-
- final TKv tKv = new TKv(new TTable.ColumnDefine(TTable.Align.RIGHT), new TTable.ColumnDefine(10, false, TTable.Align.LEFT));
- tKv.add("KEY-1", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
- tKv.add("KEY-2", "1234567890");
- tKv.add("KEY-3", "1234567890");
-
- final TTable tTable = new TTable(new TTable.ColumnDefine[]{
- new TTable.ColumnDefine(),
- new TTable.ColumnDefine(20, false, TTable.Align.LEFT)
- });
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
- tTable.addRow("OPTIONS", tKv.rendering());
-
- System.out.println(tTable.rendering());
+public class TTreeTest {
+ @Test
+ public void test() throws Exception {
+ TTree tree = new TTree(false, "root");
+ tree.begin("one").begin("ONE").end().end();
+ tree.begin("two").begin("TWO").end().begin("2").end().end();
+ tree.begin("three").end();
+ String result = tree.rendering();
+ String expected = "`---+root\n" +
+ " +---+one\n" +
+ " | `---ONE\n" +
+ " +---+two\n" +
+ " | +---TWO\n" +
+ " | `---2\n" +
+ " `---three\n";
+ assertThat(result, equalTo(expected));
+ System.out.println(result);
}
}
--
To stop receiving notification emails like this one, please contact
iluo@apache.org.