Skip to content

Commit

Permalink
Merge pull request #13 from strangelookingnerd/tests_and_cleanup
Browse files Browse the repository at this point in the history
Tests and cleanup
  • Loading branch information
strangelookingnerd committed Jun 25, 2024
2 parents 038d6d8 + 1a13231 commit 5df3b69
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Pedro Progress Bar Changelog

## [Unreleased]
### Added
- Do not use deprecated `UIUtil.isUnderWin10LookAndFeel()`
- Plugin description cleanup
- Various dependency updates

## [0.0.2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.intellij.ui.JBColor;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.util.ui.JBInsets;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.UIUtilities;

import javax.swing.ImageIcon;
Expand Down Expand Up @@ -260,9 +259,9 @@ protected int getBoxLength(int availableLength, int otherDimension) {
}

private Shape getShapedRect(float x, float y, float w, float h, float ar) {
boolean flatEnds = UIUtil.isUnderWin10LookAndFeel() || progressBar.getClientProperty(
"ProgressBar.flatEnds") == Boolean.TRUE;
return flatEnds ? new Rectangle2D.Float(x, y, w, h) : new RoundRectangle2D.Float(x, y, w, h, ar, ar);
return progressBar.getClientProperty("ProgressBar.flatEnds") == Boolean.TRUE
? new Rectangle2D.Float(x, y, w, h)
: new RoundRectangle2D.Float(x, y, w, h, ar, ar);
}

private int getStripeWidth() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<idea-plugin url="https://github.com/strangelookingnerd/pedro-progress-bar-plugin">
<id>com.github.strangelookingnerd.pedro-progress-bar</id>
<name>Pedro Progress Bar</name>
<vendor>strangelookingnerd</vendor>
<vendor url="https://strangelookingnerd.github.io">strangelookingnerd</vendor>
<category>User Interface</category>

<depends>com.intellij.modules.platform</depends>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* The MIT License
*
* Copyright (c) 2024 strangelookingnerd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.github.strangelookingnerd;

import com.intellij.ide.ui.laf.LafManagerImpl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.ui.BalloonLayout;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;

import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalProgressBarUI;
import java.awt.Rectangle;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class PedroProgressBarListenerTest {

@Test
void testUpdateProgressBar() {
// defaults
assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));

// ctor.
PedroProgressBarListener listener = new PedroProgressBarListener();
assertEquals(PedroProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
assertEquals(PedroProgressBarUI.class, UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));

// reset
UIManager.put("ProgressBarUI", null);
UIManager.getDefaults().remove(PedroProgressBarUI.class.getName());
assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));

// applicationActivated
listener.applicationActivated(new TestFrame());
assertEquals(PedroProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
assertEquals(PedroProgressBarUI.class, UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));

// reset
UIManager.put("ProgressBarUI", null);
UIManager.getDefaults().remove(PedroProgressBarUI.class.getName());
assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));

// lookAndFeelChanged
listener.lookAndFeelChanged(new LafManagerImpl());
assertEquals(PedroProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
assertEquals(PedroProgressBarUI.class, UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));
}

private static class TestFrame implements IdeFrame {

@Override
public @Nullable StatusBar getStatusBar() {
return null;
}

@Override
public @NotNull Rectangle suggestChildFrameBounds() {
return new Rectangle(0, 0, 100, 100);
}

@Override
public @Nullable Project getProject() {
return null;
}

@Override
public void setFrameTitle(String title) {
// NOP
}

@Override
public JComponent getComponent() {
return null;
}

@Override
public @Nullable BalloonLayout getBalloonLayout() {
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* The MIT License
*
* Copyright (c) 2024 strangelookingnerd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.github.strangelookingnerd;

import org.junit.jupiter.api.Test;

import javax.swing.plaf.ComponentUI;

import static com.intellij.testFramework.UsefulTestCase.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertEquals;

class PedroProgressBarUITest {

@Test
void testCreateUI() {
ComponentUI ui = PedroProgressBarUI.createUI(null);
assertInstanceOf(ui, PedroProgressBarUI.class);
}

@Test
void testGetBoxLength() {
PedroProgressBarUI progressBar = new PedroProgressBarUI();
assertEquals(0, progressBar.getBoxLength(0, 100));
}

}

0 comments on commit 5df3b69

Please sign in to comment.