20 package net.sf.gridarta.model.index;
23 import java.io.IOException;
24 import java.util.Collection;
25 import java.util.Iterator;
26 import java.util.concurrent.atomic.AtomicInteger;
35 import org.jetbrains.annotations.NotNull;
36 import org.junit.Assert;
37 import org.junit.Test;
51 public void test1() throws InterruptedException, IOException {
54 final File mapsDirectory = mapControlCreator.
createMapsDirectory(
"map1:Map1",
"path/map2:Map Name2");
61 Assert.assertEquals(2, index.findPartialName(
"").size());
62 assertEquals(index.findPartialName(
"Map1"), mapsDirectory,
"map1");
63 assertEquals(index.findPartialName(
"Map Name2"), mapsDirectory,
"path/map2");
76 public void test2() throws InterruptedException, IOException {
78 final File mapsDirectory = mapControlCreator.
createMapsDirectory(
"map1:Map1",
"path/map2:Map Name2");
81 final AtomicInteger indexingFinished =
new AtomicInteger();
85 public void valueAdded(@NotNull
final MapFile value) {
89 public void valueRemoved(@NotNull
final MapFile value) {
93 public void nameChanged() {
97 public void pendingChanged() {
101 public void indexingFinished() {
102 indexingFinished.incrementAndGet();
110 Assert.assertEquals(1, indexingFinished.getAndSet(0));
116 Assert.assertEquals(0, indexingFinished.getAndSet(0));
121 Assert.assertEquals(1, indexingFinished.getAndSet(0));
122 Assert.assertEquals(3, index.findPartialName(
"").size());
123 assertEquals(index.findPartialName(
"Map1"), mapsDirectory,
"map1");
124 assertEquals(index.findPartialName(
"Map Name2"), mapsDirectory,
"path/map2");
125 assertEquals(index.findPartialName(
"name3"), mapsDirectory,
"mapfile");
139 public static void assertEquals(@NotNull
final Collection<MapFile> mapPaths, @NotNull
final File mapsDirectory, @NotNull
final String mapPath) {
140 Assert.assertEquals(1, mapPaths.size());
141 final Iterator<MapFile> it = mapPaths.iterator();
142 final MapFile mapFile = it.next();
143 Assert.assertEquals(mapsDirectory, mapFile.
getMapsDir());
Indexes maps by map name.
void save()
Saves the map to a file.
String getPath()
Returns the map path information.
static void deleteTempDir(@NotNull final File dir)
Deletes a temporary directory.
PathManager getPathManager()
Returns the PathManager.
Regression tests for MapsIndexer.
Settings that apply to a project.
void start()
Starts indexing.
Maintains a MapsIndex for the maps directory.
Interface for listeners interested in Index related events.
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
Helper class for creating MapControl instances for regression tests.
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
void test1()
Checks that basic indexing works as expected.
void test2()
Checks that IndexListener#finalize() is called once after indexing has completed. ...
A MapArchObject implementation for testing purposes.
void addIndexListener(@NotNull final IndexListener< V > listener)
Adds an IndexListener to be notified of changes.
Base package of all Gridarta classes.
File createMapsDirectory(@NotNull final String... specs)
Creates a maps directory consisting of a set of maps.
GameObjects are the objects based on Archetypes found on maps.
void waitForIdle()
Blocks the calling thread until all pending maps have been indexed.
void stop()
Stops indexing.
ProjectSettings getProjectSettings()
Returns the ProjectSettings.
File getMapsDir()
Returns the base directory this map file is part of.
Currently nothing more than a marker interface for unification.
An Archetype implementation for testing purposes.
A GameObject implementation for testing purposes.
File getMapsDirectory()
Returns the default maps directory.
static void assertEquals(@NotNull final Collection< MapFile > mapPaths, @NotNull final File mapsDirectory, @NotNull final String mapPath)
Checks that a Collection of Files contains exactly one expected value.
The location of a map file with a map directory.
MapManager< TestGameObject, TestMapArchObject, TestArchetype > getMapManager()
Returns the MapManager.
The class Size2D represents a 2d rectangular area.
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.