From 8bb9f9263b783d41bf9c1cfb5925afb3704e42c2 Mon Sep 17 00:00:00 2001 From: Guanchao Yang <32863418+guanchao-yang@users.noreply.github.com> Date: Tue, 5 Jun 2018 15:51:11 +0800 Subject: [PATCH] Compatible old ReportUtil usage and supply test cases (#14) ## Motivation Before some alipay users use ReportUtil with the full package com.alipay.sofa.common.log.ReportUtil but in this version ReportUtil has been moved to com.alipay.sofa.common.utils.ReportUtil. Consider many users has used, so we should be compatible with it ## Modification com.alipay.sofa.common.log.ReportUtil extends com.alipay.sofa.common.utils.ReportUtil for compatible ## Result Fixes #14 #16 only litte cases and after should provide more test cases --- .github/ISSUE_TEMPLATE/Ask_Question.md | 28 +++++++++++++ .github/ISSUE_TEMPLATE/Bug_Report.md | 26 ++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 15 +++++++ .../alipay/sofa/common/log/ReportUtil.java | 31 ++++++++++++++ .../sofa/common/utils/AssertUtilTest.java | 40 +++++++++++++++++++ .../sofa/common/utils/ReportUtilTest.java | 28 +++++++++++++ 6 files changed, 168 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/Ask_Question.md create mode 100644 .github/ISSUE_TEMPLATE/Bug_Report.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 src/main/java/com/alipay/sofa/common/log/ReportUtil.java create mode 100644 src/test/java/com/alipay/sofa/common/utils/AssertUtilTest.java create mode 100644 src/test/java/com/alipay/sofa/common/utils/ReportUtilTest.java diff --git a/.github/ISSUE_TEMPLATE/Ask_Question.md b/.github/ISSUE_TEMPLATE/Ask_Question.md new file mode 100644 index 00000000..61c23046 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Ask_Question.md @@ -0,0 +1,28 @@ +--- +name: Ask Question +about: Ask a question about usage or feature + +--- + +### Your question + +describe your question clearly + +### Your scenes + +describe your use scenes (why need this feature) + +### Your advice + +describe the advice or solution you'd like + +### Environment + +- sofa-common-tools version: +- JVM version (e.g. `java -version`): +- OS version (e.g. `uname -a`): +- Maven version: +- IDE version: + + + diff --git a/.github/ISSUE_TEMPLATE/Bug_Report.md b/.github/ISSUE_TEMPLATE/Bug_Report.md new file mode 100644 index 00000000..040243fb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Bug_Report.md @@ -0,0 +1,26 @@ +--- +name: Bug Report +about: Create a report to help us improve + +--- + +### Describe the bug + +A clear and concise description of what the bug is. + +### Expected behavior + +### Actual behavior + +### Steps to reproduce + +### Minimal yet complete reproducer code (or GitHub URL to code) + +### Environment + +- sofa-common-tools version: +- JVM version (e.g. `java -version`): +- OS version (e.g. `uname -a`): +- Maven version: +- IDE version: + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..84012927 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,15 @@ +### Motivation: + +Explain the context, and why you're making that change. +To make others understand what is the problem you're trying to solve. + +### Modification: + +Describe the idea and modifications you've done. + +### Result: + +Fixes #. + +If there is no issue then describe the changes introduced by this PR. + diff --git a/src/main/java/com/alipay/sofa/common/log/ReportUtil.java b/src/main/java/com/alipay/sofa/common/log/ReportUtil.java new file mode 100644 index 00000000..c8a6f8e3 --- /dev/null +++ b/src/main/java/com/alipay/sofa/common/log/ReportUtil.java @@ -0,0 +1,31 @@ +/* + * 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.alipay.sofa.common.log; + +/** + * ReportUtil Compatible history usage + *

+ * Output logs to console and default logger + *

+ * Created by yangguanchao on 18/06/04. + */ +@Deprecated +public class ReportUtil extends com.alipay.sofa.common.utils.ReportUtil{ + +} + + diff --git a/src/test/java/com/alipay/sofa/common/utils/AssertUtilTest.java b/src/test/java/com/alipay/sofa/common/utils/AssertUtilTest.java new file mode 100644 index 00000000..437bdfc0 --- /dev/null +++ b/src/test/java/com/alipay/sofa/common/utils/AssertUtilTest.java @@ -0,0 +1,40 @@ +package com.alipay.sofa.common.utils; + +import org.junit.Test; + +/** + * AssertUtil Tester. + * + * @author + * @version 1.0 + * @since 18/06/04 + */ +public class AssertUtilTest { + + + /** + * Method: isTrue(boolean expression, String message) + */ + @Test + public void testIsTrueForExpressionMessage() throws Exception { + boolean isSuccess = false; + AssertUtil.isTrue(!isSuccess, "isTrue"); + boolean isException = false; + try { + AssertUtil.isTrue(isSuccess, "isTrue"); + } catch (Exception ex) { + isException = true; + } + AssertUtil.isTrue(isException); + } + + /** + * Method: isNull(Object object, String message) + */ + @Test + public void testIsNullForObjectMessage() throws Exception { + Object object = null; + AssertUtil.isNull(object, "null"); + AssertUtil.isNull(object); + } +} diff --git a/src/test/java/com/alipay/sofa/common/utils/ReportUtilTest.java b/src/test/java/com/alipay/sofa/common/utils/ReportUtilTest.java new file mode 100644 index 00000000..d9e16c97 --- /dev/null +++ b/src/test/java/com/alipay/sofa/common/utils/ReportUtilTest.java @@ -0,0 +1,28 @@ +package com.alipay.sofa.common.utils; + +import com.alipay.sofa.common.log.ReportUtil; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; + +/** + * ReportUtil Tester. + * + * @author + * @version 1.0 + * @since 18/06/04 + */ +public class ReportUtilTest { + + @Test + public void testUtils() { + String errMsg = "Some Error Msg"; + boolean isException = false; + try { + ReportUtil.reportError("RuntimeException", new RuntimeException()); + } catch (Exception ex) { + isException = true; + } + assertFalse(isException); + } +}