From ae9c1a2c8ba10fb2c60654d41657bf1093715b4a Mon Sep 17 00:00:00 2001 From: Menaka Jayawardena Date: Thu, 12 Oct 2017 12:21:05 +0530 Subject: [PATCH] Removed print stacktrace and changed the check for exceptions. --- .../carbon/device/mgt/core/search/ProcessorImplTest.java | 9 +++++---- .../mgt/core/search/SearchManagementServiceTest.java | 8 +++++--- .../device/mgt/core/search/util/ChangeEnumValues.java | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/ProcessorImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/ProcessorImplTest.java index 32d0d365e3..4e5f26a548 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/ProcessorImplTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/ProcessorImplTest.java @@ -34,6 +34,7 @@ import org.wso2.carbon.device.mgt.core.common.TestDataHolder; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; +import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException; import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; import org.wso2.carbon.device.mgt.core.search.mgt.impl.ProcessorImpl; import org.wso2.carbon.device.mgt.core.search.util.ChangeEnumValues; @@ -116,7 +117,7 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{ @Test(description = "Test for invalid state") - public void testInvalidState() { + public void testInvalidState() throws SearchMgtException { SearchContext context = new SearchContext(); List conditions = new ArrayList<>(); @@ -151,9 +152,9 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{ try { processor.execute(context); } catch (SearchMgtException e) { - Boolean isInvalidOperation = e.getCause().getClass().getCanonicalName().contains - ("InvalidOperatorException"); - Assert.assertTrue(isInvalidOperation); + if (!(e.getCause() instanceof InvalidOperatorException)) { + throw e; + } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java index 307441a812..9e13782945 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java @@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; +import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException; import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; import org.wso2.carbon.device.mgt.core.search.mgt.impl.SearchManagerServiceImpl; @@ -204,7 +205,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest { } @Test(description = "Test for invalid number") - public void testInvalidNumber() { + public void testInvalidNumber() throws SearchMgtException { SearchContext context = new SearchContext(); List conditions = new ArrayList<>(); @@ -221,8 +222,9 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest { try { service.search(context); } catch (SearchMgtException e) { - String expectedException = e.getCause().getClass().getName(); - Assert.assertTrue(expectedException.contains("InvalidOperatorException")); + if (!(e.getCause() instanceof InvalidOperatorException)) { + throw e; + } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/ChangeEnumValues.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/ChangeEnumValues.java index 3fa378a005..2d0163e7c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/ChangeEnumValues.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/ChangeEnumValues.java @@ -125,7 +125,6 @@ public class ChangeEnumValues { cleanEnumCache(enumType); } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException(e.getMessage(), e); } }