2021-02-01 14:31:20 +09:00
|
|
|
/*
|
|
|
|
|
* ******************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* *
|
|
|
|
|
* * This program and the accompanying materials are made available under the
|
|
|
|
|
* * terms of the Apache License, Version 2.0 which is available at
|
|
|
|
|
* * https://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
|
* *
|
2021-02-01 17:47:29 +09:00
|
|
|
* * See the NOTICE file distributed with this work for additional
|
|
|
|
|
* * information regarding copyright ownership.
|
2021-02-01 14:31:20 +09:00
|
|
|
* * 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.
|
|
|
|
|
* *
|
|
|
|
|
* * SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
* *****************************************************************************
|
|
|
|
|
*/
|
2022-09-20 15:40:53 +02:00
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
package org.deeplearning4j.common.config;
|
|
|
|
|
|
2021-03-15 13:02:01 +09:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
2022-09-20 15:40:53 +02:00
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
import org.deeplearning4j.common.config.dummies.TestAbstract;
|
2021-03-15 13:02:01 +09:00
|
|
|
import org.junit.jupiter.api.Test;
|
2020-10-29 06:38:42 -07:00
|
|
|
|
2022-09-20 15:40:53 +02:00
|
|
|
public class DL4JClassLoadingTest {
|
2020-10-29 06:38:42 -07:00
|
|
|
private static final String PACKAGE_PREFIX = "org.deeplearning4j.common.config.dummies.";
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-09-20 15:40:53 +02:00
|
|
|
public void testCreateNewInstance_constructorWithoutArguments() {
|
|
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
/* Given */
|
|
|
|
|
String className = PACKAGE_PREFIX + "TestDummy";
|
2022-09-20 15:40:53 +02:00
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
/* When */
|
|
|
|
|
Object instance = DL4JClassLoading.createNewInstance(className);
|
2022-09-20 15:40:53 +02:00
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
/* Then */
|
|
|
|
|
assertNotNull(instance);
|
|
|
|
|
assertEquals(className, instance.getClass().getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-09-20 15:40:53 +02:00
|
|
|
public void testCreateNewInstance_constructorWithArgument_implicitArgumentTypes() {
|
|
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
/* Given */
|
|
|
|
|
String className = PACKAGE_PREFIX + "TestColor";
|
2022-09-20 15:40:53 +02:00
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
/* When */
|
|
|
|
|
TestAbstract instance = DL4JClassLoading.createNewInstance(className, TestAbstract.class, "white");
|
2022-09-20 15:40:53 +02:00
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
/* Then */
|
|
|
|
|
assertNotNull(instance);
|
|
|
|
|
assertEquals(className, instance.getClass().getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-09-20 15:40:53 +02:00
|
|
|
public void testCreateNewInstance_constructorWithArgument_explicitArgumentTypes() {
|
|
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
/* Given */
|
|
|
|
|
String colorClassName = PACKAGE_PREFIX + "TestColor";
|
|
|
|
|
String rectangleClassName = PACKAGE_PREFIX + "TestRectangle";
|
2022-09-20 15:40:53 +02:00
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
/* When */
|
2022-09-20 15:40:53 +02:00
|
|
|
TestAbstract color = DL4JClassLoading.createNewInstance(
|
|
|
|
|
colorClassName,
|
|
|
|
|
Object.class,
|
|
|
|
|
new Class<?>[]{ int.class, int.class, int.class },
|
|
|
|
|
45, 175, 200);
|
|
|
|
|
|
|
|
|
|
TestAbstract rectangle = DL4JClassLoading.createNewInstance(
|
|
|
|
|
rectangleClassName,
|
|
|
|
|
Object.class,
|
|
|
|
|
new Class<?>[]{ int.class, int.class, TestAbstract.class },
|
|
|
|
|
10, 15, color);
|
|
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
/* Then */
|
|
|
|
|
assertNotNull(color);
|
|
|
|
|
assertEquals(colorClassName, color.getClass().getName());
|
2022-09-20 15:40:53 +02:00
|
|
|
|
2020-10-29 06:38:42 -07:00
|
|
|
assertNotNull(rectangle);
|
|
|
|
|
assertEquals(rectangleClassName, rectangle.getClass().getName());
|
|
|
|
|
}
|
|
|
|
|
}
|