1+ /*
2+ * The MIT License
3+ *
4+ * Copyright (c) 2024 strangelookingnerd
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+
25+ package com .github .strangelookingnerd ;
26+
27+ import com .intellij .ide .ui .laf .LafManagerImpl ;
28+ import com .intellij .openapi .project .Project ;
29+ import com .intellij .openapi .wm .IdeFrame ;
30+ import com .intellij .openapi .wm .StatusBar ;
31+ import com .intellij .ui .BalloonLayout ;
32+ import org .jetbrains .annotations .NotNull ;
33+ import org .jetbrains .annotations .Nullable ;
34+ import org .junit .jupiter .api .Test ;
35+
36+ import javax .swing .JComponent ;
37+ import javax .swing .UIManager ;
38+ import javax .swing .plaf .metal .MetalProgressBarUI ;
39+ import java .awt .Rectangle ;
40+
41+ import static org .junit .jupiter .api .Assertions .assertEquals ;
42+ import static org .junit .jupiter .api .Assertions .assertNull ;
43+
44+ class PedroProgressBarListenerTest {
45+
46+ @ Test
47+ void testUpdateProgressBar () {
48+ // defaults
49+ assertEquals (MetalProgressBarUI .class .getName (), UIManager .get ("ProgressBarUI" ));
50+ assertNull (UIManager .getDefaults ().get (PedroProgressBarUI .class .getName ()));
51+
52+ // ctor.
53+ PedroProgressBarListener listener = new PedroProgressBarListener ();
54+ assertEquals (PedroProgressBarUI .class .getName (), UIManager .get ("ProgressBarUI" ));
55+ assertEquals (PedroProgressBarUI .class , UIManager .getDefaults ().get (PedroProgressBarUI .class .getName ()));
56+
57+ // reset
58+ UIManager .put ("ProgressBarUI" , null );
59+ UIManager .getDefaults ().remove (PedroProgressBarUI .class .getName ());
60+ assertEquals (MetalProgressBarUI .class .getName (), UIManager .get ("ProgressBarUI" ));
61+ assertNull (UIManager .getDefaults ().get (PedroProgressBarUI .class .getName ()));
62+
63+ // applicationActivated
64+ listener .applicationActivated (new TestFrame ());
65+ assertEquals (PedroProgressBarUI .class .getName (), UIManager .get ("ProgressBarUI" ));
66+ assertEquals (PedroProgressBarUI .class , UIManager .getDefaults ().get (PedroProgressBarUI .class .getName ()));
67+
68+ // reset
69+ UIManager .put ("ProgressBarUI" , null );
70+ UIManager .getDefaults ().remove (PedroProgressBarUI .class .getName ());
71+ assertEquals (MetalProgressBarUI .class .getName (), UIManager .get ("ProgressBarUI" ));
72+ assertNull (UIManager .getDefaults ().get (PedroProgressBarUI .class .getName ()));
73+
74+ // lookAndFeelChanged
75+ listener .lookAndFeelChanged (new LafManagerImpl ());
76+ assertEquals (PedroProgressBarUI .class .getName (), UIManager .get ("ProgressBarUI" ));
77+ assertEquals (PedroProgressBarUI .class , UIManager .getDefaults ().get (PedroProgressBarUI .class .getName ()));
78+ }
79+
80+ private static class TestFrame implements IdeFrame {
81+
82+ @ Override
83+ public @ Nullable StatusBar getStatusBar () {
84+ return null ;
85+ }
86+
87+ @ Override
88+ public @ NotNull Rectangle suggestChildFrameBounds () {
89+ return new Rectangle (0 , 0 , 100 , 100 );
90+ }
91+
92+ @ Override
93+ public @ Nullable Project getProject () {
94+ return null ;
95+ }
96+
97+ @ Override
98+ public void setFrameTitle (String title ) {
99+ // NOP
100+ }
101+
102+ @ Override
103+ public JComponent getComponent () {
104+ return null ;
105+ }
106+
107+ @ Override
108+ public @ Nullable BalloonLayout getBalloonLayout () {
109+ return null ;
110+ }
111+ }
112+
113+ }
0 commit comments