diff --git a/entry/src/ohosTest/java/com/lijiankun24/shadowlayoutexample/ExampleOhosTest.java b/entry/src/ohosTest/java/com/lijiankun24/shadowlayoutexample/ExampleOhosTest.java index e87822aafe0ecf06864936998671286156d49ad3..30a2e233cf1ed2deb48498166dd0fb581cf40cf7 100644 --- a/entry/src/ohosTest/java/com/lijiankun24/shadowlayoutexample/ExampleOhosTest.java +++ b/entry/src/ohosTest/java/com/lijiankun24/shadowlayoutexample/ExampleOhosTest.java @@ -18,6 +18,9 @@ package com.lijiankun24.shadowlayoutexample; import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; import org.junit.Test; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + import static org.junit.Assert.assertEquals; /** @@ -35,4 +38,74 @@ public class ExampleOhosTest { final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); assertEquals("com.lijiankun24.shadowlayoutexample", actualBundleName); } + + /** + * test加 + */ + @Test + public void testAdd(){ + try { + Class numberUtil = Class.forName("com.lijiankun24.shadowlayout.NumberUtil"); + Method add = numberUtil.getMethod("add", double.class, double.class); + Object obj = numberUtil.getConstructor().newInstance(); + int invoke = (int) add.invoke(obj,1.0,1.0); + assertEquals(2,invoke); + } catch (InstantiationException | InvocationTargetException | + NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + /** + * test减 + */ + @Test + public void testSub(){ + try { + Class numberUtil = Class.forName("com.lijiankun24.shadowlayout.NumberUtil"); + Method sub = numberUtil.getMethod("sub", double.class, double.class); + Object obj = numberUtil.getConstructor().newInstance(); + int invoke = (int) sub.invoke(obj,2.0,1.0); + assertEquals(1,invoke); + } catch (InstantiationException | InvocationTargetException | + NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + /** + * test乘 + */ + @Test + public void testMul(){ + try { + Class numberUtil = Class.forName("com.wuhenzhizao.sku.utils.NumberUtil"); + Method mul = numberUtil.getMethod("mul", double.class, double.class); + Object object = numberUtil.getConstructor().newInstance(); + int invoke = (int) mul.invoke(object, 1, 2); + assertEquals(2,invoke); + } catch (InstantiationException | InvocationTargetException | + NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + /** + * test除 + */ + @Test + public void testDiv(){ + try { + Class numberUtil = Class.forName("com.wuhenzhizao.sku.utils.NumberUtil"); + Method div = numberUtil.getMethod("div", double.class, double.class); + Object object = numberUtil.getConstructor().newInstance(); + int invoke = (int) div.invoke(object, 2, 2); + assertEquals(1,invoke); + } catch (InstantiationException | InvocationTargetException | + NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + } \ No newline at end of file