Skip to content
Permalink
Browse files

remove deprecated API usages

  • Loading branch information
guymahieu committed Feb 9, 2020
1 parent 0d4b492 commit a089c685e531891da9477d12ad4940237632e7ff
@@ -19,6 +19,7 @@ dependencies {
implementation group: 'org.apache.ivy', name: 'ivy', version: '2.5.0'

testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.15.0'
}

// See https://github.com/JetBrains/gradle-intellij-plugin/

This file was deleted.

@@ -16,7 +16,8 @@

package org.clarent.ivyidea.config.ui.propertieseditor;

import com.intellij.util.ui.Table;
import com.intellij.ui.table.JBTable;
import org.jetbrains.annotations.NotNull;

import javax.swing.table.TableModel;

@@ -26,14 +27,14 @@
*
* @author Guy Mahieu
*/
public class PropertiesTable extends Table {
public class PropertiesTable extends JBTable {

public PropertiesTable() {
super(new PropertiesTableModel());
initComponents();
}

public void setModel(TableModel dataModel) {
public void setModel(@NotNull TableModel dataModel) {
super.setModel(dataModel);
initComponents();
}
@@ -48,47 +49,6 @@ private void initComponents() {

getColumnModel().getColumn(0).setHeaderValue("Name");
getColumnModel().getColumn(1).setHeaderValue("Value");

// Register custom renderer to draw deprecated configs in 'strikethrough'
// getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
//
// private Font regularFont;
// private Font strikethroughFont;
//
// public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// final ConfigurationSelectionTableModel tableModel = (ConfigurationSelectionTableModel) table.getModel();
// final Component rendererComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
// if (regularFont == null) {
// regularFont = rendererComponent.getFont();
// }
//// final int modelIndex = table.convertRowIndexToModel(row); // JDK 1.6 - if table sorting is enabled
// final Configuration configuration = tableModel.getConfigurationAt(row);
// if (configuration.getDeprecated() != null) {
// if (strikethroughFont == null) {
// final HashMap<TextAttribute, Object> attribs = new HashMap<TextAttribute, Object>();
// attribs.put(TextAttribute.STRIKETHROUGH, Boolean.TRUE);
// strikethroughFont = regularFont.deriveFont(attribs);
// }
// setToolTipText("Depracated: " + configuration.getDeprecated());
// rendererComponent.setFont(strikethroughFont);
// } else {
// setToolTipText(null);
// rendererComponent.setFont(regularFont);
// }
// rendererComponent.setEnabled(table.isEnabled());
// return rendererComponent;
// }
// });
//
// // Render description disabled if table is disabled
// getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {
// public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// final Component rendererComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
// rendererComponent.setEnabled(table.isEnabled());
// return rendererComponent;
// }
// });

}

}
@@ -145,15 +145,14 @@ public void readExternal(Element element) throws InvalidDataException {

private void readBasicSettings(Element element) {
setIvyFile(element.getAttributeValue("ivyFile", ""));
setUseCustomIvySettings(Boolean.valueOf(element.getAttributeValue("useCustomIvySettings", Boolean.TRUE.toString())));
setUseCustomIvySettings(Boolean.parseBoolean(element.getAttributeValue("useCustomIvySettings", Boolean.TRUE.toString())));
setIvySettingsFile(element.getAttributeValue("ivySettingsFile", ""));
setOnlyResolveSelectedConfigs(Boolean.valueOf(element.getAttributeValue("onlyResolveSelectedConfigs", Boolean.FALSE.toString())));
setUseProjectSettings(Boolean.valueOf(element.getAttributeValue("useProjectSettings", Boolean.TRUE.toString())));
setOnlyResolveSelectedConfigs(Boolean.parseBoolean(element.getAttributeValue("onlyResolveSelectedConfigs", Boolean.FALSE.toString())));
setUseProjectSettings(Boolean.parseBoolean(element.getAttributeValue("useProjectSettings", Boolean.TRUE.toString())));
final Element configsToResolveElement = element.getChild("configsToResolve");
if (configsToResolveElement != null) {
Set<String> configsToResolve = new TreeSet<String>();
@SuppressWarnings("unchecked")
final List<Element> configElements = (List<Element>) configsToResolveElement.getChildren("config");
Set<String> configsToResolve = new TreeSet<>();
final List<Element> configElements = configsToResolveElement.getChildren("config");
for (Element configElement : configElements) {
configsToResolve.add(configElement.getTextTrim());
}
@@ -20,6 +20,7 @@
import com.intellij.ui.BooleanTableCellRenderer;
import com.intellij.ui.table.JBTable;
import org.apache.ivy.core.module.descriptor.Configuration;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
@@ -45,7 +46,7 @@ public ConfigurationSelectionTable() {
initComponents();
}

public void setModel(TableModel dataModel) {
public void setModel(@NotNull TableModel dataModel) {
super.setModel(dataModel);
((ConfigurationSelectionTableModel) dataModel).setEditable(editable);
initComponents();
@@ -99,11 +100,10 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
if (regularFont == null) {
regularFont = rendererComponent.getFont();
}
// final int modelIndex = table.convertRowIndexToModel(row); // JDK 1.6 - if table sorting is enabled
final Configuration configuration = tableModel.getConfigurationAt(row);
if (configuration.getDeprecated() != null) {
if (strikethroughFont == null) {
final HashMap<TextAttribute, Object> attribs = new HashMap<TextAttribute, Object>();
final HashMap<TextAttribute, Object> attribs = new HashMap<>();
attribs.put(TextAttribute.STRIKETHROUGH, Boolean.TRUE);
strikethroughFont = regularFont.deriveFont(attribs);
}
@@ -50,7 +50,6 @@
</group>
</actions>
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceImplementation="org.clarent.ivyidea.IvyIdeaPlugin"/>

<projectService serviceImplementation="org.clarent.ivyidea.intellij.IvyIdeaProjectComponent" />
<projectService serviceImplementation="org.clarent.ivyidea.intellij.IvyIdeaConsoleService" />
@@ -16,83 +16,83 @@

package org.clarent.ivyidea.config.model;

import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.clarent.ivyidea.config.model.ArtifactTypeSettings.DependencyCategory.Classes;

/**
* @author Guy Mahieu
*/
public class ArtifactTypeSettingsTest extends TestCase {
public class ArtifactTypeSettingsTest {

@Test
public void testNewObjectAlwaysEmpty() {
Assert.assertTrue(new ArtifactTypeSettings().isConfigurationEmpty());
assertThat(new ArtifactTypeSettings().isConfigurationEmpty()).isTrue();
}

@Test
public void testObjectWithOnlyEmptyStringsAlwaysEmpty() {
final ArtifactTypeSettings artifactTypeSettings = new ArtifactTypeSettings();
artifactTypeSettings.setClassesTypes("");
Assert.assertTrue(artifactTypeSettings.isConfigurationEmpty());
assertThat(artifactTypeSettings.isConfigurationEmpty()).isTrue();
}

@Test
public void testObjectWithDataNeverEmpty() {
final ArtifactTypeSettings typeSettings = new ArtifactTypeSettings();
typeSettings.setTypesForCategory(Classes, "jar");
Assert.assertFalse(typeSettings.isConfigurationEmpty());
assertThat(typeSettings.isConfigurationEmpty()).isFalse();
}

@Test
public void testTypeNamesAreCaseInsensitive() {
final ArtifactTypeSettings typeSettings = new ArtifactTypeSettings();
typeSettings.setTypesForCategory(Classes, "JAR");
Assert.assertEquals(Classes, typeSettings.getCategoryForType("jar"));
assertThat(typeSettings.getCategoryForType("jar")).isSameAs(Classes);
}

@Test
public void testCorrectCategoryReturnedForType() {
final ArtifactTypeSettings typeSettings = new ArtifactTypeSettings();
typeSettings.setTypesForCategory(Classes, "jar");
Assert.assertEquals(Classes, typeSettings.getCategoryForType("jar"));
Assert.assertEquals(Classes, typeSettings.getCategoryForType("jar "));
Assert.assertEquals(Classes, typeSettings.getCategoryForType(" jar"));
Assert.assertEquals(Classes, typeSettings.getCategoryForType(" jar "));
assertThat(typeSettings.getCategoryForType("jar")).isSameAs(Classes);
assertThat(typeSettings.getCategoryForType(" jar")).isSameAs(Classes);
assertThat(typeSettings.getCategoryForType("jar ")).isSameAs(Classes);
assertThat(typeSettings.getCategoryForType(" jar ")).isSameAs(Classes);
}

@Test
public void testOrderOfTypesPreservedWhenSettingAndGetting() {
final ArtifactTypeSettings typeSettings = new ArtifactTypeSettings();
final String expected = "a, b, c, d, e, f, g";
typeSettings.setTypesForCategory(Classes, expected);
final String actual = typeSettings.getTypesStringForCategory(Classes);
Assert.assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

@Test
public void testNullForUnknownType() {
final ArtifactTypeSettings typeSettings = new ArtifactTypeSettings();
typeSettings.setTypesForCategory(Classes, "jar");
Assert.assertNull(typeSettings.getCategoryForType("foo"));
assertThat(typeSettings.getCategoryForType("foo")).isNull();
}

@Test
public void testSerializationGettersDoNotReturnDefaultValuesIfObjectEmpty() {
final ArtifactTypeSettings typeSettings = new ArtifactTypeSettings();
Assert.assertEquals("", typeSettings.getClassesTypes());
Assert.assertEquals("", typeSettings.getSourcesTypes());
Assert.assertEquals("", typeSettings.getJavadocTypes());
assertThat(typeSettings.getClassesTypes()).isEmpty();
assertThat(typeSettings.getSourcesTypes()).isEmpty();
assertThat(typeSettings.getJavadocTypes()).isEmpty();
}

@Test
public void testGetTypeStringReturnsDefaultValuesIfObjectEmpty() {
final ArtifactTypeSettings typeSettings = new ArtifactTypeSettings();
for (ArtifactTypeSettings.DependencyCategory category : ArtifactTypeSettings.DependencyCategory.values()) {
final String typesStringForCategory = typeSettings.getTypesStringForCategory(category);
Assert.assertNotNull(typesStringForCategory);
Assert.assertTrue(typesStringForCategory.length() > 0);
assertThat(typesStringForCategory).isNotNull();
assertThat(typesStringForCategory.length() > 0).isTrue();
}
}

@@ -18,7 +18,8 @@

import org.junit.Test;

import static junit.framework.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.clarent.ivyidea.logging.IvyLogLevel.Error;
import static org.clarent.ivyidea.logging.IvyLogLevel.*;

/**
@@ -28,8 +29,8 @@

@Test
public void test_isMoreVerboseThan() {
assertTrue(Error.isMoreVerboseThan(None));
assertTrue(Info.isMoreVerboseThan(None));
assertFalse(Error.isMoreVerboseThan(Debug));
assertThat(Error.isMoreVerboseThan(None)).isTrue();
assertThat(Info.isMoreVerboseThan(None)).isTrue();
assertThat(Error.isMoreVerboseThan(Debug)).isFalse();
}
}

0 comments on commit a089c68

Please sign in to comment.
You can’t perform that action at this time.