• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.trace.fragment;
17 
18 import com.intellij.util.ui.UIUtil;
19 import ohos.devtools.views.trace.bean.Process;
20 import org.junit.jupiter.api.Assertions;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23 
24 import javax.swing.JPanel;
25 import java.awt.Graphics2D;
26 import java.awt.event.MouseEvent;
27 import java.awt.image.BufferedImage;
28 
29 /**
30  * test ProcessDataFragment class .
31  *
32  * @date 2021/4/24 17:57
33  */
34 class ProcessDataFragmentTest {
35     private ProcessDataFragment processDataFragment;
36     private JPanel jPanel;
37 
38     /**
39      * init the memDataFragment .
40      */
41     @BeforeEach
setUp()42     void setUp() {
43         Process process = new Process();
44         process.setPid(1);
45         jPanel = new JPanel();
46         processDataFragment = new ProcessDataFragment(jPanel, process);
47     }
48 
49     /**
50      * test function the draw .
51      */
52     @Test
draw()53     void draw() {
54         BufferedImage image = UIUtil.createImage(new JPanel(), 1, 1, BufferedImage.TYPE_INT_ARGB);
55         Graphics2D graphics2D = image.createGraphics();
56         processDataFragment.draw(graphics2D);
57         Assertions.assertNotNull(processDataFragment);
58     }
59 
60     /**
61      * test function the mouseClicked .
62      */
63     @Test
mouseClicked()64     void mouseClicked() {
65         MouseEvent mouseEvent = new MouseEvent(jPanel, 1, 1, 1, 1, 1, 1, true, 1);
66         processDataFragment.mouseClicked(mouseEvent);
67         Assertions.assertNotNull(processDataFragment);
68     }
69 
70     /**
71      * test function the mouseMoved .
72      */
73     @Test
mouseMoved()74     void mouseMoved() {
75         MouseEvent mouseEvent = new MouseEvent(jPanel, 1, 1, 1, 1, 1, 1, true, 1);
76         processDataFragment.mouseMoved(mouseEvent);
77         Assertions.assertNotNull(processDataFragment);
78     }
79 
80     /**
81      * test function the click .
82      */
83     @Test
click()84     void click() {
85         MouseEvent mouseEvent = new MouseEvent(jPanel, 1, 1, 1, 1, 1, 1, true, 1);
86         processDataFragment.click(mouseEvent);
87         Assertions.assertNotNull(processDataFragment);
88     }
89 }