From 35e15cb5717e5cd868f82097f9f5349d0c95d93a Mon Sep 17 00:00:00 2001 From: Tomasz Linkowski Date: Thu, 7 Mar 2019 16:51:15 +0100 Subject: [PATCH] #21: introduced UniJException --- .../java/pl/tlinkowski/unij/core/UniJ.java | 5 ++-- .../unij/exception/UniJException.java | 30 +++++++++++++++++++ .../pl/tlinkowski/unij/core/UniJSpec.groovy | 4 ++- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 subprojects/unij-core/src/main/java/pl/tlinkowski/unij/exception/UniJException.java diff --git a/subprojects/unij-core/src/main/java/pl/tlinkowski/unij/core/UniJ.java b/subprojects/unij-core/src/main/java/pl/tlinkowski/unij/core/UniJ.java index 61eca1c..e76c9f7 100644 --- a/subprojects/unij-core/src/main/java/pl/tlinkowski/unij/core/UniJ.java +++ b/subprojects/unij-core/src/main/java/pl/tlinkowski/unij/core/UniJ.java @@ -25,6 +25,7 @@ import pl.tlinkowski.unij.annotation.VisibleForTesting; import pl.tlinkowski.unij.core.provider.UnmodifiableListFactory; +import pl.tlinkowski.unij.exception.UniJException; /** * @author Tomasz Linkowski @@ -47,8 +48,8 @@ static T load(Class serviceClass) { private static void validateLoadedServices(Collection services, Class serviceClass) { if (services.isEmpty()) { - throw new IllegalStateException(String.format( - "No %s service found. Ensure proper unij-* module is on the classpath/modulepath", serviceClass + throw new UniJException(String.format( + "No %s service found. Ensure proper unij-* module is on the classpath/modulepath", serviceClass.getName() )); } log.debug("{} service: found {}", serviceClass.getName(), services); diff --git a/subprojects/unij-core/src/main/java/pl/tlinkowski/unij/exception/UniJException.java b/subprojects/unij-core/src/main/java/pl/tlinkowski/unij/exception/UniJException.java new file mode 100644 index 0000000..62dd31c --- /dev/null +++ b/subprojects/unij-core/src/main/java/pl/tlinkowski/unij/exception/UniJException.java @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2019 Tomasz Linkowski. + * + * Licensed 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 pl.tlinkowski.unij.exception; + +/** + * Dedicated unchecked exception for UniJ. + * + * @author Tomasz Linkowski + */ +public class UniJException extends RuntimeException { + + public UniJException(String message) { + super(message); + } +} diff --git a/subprojects/unij-core/src/test/groovy/pl/tlinkowski/unij/core/UniJSpec.groovy b/subprojects/unij-core/src/test/groovy/pl/tlinkowski/unij/core/UniJSpec.groovy index c183ab3..7db49af 100644 --- a/subprojects/unij-core/src/test/groovy/pl/tlinkowski/unij/core/UniJSpec.groovy +++ b/subprojects/unij-core/src/test/groovy/pl/tlinkowski/unij/core/UniJSpec.groovy @@ -20,6 +20,8 @@ package pl.tlinkowski.unij.core import spock.lang.Specification +import pl.tlinkowski.unij.exception.UniJException + /** * @author Tomasz Linkowski */ @@ -29,7 +31,7 @@ class UniJSpec extends Specification { when: UniJ.load(ServiceWithoutImpl) then: - thrown(IllegalStateException) + thrown(UniJException) } private static interface ServiceWithoutImpl {