Test xml keys are unique

This commit is contained in:
Clément Fournier
2017-09-08 19:30:34 +02:00
parent dfb6bd4d50
commit e993a7bf21
6 changed files with 54 additions and 11 deletions

View File

@ -36,5 +36,10 @@
<artifactId>pmd-apex</artifactId>
<version>6.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -44,7 +44,7 @@ import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
/**
* Presenter of the designer window.
* Presenter of the designer window. Subscribes to the events of the {@link DesignerWindow} that instantiates it.
*
* @author Clément Fournier
* @since 6.0.0
@ -280,7 +280,7 @@ public class DesignerWindowPresenter {
XMLSettingsSaver saver = XMLSettingsSaver.forFile(SETTINGS_FILE_NAME);
for (DesignerWindowSettings setting : DesignerWindowSettings.values()) {
saver.put(setting.keyName, setting.getValueFrom(this));
saver.put(setting.getKeyName(), setting.getValueFrom(this));
}
saver.save();
@ -291,7 +291,7 @@ public class DesignerWindowPresenter {
private void loadSettings() throws IOException {
Set<String> keyNames = Arrays.stream(DesignerWindowSettings.values())
.map(e -> e.keyName)
.map(DesignerWindowSettings::getKeyName)
.collect(Collectors.toSet());
XMLSettingsLoader loader = new XMLSettingsLoader(SETTINGS_FILE_NAME, keyNames);
@ -304,8 +304,6 @@ public class DesignerWindowPresenter {
/********************************/
/* SETTINGS LOAD/STORE ROUTINES */
/********************************/

View File

@ -47,7 +47,7 @@ enum DesignerWindowSettings {
DesignerWindowPresenter::setLeftToolbarDividerPosition);
public final String keyName;
private final String keyName;
private final Function<DesignerWindowPresenter, String> getValueFunction;
private final PresenterSettingSetter setValueFunction;
@ -83,6 +83,11 @@ enum DesignerWindowSettings {
}
public String getKeyName() {
return keyName;
}
/** Get the setting from the name of its key. */
static DesignerWindowSettings ofKeyName(String key) {
return Arrays.stream(DesignerWindowSettings.values())

View File

@ -20,7 +20,7 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
/**
* Main class of the model.
* Main class of the model. Manages the compilation unit and evaluation logic.
*
* @author Clément Fournier
* @since 6.0.0
@ -61,7 +61,7 @@ public class ASTManager {
public String getXPathVersion() {
return xpathEvaluator.xpathVersionProperty().get();
return xpathEvaluator.getXpathVersion();
}
@ -82,11 +82,11 @@ public class ASTManager {
/**
* Evaluates an XPath request, returns the matching nodes.
* Evaluates an XPath query, returns the matching nodes.
*
* @param xpathQuery Query to execute
*
* @return The matching nodes, or Optional.empty if the compilation unit is invalid.
* @return List of the matching nodes, never null.
*
* @throws XPathEvaluationException if there was an error during the evaluation. The cause is preserved.
*/
@ -97,6 +97,13 @@ public class ASTManager {
}
/**
* Returns true if the source must be recompiled.
*
* @param source Source to test
*
* @return true if the current AST does not correspond to the parameter source
*/
public boolean isRecompilationNeeded(String source) {
return !StringUtils.equals(source, lastValidSource)
|| !languageVersion.get().equals(lastLanguageVersion);

View File

@ -33,7 +33,7 @@ class XPathEvaluator {
private final StringProperty xpathVersion = new SimpleStringProperty();
public String getXpathVersion() {
String getXpathVersion() {
return xpathVersion.get();
}

View File

@ -0,0 +1,28 @@
package net.sourceforge.pmd.util.fxdesigner;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
/**
* @author Clément Fournier
* @since 6.0.0
*/
public class DesignerWindowSettingsTest {
@Test
public void testKeysNamesAreUnique() {
List<String> keyNames = Arrays.stream(DesignerWindowSettings.values())
.map(DesignerWindowSettings::getKeyName)
.collect(Collectors.toList());
assertEquals(keyNames.size(), new HashSet<>(keyNames).size());
}
}