From f4da4c35fc5e45604983f04668375e3e1c43db6b Mon Sep 17 00:00:00 2001 From: harshanL Date: Fri, 13 Feb 2015 10:56:42 +0530 Subject: [PATCH] Refactored unit-tests --- .../MobileDeviceManagementConfigTests.java | 43 ++++++++----------- .../MobileFeaturePropertyDAOTestSuite.java | 2 +- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConfigTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConfigTests.java index fd692365a..ad7713761 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConfigTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConfigTests.java @@ -70,65 +70,58 @@ public class MobileDeviceManagementConfigTests { } } - @Test() - public void testMandateManagementRepositoryElement() { + @Test(expectedExceptions = JAXBException.class) + public void testMandateManagementRepositoryElement() throws JAXBException { File malformedConfig = new File( MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY); this.validateMalformedConfig(malformedConfig); } - @Test - public void testMandateDataSourceConfigurationElement() { + @Test(expectedExceptions = JAXBException.class) + public void testMandateDataSourceConfigurationElement() throws JAXBException { File malformedConfig = new File( MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG); this.validateMalformedConfig(malformedConfig); } - @Test - public void testMandateJndiLookupDefinitionElement() { + @Test(expectedExceptions = JAXBException.class) + public void testMandateJndiLookupDefinitionElement() throws JAXBException { File malformedConfig = new File( MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG); this.validateMalformedConfig(malformedConfig); } - @Test - public void testMandateAPIPublisherElement() { + @Test(expectedExceptions = JAXBException.class) + public void testMandateAPIPublisherElement() throws JAXBException { File malformedConfig = new File( MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG); this.validateMalformedConfig(malformedConfig); } - @Test - public void testMandateAPIsElement() { + @Test(expectedExceptions = JAXBException.class) + public void testMandateAPIsElement() throws JAXBException { File malformedConfig = new File( MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG); this.validateMalformedConfig(malformedConfig); } - @Test - public void testMandateAPIElement() { + @Test(expectedExceptions = JAXBException.class) + public void testMandateAPIElement() throws JAXBException { File malformedConfig = new File( MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG); this.validateMalformedConfig(malformedConfig); } /** - * * Validates a given malformed-configuration file. - * */ - private void validateMalformedConfig(File malformedConfig) { - try { - JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class); - Unmarshaller um = ctx.createUnmarshaller(); - um.setSchema(this.getSchema()); - um.unmarshal(malformedConfig); - Assert.assertTrue(false); - } catch (JAXBException e) { - log.error("Error occurred while unmarsharlling mobile device management config", e); - Assert.assertTrue(true); - } + private void validateMalformedConfig(File malformedConfig) throws JAXBException { + JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class); + Unmarshaller um = ctx.createUnmarshaller(); + um.setSchema(this.getSchema()); + um.unmarshal(malformedConfig); + Assert.assertTrue(false); } private Schema getSchema() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java index 2985ded85..ff8980848 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java @@ -168,7 +168,7 @@ public class MobileFeaturePropertyDAOTestSuite { @Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest", "getFeaturePropertyOfFeatureTest" }, expectedExceptions = MobileDeviceManagementDAOException.class) - public void updateFeaturePropertyTest() throws MobileDeviceManagementDAOException { + public void updateMobileFeaturePropertyTest() throws MobileDeviceManagementDAOException { //Update 1st property to a non-exist feature MobileFeatureProperty mobileFeatureProperty = new MobileFeatureProperty(); mobileFeatureProperty.setFeatureID(2);