From 1a51c3a5a563911402431ebb3925e754191bc153 Mon Sep 17 00:00:00 2001 From: Adrien LAUER Date: Wed, 22 Apr 2015 17:16:47 +0200 Subject: [PATCH] Remove assertions from core, confine assertj in test scope --- core-support/core/pom.xml | 4 - .../assertions/CoreAssertionsErrorCode.java | 27 ---- .../seed/core/assertions/CoreClassAssert.java | 115 ------------------ .../core/assertions/CoreObjectAssert.java | 85 ------------- .../core/utils}/BindingDefinitionsAssert.java | 4 +- .../seed/core/utils/SeedBindingUtilsTest.java | 1 - .../org/seedstack/seed/it/SeedITRunner.java | 4 +- .../it/{internal => api}/ITErrorCode.java | 5 +- .../helper => test}/AbstractSeedTest.java | 2 +- .../helper => test/rule}/MockitoRule.java | 2 +- 10 files changed, 9 insertions(+), 240 deletions(-) delete mode 100644 core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreAssertionsErrorCode.java delete mode 100644 core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreClassAssert.java delete mode 100644 core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreObjectAssert.java rename core-support/core/src/{main/java/org/seedstack/seed/core/assertions => test/java/org/seedstack/seed/core/utils}/BindingDefinitionsAssert.java (95%) rename integrationtest-support/core/src/main/java/org/seedstack/seed/it/{internal => api}/ITErrorCode.java (86%) rename unittest-support/src/main/java/org/seedstack/seed/{unittest/helper => test}/AbstractSeedTest.java (93%) rename unittest-support/src/main/java/org/seedstack/seed/{unittest/helper => test/rule}/MockitoRule.java (96%) diff --git a/core-support/core/pom.xml b/core-support/core/pom.xml index b75281a31..68dd02a63 100644 --- a/core-support/core/pom.xml +++ b/core-support/core/pom.xml @@ -54,10 +54,6 @@ com.fasterxml.jackson.core jackson-databind - - org.assertj - assertj-core - org.json json diff --git a/core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreAssertionsErrorCode.java b/core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreAssertionsErrorCode.java deleted file mode 100644 index bc2727ee6..000000000 --- a/core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreAssertionsErrorCode.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved. - * - * This file is part of SeedStack, An enterprise-oriented full development stack. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.seedstack.seed.core.assertions; - -import org.seedstack.seed.core.api.ErrorCode; - -/** - * SEED core assertions error codes. - * - * @author epo.jemba@ext.mpsa.com - * @author pierre.thirouin@ext.mpsa.com - */ -enum CoreAssertionsErrorCode implements ErrorCode { - UNEXPECTED_EXCEPTION, - CLASS_IS_NOT_INJECTABLE, - CLASS_IS_NOT_INJECTED_WITH, - BAD_PROPERTY_VALUE, - OBJECT_IS_NULL, - METHOD_DOES_NOT_EXIST -} diff --git a/core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreClassAssert.java b/core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreClassAssert.java deleted file mode 100644 index e156cfda9..000000000 --- a/core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreClassAssert.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved. - * - * This file is part of SeedStack, An enterprise-oriented full development stack. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.seedstack.seed.core.assertions; - -import com.google.inject.Injector; -import org.seedstack.seed.core.api.SeedException; -import org.assertj.core.api.AbstractClassAssert; -import org.seedstack.seed.core.utils.SeedReflectionUtils; - -import javax.inject.Inject; -import java.lang.reflect.Method; - -/** - * This assertion class provides assertions around classes. - * - * @param the assertion type. - * @author epo.jemba@ext.mpsa.com - */ -public class CoreClassAssert> extends AbstractClassAssert { - @Inject - private static Injector injector; - - /** - * Creates the assertion with the specified types. - * - * @param actual the class to test - * @param selfType the self type of this assertion class ({@link AbstractClassAssert} - */ - protected CoreClassAssert(Class actual, Class selfType) { - super(actual, selfType); - } - - /** - * Checks if the class is injectable. - * - * @return itself - */ - public S isInjectable() { - try { - injector.getInstance(actual); - } catch (Exception e) { - throw SeedException - .wrap(e, CoreAssertionsErrorCode.CLASS_IS_NOT_INJECTABLE) - .put("className", actual.getName()) - .put("more", "\n" + e.getMessage()); - } - - return myself; - } - - /** - * Checks if the class is injected with an instance assignable to the specified class. - * - * @param candidate the class to test for assignation - * @return itself - */ - public S isInjectedWithInstanceOf(Class candidate) { - Object injectee; - - try { - injectee = injector.getInstance(actual); - } catch (Exception e) { - throw SeedException - .wrap(e, CoreAssertionsErrorCode.CLASS_IS_NOT_INJECTABLE) - .put("className", actual.getName()) - .put("more", "\n" + e.getMessage()); - } - - SeedException - .createNew(CoreAssertionsErrorCode.CLASS_IS_NOT_INJECTED_WITH) - .put("className", actual.getName()) - .put("injectee", candidate.getName()) - .put("actual", injectee.getClass().getName()) - .throwsIf(!injectee.getClass().equals(candidate) && !candidate.isAssignableFrom(injectee.getClass())); - - return myself; - } - - /** - * Checks if the class has the specified method. - * - * @param expectedMethodName the method name to check for. - * @return itself. - */ - public S hasDeclaredMethod(String expectedMethodName) { - Class actualClass = SeedReflectionUtils.cleanProxy(actual); - boolean found = false; - - try { - for (Method method : actualClass.getDeclaredMethods()) { - if (found = method.getName().equals(expectedMethodName)) { - break; - } - } - } catch (Exception e) { - throw SeedException.wrap(e, CoreAssertionsErrorCode.METHOD_DOES_NOT_EXIST) - .put("methodName", expectedMethodName) - .put("className", actualClass.getName()); - } - - SeedException.createNew(CoreAssertionsErrorCode.METHOD_DOES_NOT_EXIST) - .put("methodName", expectedMethodName) - .put("className", actualClass.getName()) - .throwsIf(!found); - - return myself; - } -} diff --git a/core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreObjectAssert.java b/core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreObjectAssert.java deleted file mode 100644 index 42cbf7ee2..000000000 --- a/core-support/core/src/main/java/org/seedstack/seed/core/assertions/CoreObjectAssert.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved. - * - * This file is part of SeedStack, An enterprise-oriented full development stack. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.seedstack.seed.core.assertions; - -import com.google.common.base.Objects; -import org.seedstack.seed.core.api.SeedException; -import org.assertj.core.api.AbstractObjectAssert; -import org.seedstack.seed.core.utils.SeedReflectionUtils; - -import java.lang.reflect.Method; - -/** - * This assertion class provides assertions around instances. - * - * @param the type of the asserted object. - * @author epo.jemba@ext.mpsa.com - */ -public class CoreObjectAssert extends AbstractObjectAssert, A> { - - /** - * Creates the assertion with the specified instance. - * - * @param actual the instance to test - */ - public CoreObjectAssert(A actual) { - super(actual, CoreObjectAssert.class); - } - - /** - * Check if a property exists and if it equals to expectedValue. - * - * @param propertyName the property name to check for - * @param expectedValue the expected value - * @return itself - */ - public CoreObjectAssert propertyEquals(String propertyName, Object expectedValue) { - Method method; - Object returnedObject; - String computedMethodName = null; - Class actualClass = SeedReflectionUtils.cleanProxy(actual.getClass()); - - // reach method - try { - computedMethodName = "get" + propertyName.substring(0, 1).toUpperCase(); - if (computedMethodName.length() > 1) { - computedMethodName += propertyName.substring(1); - } - - method = actualClass.getMethod(computedMethodName); - } catch (Exception e) { - throw SeedException.wrap(e, CoreAssertionsErrorCode.UNEXPECTED_EXCEPTION) - .put("more", String.format("The method [%s] does not exists in class [%s]", computedMethodName, actualClass)); - } - - // call the method - try { - returnedObject = method.invoke(actual); - } catch (Exception e) { - throw SeedException.wrap(e, CoreAssertionsErrorCode.UNEXPECTED_EXCEPTION) - .put("more", String.format("The method [%s] on object [%s] can not be executed.", computedMethodName, actual)); - } - - SeedException.createNew(CoreAssertionsErrorCode.BAD_PROPERTY_VALUE) - .put("property", propertyName) - .put("expectedValue", expectedValue) - .put("actualValue", returnedObject) - .throwsIf(!Objects.equal(expectedValue, returnedObject)); - - return myself; - } - - @Override - public CoreObjectAssert isNotNull() { - SeedException.createNew(CoreAssertionsErrorCode.OBJECT_IS_NULL).throwsIfNull(actual); - return myself; - } - -} diff --git a/core-support/core/src/main/java/org/seedstack/seed/core/assertions/BindingDefinitionsAssert.java b/core-support/core/src/test/java/org/seedstack/seed/core/utils/BindingDefinitionsAssert.java similarity index 95% rename from core-support/core/src/main/java/org/seedstack/seed/core/assertions/BindingDefinitionsAssert.java rename to core-support/core/src/test/java/org/seedstack/seed/core/utils/BindingDefinitionsAssert.java index 9179d6a44..d94f8452a 100644 --- a/core-support/core/src/main/java/org/seedstack/seed/core/assertions/BindingDefinitionsAssert.java +++ b/core-support/core/src/test/java/org/seedstack/seed/core/utils/BindingDefinitionsAssert.java @@ -7,7 +7,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.seedstack.seed.core.assertions; +package org.seedstack.seed.core.utils; import com.google.inject.Key; import org.assertj.core.api.Assertions; @@ -17,7 +17,7 @@ import static org.seedstack.seed.core.utils.SeedBindingUtils.resolveBindingDefinitions; /** - * This assertion class provides assertions around types. + * This assertion class provides assertions around bindings. * * @author pierre.thirouin@ext.mpsa.com */ diff --git a/core-support/core/src/test/java/org/seedstack/seed/core/utils/SeedBindingUtilsTest.java b/core-support/core/src/test/java/org/seedstack/seed/core/utils/SeedBindingUtilsTest.java index 899b57005..6826c80fe 100644 --- a/core-support/core/src/test/java/org/seedstack/seed/core/utils/SeedBindingUtilsTest.java +++ b/core-support/core/src/test/java/org/seedstack/seed/core/utils/SeedBindingUtilsTest.java @@ -16,7 +16,6 @@ import com.google.inject.TypeLiteral; import org.seedstack.seed.core.api.SeedException; import org.junit.Test; -import org.seedstack.seed.core.assertions.BindingDefinitionsAssert; import org.seedstack.seed.core.utils.sample.*; import static org.seedstack.seed.core.utils.SeedBindingUtils.resolveBindingDefinitions; diff --git a/integrationtest-support/core/src/main/java/org/seedstack/seed/it/SeedITRunner.java b/integrationtest-support/core/src/main/java/org/seedstack/seed/it/SeedITRunner.java index 89bcd4f52..a3f2aefb0 100644 --- a/integrationtest-support/core/src/main/java/org/seedstack/seed/it/SeedITRunner.java +++ b/integrationtest-support/core/src/main/java/org/seedstack/seed/it/SeedITRunner.java @@ -18,7 +18,7 @@ import org.seedstack.seed.it.api.Expect; import org.seedstack.seed.it.api.WithPlugins; import org.seedstack.seed.it.api.WithoutSpiPluginsLoader; -import org.seedstack.seed.it.internal.ITErrorCode; +import org.seedstack.seed.it.api.ITErrorCode; import org.seedstack.seed.it.internal.ITPlugin; import org.seedstack.seed.it.spi.ITKernelMode; import org.seedstack.seed.it.spi.ITRunnerPlugin; @@ -346,7 +346,7 @@ private void processException(Exception e) { if (unwrappedThrowable == null) { throw SeedException.createNew(ITErrorCode.EXPECTED_EXCEPTION_DID_NOT_OCCURRED).put("expectedClass", expectedClass); } else if (!unwrappedThrowable.getClass().equals(expectedClass)) { - throw SeedException.createNew(ITErrorCode.ANOTHER_EXCEPTION_THAN_EXPECTED_OCCURED).put("expectedClass", expectedClass).put("occurredClass", unwrappedThrowable.getClass()); + throw SeedException.createNew(ITErrorCode.ANOTHER_EXCEPTION_THAN_EXPECTED_OCCURRED).put("expectedClass", expectedClass).put("occurredClass", unwrappedThrowable.getClass()); } } } diff --git a/integrationtest-support/core/src/main/java/org/seedstack/seed/it/internal/ITErrorCode.java b/integrationtest-support/core/src/main/java/org/seedstack/seed/it/api/ITErrorCode.java similarity index 86% rename from integrationtest-support/core/src/main/java/org/seedstack/seed/it/internal/ITErrorCode.java rename to integrationtest-support/core/src/main/java/org/seedstack/seed/it/api/ITErrorCode.java index f0f7832cc..c0f4a3b77 100644 --- a/integrationtest-support/core/src/main/java/org/seedstack/seed/it/internal/ITErrorCode.java +++ b/integrationtest-support/core/src/main/java/org/seedstack/seed/it/api/ITErrorCode.java @@ -7,7 +7,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.seedstack.seed.it.internal; +package org.seedstack.seed.it.api; import org.seedstack.seed.core.api.ErrorCode; @@ -22,5 +22,6 @@ public enum ITErrorCode implements ErrorCode { TEST_PLUGINS_MISMATCH, UNEXPECTED_EXCEPTION_OCCURRED, EXPECTED_EXCEPTION_DID_NOT_OCCURRED, - ANOTHER_EXCEPTION_THAN_EXPECTED_OCCURED, FAILED_TO_INITIALIZE_KERNEL + ANOTHER_EXCEPTION_THAN_EXPECTED_OCCURRED, + FAILED_TO_INITIALIZE_KERNEL } diff --git a/unittest-support/src/main/java/org/seedstack/seed/unittest/helper/AbstractSeedTest.java b/unittest-support/src/main/java/org/seedstack/seed/test/AbstractSeedTest.java similarity index 93% rename from unittest-support/src/main/java/org/seedstack/seed/unittest/helper/AbstractSeedTest.java rename to unittest-support/src/main/java/org/seedstack/seed/test/AbstractSeedTest.java index 8965e7551..65ca0e420 100644 --- a/unittest-support/src/main/java/org/seedstack/seed/unittest/helper/AbstractSeedTest.java +++ b/unittest-support/src/main/java/org/seedstack/seed/test/AbstractSeedTest.java @@ -13,7 +13,7 @@ /** * */ -package org.seedstack.seed.unittest.helper; +package org.seedstack.seed.test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; diff --git a/unittest-support/src/main/java/org/seedstack/seed/unittest/helper/MockitoRule.java b/unittest-support/src/main/java/org/seedstack/seed/test/rule/MockitoRule.java similarity index 96% rename from unittest-support/src/main/java/org/seedstack/seed/unittest/helper/MockitoRule.java rename to unittest-support/src/main/java/org/seedstack/seed/test/rule/MockitoRule.java index 06ed54eea..dc5195a3d 100644 --- a/unittest-support/src/main/java/org/seedstack/seed/unittest/helper/MockitoRule.java +++ b/unittest-support/src/main/java/org/seedstack/seed/test/rule/MockitoRule.java @@ -7,7 +7,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.seedstack.seed.unittest.helper; +package org.seedstack.seed.test.rule; import org.junit.rules.TestRule; import org.junit.runner.Description;