2 * Copyright (c) 2018-2020. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.wiki;
19 import java.util.LinkedList;
20 import java.util.List;
22 import org.apache.commons.configuration.HierarchicalConfiguration;
23 import org.apache.commons.configuration.XMLConfiguration;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.JUnit4;
30 import org.hedgecode.chess.AbstractPositionTest;
31 import org.hedgecode.chess.Builder;
32 import org.hedgecode.chess.position.Position;
35 * Tests for {@link WikiBuilder}.
37 * @author Dmitry Samoshin aka gotty
39 @RunWith(JUnit4.class)
40 public class WikiBuilderTest extends AbstractPositionTest implements WikiPositionTest {
42 private static final String LINE_REGEX = "\\r?\\n";
45 public void testBuild() throws Exception {
46 Builder wikiBuilder = WikiBuilder.getInstance();
47 for (HierarchicalConfiguration testConfig : getXMLConfig().configurationsAt(TESTS)) {
50 MSG_WIKI_POSITION, testConfig.getString(AbstractPositionTest.NAME)
53 String wiki = testConfig.getString(WIKI_TAG);
54 Position position = assignPosition(
55 testConfig.configurationAt(AbstractPositionTest.POSITION)
57 boolean withTemplate = false;
58 if (testConfig.containsKey(WIKI_TEMPLATE)) {
59 withTemplate = testConfig.getBoolean(WIKI_TEMPLATE);
61 Wiki.setTemplate(withTemplate);
64 wikiBuilder.build(position)
70 protected void assertStringEquals(String expected, String actual) {
71 Assert.assertNotNull(expected);
72 Assert.assertNotNull(actual);
73 String[] expectedLines = expected.split(LINE_REGEX);
74 String[] actualLines = actual.split(LINE_REGEX);
79 for (int i = 0; i < expectedLines.length; ++i) {
80 super.assertStringEquals(
81 expectedLines[i].trim(),
88 public List<XMLConfiguration> getXMLPositions() throws Exception {
89 List<XMLConfiguration> xmlPositions = new LinkedList<>();
90 for (HierarchicalConfiguration testConfig : getXMLConfig().configurationsAt(TESTS)) {
93 testConfig.configurationAt(AbstractPositionTest.POSITION)