Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests and cleanup #13

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}

}