001/*
002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
003 * Copyright (C) 2000-2010 The Gridarta Developers.
004 *
005 * This program is free software; you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation; either version 2 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License along
016 * with this program; if not, write to the Free Software Foundation, Inc.,
017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
018 */
019
020package net.sf.gridarta.model.errorview;
021
022import org.apache.log4j.Category;
023import org.apache.log4j.Logger;
024import org.jetbrains.annotations.NotNull;
025
026/**
027 * An {@link ErrorView} suitable for unit tests.
028 * @author Andreas Kirschbaum
029 */
030public class TestErrorView implements ErrorView {
031
032    /**
033     * The {@link Logger} for printing log messages.
034     */
035    @NotNull
036    private static final Category log = Logger.getLogger(TestErrorView.class);
037
038    /**
039     * Whether errors have been collected.
040     */
041    private boolean hasErrors;
042
043    /**
044     * Whether warnings have been collected.
045     */
046    private boolean hasWarnings;
047
048    /**
049     * {@inheritDoc}
050     */
051    @Override
052    public void addError(@NotNull final ErrorViewCategory categoryName, @NotNull final String message) {
053        hasErrors = true;
054        if (log.isInfoEnabled()) {
055            log.info("addError: " + categoryName + " " + message);
056        }
057    }
058
059    /**
060     * {@inheritDoc}
061     */
062    @Override
063    public void addError(@NotNull final ErrorViewCategory categoryName, final int lineNo, @NotNull final String message) {
064        hasErrors = true;
065        if (log.isInfoEnabled()) {
066            log.info("addError: " + categoryName + " " + lineNo + " " + message);
067        }
068    }
069
070    /**
071     * {@inheritDoc}
072     */
073    @Override
074    public void addWarning(@NotNull final ErrorViewCategory categoryName, @NotNull final String message) {
075        hasWarnings = true;
076        if (log.isInfoEnabled()) {
077            log.info("addWarning: " + categoryName + " " + message);
078        }
079    }
080
081    /**
082     * {@inheritDoc}
083     */
084    @Override
085    public void addWarning(@NotNull final ErrorViewCategory categoryName, final int lineNo, @NotNull final String message) {
086        hasWarnings = true;
087        if (log.isInfoEnabled()) {
088            log.info("addWarning: " + categoryName + " " + lineNo + " " + message);
089        }
090    }
091
092    /**
093     * {@inheritDoc}
094     */
095    @Override
096    public boolean hasErrors() {
097        return hasErrors;
098    }
099
100    /**
101     * Returns whether at least one warning message has been added.
102     * @return whether warnings exist
103     */
104    public boolean hasWarnings() {
105        return hasWarnings;
106    }
107
108    /**
109     * {@inheritDoc}
110     */
111    @Override
112    public void waitDialog() throws InterruptedException {
113        throw new AssertionError();
114    }
115
116}