Gridarta Editor
AutojoinListsHelper.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.autojoin;
21 
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.regex.Pattern;
29 import org.jetbrains.annotations.NotNull;
30 import org.junit.Assert;
31 
36 public class AutojoinListsHelper {
37 
41  @NotNull
42  private static final Pattern ALTERNATIVES_PATTERN = Pattern.compile("\\|");
43 
47  @NotNull
49 
53  @NotNull
55 
60  this(new TestMapModelCreator(false));
61  }
62 
67  public AutojoinListsHelper(@NotNull final TestMapModelCreator mapModelCreator) {
68  this.mapModelCreator = mapModelCreator;
69  autojoinLists = mapModelCreator.getAutojoinLists();
70  }
71 
78  public void newAutojoinLists(@NotNull final String... archetypeNames) throws IllegalAutojoinListException {
79  final List<List<TestArchetype>> archetypes = new ArrayList<>();
80  for (final String archetypeNameList : archetypeNames) {
81  final List<TestArchetype> archetypeList = new ArrayList<>();
82  if (!archetypeNameList.isEmpty()) {
83  for (final String archetypeName : ALTERNATIVES_PATTERN.split(archetypeNameList, -1)) {
84  archetypeList.add(mapModelCreator.getArchetype(archetypeName));
85  }
86  }
87  archetypes.add(archetypeList);
88  }
89  autojoinLists.addAutojoinList(new AutojoinList<>(archetypes));
90  }
91 
97  public void newAutojoinListsFail(@NotNull final String expectedException, @NotNull final String... archetypeNames) {
98  try {
99  newAutojoinLists(archetypeNames);
100  Assert.fail();
101  } catch (final IllegalAutojoinListException ex) {
102  Assert.assertEquals(expectedException, ex.getMessage());
103  }
104  }
105 
106 }
Helper class for regression tests to create MapModel instances.
Implements AutojoinList related functions.
void newAutojoinListsFail(@NotNull final String expectedException, @NotNull final String... archetypeNames)
Creates a new AutojoinLists instance and expects an error.
A MapArchObject implementation for testing purposes.
Contains a list of (typically wall-)arches which do autojoining.
Base package of all Gridarta classes.
final TestMapModelCreator mapModelCreator
The TestMapModelCreator instance.
GameObjects are the objects based on Archetypes found on maps.
final AutojoinLists< TestGameObject, TestMapArchObject, TestArchetype > autojoinLists
The AutojoinLists instance.
void addAutojoinList(@NotNull final AutojoinList< G, A, R > autojoinList)
Adds a new autojoin list.
TestArchetype getArchetype(@NotNull final String archetypeName)
Returns an archetype.
static final Pattern ALTERNATIVES_PATTERN
A Pattern that matches alternative archetypes.
AutojoinListsHelper(@NotNull final TestMapModelCreator mapModelCreator)
Creates a new instance.
void newAutojoinLists(@NotNull final String... archetypeNames)
Creates a new AutojoinLists instance.
Manages a mapping between archetypes to AutojoinLists.
An Archetype implementation for testing purposes.
A GameObject implementation for testing purposes.