You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/06/13 06:33:26 UTC
[GitHub] beiwei30 closed pull request #1936: [dubbo-1689]: Enhance the test
coverage part-10 : dubbo-plugin module, unit test for text
beiwei30 closed pull request #1936: [dubbo-1689]: Enhance the test coverage part-10 : dubbo-plugin module, unit test for text
URL: https://github.com/apache/incubator-dubbo/pull/1936
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 d0159e6411..b23595b885 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 @@
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 499e0918d3..36f1101156 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 0000000000..597b77b6e8
--- /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/TTreeTest.java b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TTreeTest.java
new file mode 100644
index 0000000000..ac89477e92
--- /dev/null
+++ b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TTreeTest.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 com.alibaba.dubbo.qos.textui;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+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);
+ }
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org