001package org.apache.commons.digester3.binder;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.junit.Assert.assertSame;
023import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
024
025import org.apache.commons.digester3.Digester;
026import org.junit.Test;
027import org.xml.sax.ErrorHandler;
028import org.xml.sax.Locator;
029import org.xml.sax.SAXException;
030import org.xml.sax.SAXParseException;
031
032public final class DigesterLoaderTestCase
033{
034
035    /**
036     * DIGESTER-151
037     */
038    @Test
039    public void digester151()
040    {
041        ErrorHandler expected = new ErrorHandler()
042        {
043
044            public void warning( SAXParseException exception )
045                throws SAXException
046            {
047                // do nothing
048            }
049
050            public void fatalError( SAXParseException exception )
051                throws SAXException
052            {
053                // do nothing
054            }
055
056            public void error( SAXParseException exception )
057                throws SAXException
058            {
059                // do nothing
060            }
061
062        };
063
064        Digester digester = newLoader( new AbstractRulesModule()
065        {
066
067            @Override
068            protected void configure()
069            {
070                // do nothing
071            }
072
073        } ).setErrorHandler( expected ).newDigester();
074
075        ErrorHandler actual = digester.getErrorHandler();
076
077        assertSame( expected, actual );
078    }
079
080    @Test
081    public void digeser152()
082    {
083        Locator expected = new Locator()
084        {
085
086            public String getSystemId()
087            {
088                // just fake method
089                return null;
090            }
091
092            public String getPublicId()
093            {
094                // just fake method
095                return null;
096            }
097
098            public int getLineNumber()
099            {
100                // just fake method
101                return 0;
102            }
103
104            public int getColumnNumber()
105            {
106                // just fake method
107                return 0;
108            }
109        };
110
111        Digester digester = newLoader( new AbstractRulesModule()
112        {
113
114            @Override
115            protected void configure()
116            {
117                // do nothing
118            }
119
120        } ).setDocumentLocator( expected ).newDigester();
121
122        Locator actual = digester.getDocumentLocator();
123
124        assertSame( expected, actual );
125    }
126
127    @Test
128    public void digester155()
129    {
130        ClassLoader expected = getClass().getClassLoader();
131
132        Digester digester = newLoader( new AbstractRulesModule()
133        {
134
135            @Override
136            protected void configure()
137            {
138                // do nothing
139            }
140
141        } ).setClassLoader( expected ).newDigester();
142
143        ClassLoader actual = digester.getClassLoader();
144
145        assertSame( expected, actual );
146    }
147
148}