20 package net.sf.gridarta.gui.mapmenu;
23 import java.io.IOException;
24 import java.util.ResourceBundle;
25 import java.util.prefs.BackingStoreException;
26 import java.util.prefs.Preferences;
27 import javax.swing.tree.DefaultMutableTreeNode;
28 import javax.swing.tree.TreeNode;
33 import net.
sf.japi.swing.action.ActionBuilder;
34 import net.
sf.japi.swing.action.ActionBuilderFactory;
35 import net.
sf.japi.swing.action.DefaultActionBuilder;
36 import org.jetbrains.annotations.NotNull;
37 import org.junit.Assert;
38 import org.junit.BeforeClass;
39 import org.junit.Test;
52 public void test1() throws IOException {
59 }
catch (
final IOException ignored) {
68 final MapMenuEntry mapMenuEntry0 = result0.getMapMenuEntry();
69 Assert.assertEquals(
"directory0/sub", result0.getDirectory());
70 Assert.assertEquals(
"title0", mapMenuEntry0.
getTitle());
72 final MapMenuEntryMap mapMenuEntryMap0 = (MapMenuEntryMap) mapMenuEntry0;
73 Assert.assertEquals(pathManager.
getMapFile(
new File(
"filename0")), mapMenuEntryMap0.
getMapFile());
76 final MapMenuEntry mapMenuEntry1 = result1.getMapMenuEntry();
77 Assert.assertEquals(
"directory1/sub", result1.getDirectory());
78 Assert.assertEquals(
"title1", mapMenuEntry1.
getTitle());
84 }
catch (
final IOException ignored) {
91 }
catch (
final IOException ignored) {
102 public void test2() throws BackingStoreException {
104 final ActionBuilder actionBuilder =
new DefaultActionBuilder(
"net.sf.gridarta");
105 ActionBuilderFactory.getInstance().putActionBuilder(
"net.sf.gridarta", actionBuilder);
106 final ResourceBundle resourceBundle = ResourceBundle.getBundle(
"net.sf.gridarta.gui.mapmenu.testLoad1");
107 actionBuilder.addBundle(resourceBundle);
109 final Preferences preferences = Preferences.userNodeForPackage(
MainControl.class);
110 for (
final String key : resourceBundle.keySet()) {
111 final String value = resourceBundle.getString(key);
112 preferences.put(key, value);
117 Assert.assertEquals(10, mapMenu1.
size());
119 for (
final String key : preferences.keys()) {
120 preferences.remove(key);
125 Assert.assertEquals(0, mapMenu2.
size());
130 Assert.assertEquals(10, mapMenu2.
size());
142 final ActionBuilder actionBuilder =
new DefaultActionBuilder(
"net.sf.gridarta");
143 ActionBuilderFactory.getInstance().putActionBuilder(
"net.sf.gridarta", actionBuilder);
148 final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) mapMenu1.
getRoot().getFirstChild();
166 private static void compareTrees(@NotNull
final TreeNode treeNode1, @NotNull
final TreeNode treeNode2) {
167 Assert.assertEquals(treeNode1.getChildCount(), treeNode2.getChildCount());
168 for (
int i = 0; i < treeNode1.getChildCount(); i++) {
169 final DefaultMutableTreeNode childTreeNode1 = (DefaultMutableTreeNode) treeNode1.getChildAt(i);
170 final DefaultMutableTreeNode childTreeNode2 = (DefaultMutableTreeNode) treeNode2.getChildAt(i);
173 Assert.assertSame(mapMenuEntry1.getClass(), mapMenuEntry2.getClass());
190 mapMenuEntry1.
visit(mapMenuEntryVisitor);
199 System.setProperty(
"java.util.prefs.PreferencesFactory",
"net.sf.gridarta.preferences.FilePreferencesFactory");
This class contains methods for converting relative map paths to absolute map paths and vice versa...
Reading and writing of maps, handling of paths.
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
Base package of all Gridarta classes.
Interface used as preferences location.
static void initialize(@NotNull final String defaultName, @Nullable final File file)
Initialize the module.
An ProjectSettings implementation for testing purposes.
A PreferencesFactory which creates FilePreferences instances.