1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package ohos.devtools.views.distributed.bean; 17 18 import org.junit.jupiter.api.AfterAll; 19 import org.junit.jupiter.api.BeforeAll; 20 import org.junit.jupiter.api.Test; 21 22 import java.lang.reflect.Field; 23 24 import static org.junit.jupiter.api.Assertions.assertEquals; 25 26 class DistributedParamsTest { 27 private static DistributedParams distributedParams; 28 private static DistributedParams.Builder builder; 29 30 @BeforeAll createBean()31 static void createBean() { 32 builder = new DistributedParams.Builder(); 33 builder.setDeviceNameA("nameA"); 34 builder.setDeviceNameB("nameB"); 35 builder.setPathA("pathA"); 36 builder.setPathB("pathB"); 37 builder.setPkgNameB("PkgNameA"); 38 builder.setPkgNameB("PkgNameB"); 39 builder.setProcessIdA(1); 40 builder.setProcessIdB(2); 41 builder.setOffsetA(1L); 42 builder.setOffsetB(2L); 43 distributedParams = new DistributedParams(builder); 44 } 45 46 @AfterAll end()47 static void end() { 48 distributedParams = null; 49 builder = null; 50 } 51 52 @Test getPkgNameA()53 void getPkgNameA() throws NoSuchFieldException, IllegalAccessException { 54 final Field field = builder.getClass().getDeclaredField("pkgNameA"); 55 field.setAccessible(true); 56 assertEquals(distributedParams.getPkgNameA(), field.get(builder)); 57 } 58 59 @Test getPkgNameB()60 void getPkgNameB() throws NoSuchFieldException, IllegalAccessException { 61 final Field field = builder.getClass().getDeclaredField("pkgNameB"); 62 field.setAccessible(true); 63 assertEquals(distributedParams.getPkgNameB(), field.get(builder)); 64 } 65 66 @Test getProcessIdA()67 void getProcessIdA() throws NoSuchFieldException, IllegalAccessException { 68 final Field field = builder.getClass().getDeclaredField("processIdA"); 69 field.setAccessible(true); 70 assertEquals(distributedParams.getProcessIdA(), field.get(builder)); 71 } 72 73 @Test getProcessIdB()74 void getProcessIdB() throws NoSuchFieldException, IllegalAccessException { 75 final Field field = builder.getClass().getDeclaredField("processIdB"); 76 field.setAccessible(true); 77 assertEquals(distributedParams.getProcessIdB(), field.get(builder)); 78 } 79 80 @Test getDeviceNameA()81 void getDeviceNameA() throws NoSuchFieldException, IllegalAccessException { 82 final Field field = builder.getClass().getDeclaredField("deviceNameA"); 83 field.setAccessible(true); 84 assertEquals(distributedParams.getDeviceNameA(), field.get(builder)); 85 } 86 87 @Test getDeviceNameB()88 void getDeviceNameB() throws NoSuchFieldException, IllegalAccessException { 89 final Field field = builder.getClass().getDeclaredField("deviceNameB"); 90 field.setAccessible(true); 91 assertEquals(distributedParams.getDeviceNameB(), field.get(builder)); 92 } 93 94 @Test getPathA()95 void getPathA() throws NoSuchFieldException, IllegalAccessException { 96 final Field field = builder.getClass().getDeclaredField("pathA"); 97 field.setAccessible(true); 98 assertEquals(distributedParams.getPathA(), field.get(builder)); 99 } 100 101 @Test getPathB()102 void getPathB() throws NoSuchFieldException, IllegalAccessException { 103 final Field field = builder.getClass().getDeclaredField("pathB"); 104 field.setAccessible(true); 105 assertEquals(distributedParams.getPathB(), field.get(builder)); 106 } 107 108 @Test getOffsetA()109 void getOffsetA() throws NoSuchFieldException, IllegalAccessException { 110 final Field field = builder.getClass().getDeclaredField("offsetA"); 111 field.setAccessible(true); 112 assertEquals(distributedParams.getOffsetA(), field.get(builder)); 113 } 114 115 @Test getOffsetB()116 void getOffsetB() throws NoSuchFieldException, IllegalAccessException { 117 final Field field = builder.getClass().getDeclaredField("offsetB"); 118 field.setAccessible(true); 119 assertEquals(distributedParams.getOffsetB(), field.get(builder)); 120 } 121 }