Gridarta Editor
AbstractArchetypeParserTest.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.io;
21 
22 import java.io.BufferedReader;
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.Reader;
26 import java.io.StringReader;
27 import java.util.ArrayList;
28 import java.util.List;
36 import org.jetbrains.annotations.NotNull;
37 import org.junit.Assert;
38 
43 public abstract class AbstractArchetypeParserTest<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
44 
53  protected void check(@NotNull final String input, final boolean hasErrors, final boolean hasWarnings, final int archetypes) throws IOException {
55  final TestErrorView errorView = new TestErrorView();
56  final List<G> invObjects = new ArrayList<>();
57  final Reader reader = new StringReader(input);
58  try (BufferedReader bufferedReader = new BufferedReader(reader)) {
59  archetypeParser.parseArchetypeFromStream(bufferedReader, null, null, null, "panel", "folder", "", invObjects, new ErrorViewCollector(errorView, new File("*string*")));
60  }
61  Assert.assertEquals(hasErrors, errorView.hasErrors());
62  Assert.assertEquals(hasWarnings, errorView.hasWarnings());
63  Assert.assertEquals(archetypes, getArchetypeSet().getArchetypeCount());
64  }
65 
70  @NotNull
72 
77  @NotNull
78  protected abstract ArchetypeSet<G, A, R> getArchetypeSet();
79 
80 }
Convenience class for adding messages to a ErrorView instance using a fixed category name...
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
boolean hasErrors
Whether errors have been collected.
GameObjects are the objects based on Archetypes found on maps.
void parseArchetypeFromStream(@NotNull final BufferedReader in, @Nullable final R prototype, @Nullable final String line, @Nullable final String archName, @NotNull final String panelName, @NotNull final String folderName, @NotNull final String archPath, @NotNull final List< G > invObjects, @NotNull final ErrorViewCollector errorViewCollector)
void check(@NotNull final String input, final boolean hasErrors, final boolean hasWarnings, final int archetypes)
Creates a new archetype parser and parses the given input.
abstract AbstractArchetypeParser< G, A, R, ? extends AbstractArchetypeBuilder< G, A, R > > newArchetypeParser()
Creates a new AbstractArchetypeParser instance.
abstract ArchetypeSet< G, A, R > getArchetypeSet()
Returns the ArchetypeSet.
Interface that captures similarities between different ArchetypeSet implementations.
boolean hasWarnings
Whether warnings have been collected.
Abstract base class for regression tests for ArchetypeParser.
An ErrorView suitable for unit tests.