diff options
Diffstat (limited to 'sonar-testing-harness/src')
-rw-r--r-- | sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java index e537466d262..0a5d8fcaef0 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java @@ -23,8 +23,13 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; import java.net.URL; +import static org.fest.assertions.Assertions.assertThat; +import static org.fest.assertions.Fail.fail; + /** * Utilities for unit tests * @@ -67,4 +72,15 @@ public final class TestUtils { resourcePath += path; return getResource(resourcePath); } + + public static void assertPrivateConstructor(Class clazz) { + try { + Constructor constructor = clazz.getDeclaredConstructor(); + assertThat(Modifier.isPrivate(constructor.getModifiers())).isTrue(); + constructor.setAccessible(true); + constructor.newInstance(); + } catch (Exception e) { + fail("Fail to instantiate " + clazz, e); + } + } } |