| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| CreateInstanceByDefaultConstructor |
|
| 4.0;4 |
| 1 | package org.jbehave.core.steps.needle.configuration; | |
| 2 | ||
| 3 | /** | |
| 4 | * Instantiates new java object by default constructor | |
| 5 | * @author Jan Galinski, Holisticon AG (jan.galinski@holisticon.de) | |
| 6 | * @author Simon Zambrovski, Holisticon AG (simon.zambrovski@holisticon.de) | |
| 7 | */ | |
| 8 | 2 | public enum CreateInstanceByDefaultConstructor { |
| 9 | ||
| 10 | /** | |
| 11 | * Singleton | |
| 12 | */ | |
| 13 | 1 | INSTANCE; |
| 14 | ||
| 15 | public final <T> T apply(final Class<T> type) { | |
| 16 | try { | |
| 17 | 12 | final T newInstance = type.getConstructor().newInstance(); |
| 18 | 12 | return newInstance; |
| 19 | 0 | } catch (final Exception e) { |
| 20 | 0 | throw new IllegalStateException(String.format("Can not instantiate instance of %s by default constructor.", type.getSimpleName()), e); |
| 21 | } | |
| 22 | } | |
| 23 | ||
| 24 | } |