summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src/test/java
diff options
context:
space:
mode:
authoryoubowu <wu.youbo@zte.com.cn>2017-03-01 10:55:46 +0800
committer6092002067 <wu.youbo@zte.com.cn>2017-03-01 10:55:46 +0800
commit57d0c9e7572a9de13c7e26f57e98e9a0cdd564a7 (patch)
treee04f37e378a668eb4c4fa900132d57a8abc3fbce /holmes-actions/src/test/java
parent4043a64dabad0f27afcb67e9b62272c4e44a4214 (diff)
Fix the sonar detected error
Issue-ID:HOLMES-51 Change-Id: I1ac160651d7cd1382076a447d33482219cdb0def Signed-off-by: youbowu <wu.youbo@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/test/java')
-rw-r--r--holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java6
-rw-r--r--holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java50
-rw-r--r--holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java23
-rw-r--r--holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java3
4 files changed, 73 insertions, 9 deletions
diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java
index b740d87..49858ab 100644
--- a/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java
+++ b/holmes-actions/src/test/java/org/openo/holmes/common/api/stat/AlarmTest.java
@@ -170,9 +170,9 @@ public class AlarmTest {
@Test
public void testGetAlarmTypeRuleId_notNull() throws Exception {
final String ruleId = "ruleId";
- final int rootAlarmTyep = 2;
- alarm.getRootAlarmTypeMap().put(ruleId, rootAlarmTyep);
- assertThat(rootAlarmTyep, equalTo(alarm.getRootAlarmType(ruleId)));
+ final int rootAlarmType = 2;
+ alarm.getRootAlarmTypeMap().put(ruleId, rootAlarmType);
+ assertThat(rootAlarmType, equalTo(alarm.getRootAlarmType(ruleId)));
}
@Test
diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java
index b56e4ee..18c774e 100644
--- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java
+++ b/holmes-actions/src/test/java/org/openo/holmes/common/utils/DbDaoUtilTest.java
@@ -18,10 +18,13 @@ package org.openo.holmes.common.utils;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jdbi.DBIFactory;
import io.dropwizard.setup.Environment;
+import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -81,7 +84,7 @@ public class DbDaoUtilTest {
}
@Test
- public void getDao() throws Exception {
+ public void getDao_normal() throws Exception {
Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class);
@@ -93,7 +96,22 @@ public class DbDaoUtilTest {
}
@Test
- public void testGetHandle() throws Exception {
+ public void getDao_exception() throws Exception {
+ Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
+
+ expect(jdbi.open(anyObject(Class.class))).andThrow(new RuntimeException(""));
+
+ PowerMock.replayAll();
+
+ Object o = dbDaoUtil.getDao(String.class);
+
+ PowerMock.verifyAll();
+
+ assertThat(o, equalTo(null));
+ }
+
+ @Test
+ public void getHandle_normal() throws Exception {
Handle handle = PowerMock.createMock(Handle.class);
Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
@@ -105,9 +123,24 @@ public class DbDaoUtilTest {
PowerMock.verifyAll();
}
+ @Test
+ public void getHandle_exception() throws Exception {
+ Handle handle = PowerMock.createMock(Handle.class);
+
+ Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
+ expect(jdbi.open()).andThrow(new RuntimeException(""));
+
+ PowerMock.replayAll();
+
+ Handle handle1 = dbDaoUtil.getHandle();
+
+ PowerMock.verifyAll();
+
+ assertThat(handle1, equalTo(null));
+ }
@Test
- public void testClose() throws Exception {
+ public void close_normal() throws Exception {
Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
jdbi.close(anyObject());
@@ -119,6 +152,17 @@ public class DbDaoUtilTest {
}
@Test
+ public void close_exception() throws Exception {
+ Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
+ jdbi.close(anyObject());
+ EasyMock.expectLastCall().andThrow(new RuntimeException(""));
+ PowerMock.replayAll();
+
+ dbDaoUtil.close(new Object());
+
+ PowerMock.verifyAll();
+ }
+ @Test
public void testGetJdbiDaoByOnDemand() throws Exception {
Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
expect(jdbi.onDemand(anyObject(Class.class))).andReturn(Class.class);
diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java
index 64b31f4..c3631ac 100644
--- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java
+++ b/holmes-actions/src/test/java/org/openo/holmes/common/utils/I18nProxyTest.java
@@ -21,6 +21,7 @@ import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Locale;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
@@ -34,8 +35,28 @@ public class I18nProxyTest {
}
@Test
- public void testGetValue() {
+ public void getValue_locale_and_key() {
String result = i18nProxy.getValue(new Locale("zh"), "test");
assertThat(result, equalTo(null));
}
+ @Test
+ public void getValueByArgs(){
+ String result = i18nProxy.getValueByArgs(new Locale("zh"), "test",new String[]{"1"});
+ assertThat(result,equalTo(null));
+ }
+ @Test
+ public void getValue_by_key(){
+ Map<String,String> result = i18nProxy.getValue("test");
+ assertThat(result, equalTo(null));
+ }
+ @Test
+ public void jsonI18n(){
+ String result = i18nProxy.jsonI18n("test");
+ assertThat(result,equalTo(null));
+ }
+ @Test
+ public void i18nWithArgs(){
+ String result = i18nProxy.i18nWithArgs("test",new String[]{});
+ assertThat(result,equalTo("null"));
+ }
} \ No newline at end of file
diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java
index 25da9ac..a2a0542 100644
--- a/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java
+++ b/holmes-actions/src/test/java/org/openo/holmes/common/utils/JudgeNullUtilTest.java
@@ -26,7 +26,7 @@ import org.junit.Test;
public class JudgeNullUtilTest {
@Test
- public void isEmpty_array() {
+ public void isEmpty_array_length_zero() {
boolean resultShorts = JudgeNullUtil.isEmpty(new short[]{});
boolean resultInts = JudgeNullUtil.isEmpty(new int[]{});
boolean resultLongs = JudgeNullUtil.isEmpty(new long[]{});
@@ -40,5 +40,4 @@ public class JudgeNullUtilTest {
assertThat(true, equalTo(resultStrings));
assertThat(true, equalTo(resultLists));
}
-
} \ No newline at end of file