Skip to content

Commit

Permalink
Fix Quality Gate issues (SonarSource#1933)
Browse files Browse the repository at this point in the history
  • Loading branch information
joke1196 authored Aug 15, 2024
1 parent 021d4ef commit 4c259cc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.sonar.plugins.python;

import java.util.Objects;
import org.sonar.api.config.Configuration;
import org.sonar.api.resources.AbstractLanguage;

Expand All @@ -41,4 +42,24 @@ public String[] getFileSuffixes() {
String[] suffixes = filterEmptyStrings(configuration.getStringArray(PythonPlugin.IPYNB_FILE_SUFFIXES_KEY));
return suffixes.length == 0 ? DEFAULT_FILE_SUFFIXES : suffixes;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()){
return false;
}
if (!super.equals(o)) {
return false;
}
IPynb iPynb = (IPynb) o;
return Objects.equals(configuration, iPynb.configuration);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.sonar.api.config.internal.MapSettings;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.sonar.plugins.python.PythonPlugin.IPYNB_FILE_SUFFIXES_KEY;

class IPynbTest {
Expand Down Expand Up @@ -53,4 +55,31 @@ void empty_file_suffixes() {
IPynb language = new IPynb(settings.asConfig());
assertThat(language.getFileSuffixes()).hasSize(1).contains("ipynb");
}

@Test
void equals() {
ConfigurationBridge emptyConfig = new ConfigurationBridge(new MapSettings());
IPynb one = new IPynb(emptyConfig);
IPynb other = new IPynb(emptyConfig);
IPynb nullConfig = null;

MapSettings settings = new MapSettings();
settings.setProperty(IPYNB_FILE_SUFFIXES_KEY, "ipynb,my_custom_extension");
IPynb customConfig = new IPynb(settings.asConfig());

assertEquals(one, one);
assertEquals(one, other);
assertNotEquals(one, nullConfig);
assertNotEquals(one, customConfig);
assertNotEquals(one, new Python(new ConfigurationBridge(new MapSettings())));
}

@Test
void hashcode() {
ConfigurationBridge emptyConfig = new ConfigurationBridge(new MapSettings());
IPynb one = new IPynb(emptyConfig);
IPynb other = new IPynb(emptyConfig);
assertEquals(one.hashCode(), other.hashCode());
assertNotEquals(one.hashCode(), "test".hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.event.Level;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
Expand Down

0 comments on commit 4c259cc

Please sign in to comment.