View Javadoc

1   package org.apache.commons.digester3.binder;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.assertSame;
23  import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
24  
25  import org.apache.commons.digester3.Digester;
26  import org.junit.Test;
27  import org.xml.sax.ErrorHandler;
28  import org.xml.sax.Locator;
29  import org.xml.sax.SAXException;
30  import org.xml.sax.SAXParseException;
31  
32  public final class DigesterLoaderTestCase
33  {
34  
35      /**
36       * DIGESTER-151
37       */
38      @Test
39      public void digester151()
40      {
41          ErrorHandler expected = new ErrorHandler()
42          {
43  
44              public void warning( SAXParseException exception )
45                  throws SAXException
46              {
47                  // do nothing
48              }
49  
50              public void fatalError( SAXParseException exception )
51                  throws SAXException
52              {
53                  // do nothing
54              }
55  
56              public void error( SAXParseException exception )
57                  throws SAXException
58              {
59                  // do nothing
60              }
61  
62          };
63  
64          Digester digester = newLoader( new AbstractRulesModule()
65          {
66  
67              @Override
68              protected void configure()
69              {
70                  // do nothing
71              }
72  
73          } ).setErrorHandler( expected ).newDigester();
74  
75          ErrorHandler actual = digester.getErrorHandler();
76  
77          assertSame( expected, actual );
78      }
79  
80      @Test
81      public void digeser152()
82      {
83          Locator expected = new Locator()
84          {
85  
86              public String getSystemId()
87              {
88                  // just fake method
89                  return null;
90              }
91  
92              public String getPublicId()
93              {
94                  // just fake method
95                  return null;
96              }
97  
98              public int getLineNumber()
99              {
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 }