View Javadoc
1   /*
2    * Copyright (C) 2010, Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.junit.http;
12  
13  import java.util.Enumeration;
14  import java.util.HashMap;
15  import java.util.Iterator;
16  import java.util.Map;
17  
18  import javax.servlet.ServletConfig;
19  import javax.servlet.ServletContext;
20  
21  /**
22   * Mock ServletConfig
23   */
24  public class MockServletConfig implements ServletConfig {
25  	private final Map<String, String> parameters = new HashMap<>();
26  
27  	/**
28  	 * Set init parameter.
29  	 *
30  	 * @param name
31  	 * @param value
32  	 */
33  	public void setInitParameter(String name, String value) {
34  		parameters.put(name, value);
35  	}
36  
37  	/** {@inheritDoc} */
38  	@Override
39  	public String getInitParameter(String name) {
40  		return parameters.get(name);
41  	}
42  
43  	/** {@inheritDoc} */
44  	@Override
45  	public Enumeration<String> getInitParameterNames() {
46  		final Iterator<String> i = parameters.keySet().iterator();
47  		return new Enumeration<>() {
48  
49  			@Override
50  			public boolean hasMoreElements() {
51  				return i.hasNext();
52  			}
53  
54  			@Override
55  			public String nextElement() {
56  				return i.next();
57  			}
58  		};
59  	}
60  
61  	/** {@inheritDoc} */
62  	@Override
63  	public String getServletName() {
64  		return "MOCK_SERVLET";
65  	}
66  
67  	/** {@inheritDoc} */
68  	@Override
69  	public ServletContext getServletContext() {
70  		return null;
71  	}
72  }