Private constructors do not really have to be that defensive.
Remove exception throws and related tests.
Change-Id: I245264a78607d136d92a4c18d68f5d5df17a4832
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
private static final Interner<String> PACKAGE_INTERNER = Interners.newWeakInterner();
private BindingMapping() {
- throw new UnsupportedOperationException("Utility class should not be instantiated");
+ // Hidden on purpose
}
public static @NonNull String getRootPackageName(final QName module) {
});
private BindingReflections() {
- throw new UnsupportedOperationException("Utility class.");
+ // Hidden on purpose
}
/**
new AugmentationReadingStrategy();
private DataObjectReadingUtil() {
- throw new UnsupportedOperationException("Utility class. Instantion is not allowed.");
+ // Hidden on purpose
}
/**
import static com.google.common.collect.ImmutableList.of;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
assertEquals("", BindingMapping.getClassName(""));
}
- @Test(expected = UnsupportedOperationException.class)
- @SuppressWarnings({ "checkstyle:illegalThrows", "checkstyle:avoidHidingCauseException" })
- public void privateConstructTest() throws Throwable {
- final Constructor<BindingMapping> bindingMappingConstructor = BindingMapping.class.getDeclaredConstructor();
- assertFalse(bindingMappingConstructor.isAccessible());
-
- bindingMappingConstructor.setAccessible(true);
- try {
- bindingMappingConstructor.newInstance();
- fail("Expected exception for calling private constructor");
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
-
@Test
public void mapEnumAssignedNamesTest() {
// Okay identifier
import static org.opendaylight.mdsal.binding.spec.reflect.BindingReflections.findHierarchicalParent;
import com.google.common.util.concurrent.ListenableFuture;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
assertEquals(QName.create("test", "test"), BindingReflections.getQName(TestIdentity.class));
}
- @Test(expected = UnsupportedOperationException.class)
- @SuppressWarnings({ "checkstyle:illegalThrows", "checkstyle:avoidHidingCauseException" })
- public void testPrivateConstructor() throws Throwable {
- assertFalse(BindingReflections.class.getDeclaredConstructor().isAccessible());
- final Constructor<?> constructor = BindingReflections.class.getDeclaredConstructor();
- constructor.setAccessible(true);
- try {
- constructor.newInstance();
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
-
- private interface TestIdentity extends BaseIdentity {
- @SuppressWarnings("unused")
+ interface TestIdentity extends BaseIdentity {
QName QNAME = QName.create("test", "test");
}
- private static final class TestImplementation implements Augmentation<TestImplementation>, RpcService {
- @SuppressWarnings("unused")
+ static final class TestImplementation implements Augmentation<TestImplementation>, RpcService {
public static final QName QNAME = QName.create("test", "test");
- @SuppressWarnings({ "unused", "static-method" })
+ @SuppressWarnings("static-method")
ListenableFuture<List<Object>> rpcMethodTest() {
return null;
}
- @SuppressWarnings({ "unused", "static-method" })
+ @SuppressWarnings("static-method")
ListenableFuture<?> rpcMethodTest2() {
return null;
}
*/
package org.opendaylight.mdsal.binding.spec.util;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.UnmodifiableIterator;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Before;
public void testReadDataWithTwoParams() {
readData(mockedDataObject, DataObject.class);
}
-
- @Test(expected = UnsupportedOperationException.class)
- @SuppressWarnings({ "checkstyle:illegalThrows", "checkstyle:avoidHidingCauseException" })
- public void testPrivateConstructor() throws Throwable {
- assertFalse(DataObjectReadingUtil.class.getDeclaredConstructor().isAccessible());
- final Constructor<?> constructor = DataObjectReadingUtil.class.getDeclaredConstructor();
- constructor.setAccessible(true);
- try {
- constructor.newInstance();
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
}
\ No newline at end of file
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public final class ListsBindingUtils {
-
private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
- private ListsBindingUtils() {
- throw new UnsupportedOperationException();
- }
-
public static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
public static final TopLevelListKey TOP_BAR_KEY = new TopLevelListKey("bar");
public static final ListViaUsesKey USES_ONE_KEY = new ListViaUsesKey("one");
public static final ListViaUsesKey USES_TWO_KEY = new ListViaUsesKey("two");
+ private ListsBindingUtils() {
+ // Hidden on purpose
+ }
public static InstanceIdentifier<TopLevelList> path(final TopLevelListKey key) {
return TOP_PATH.child(TopLevelList.class, key);