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 */ setInitParameter(String name, String value)33 public void setInitParameter(String name, String value) { 34 parameters.put(name, value); 35 } 36 37 /** {@inheritDoc} */ 38 @Override getInitParameter(String name)39 public String getInitParameter(String name) { 40 return parameters.get(name); 41 } 42 43 /** {@inheritDoc} */ 44 @Override getInitParameterNames()45 public Enumeration<String> getInitParameterNames() { 46 final Iterator<String> i = parameters.keySet().iterator(); 47 return new Enumeration<String>() { 48 @Override 49 public boolean hasMoreElements() { 50 return i.hasNext(); 51 } 52 53 @Override 54 public String nextElement() { 55 return i.next(); 56 } 57 }; 58 } 59 60 /** {@inheritDoc} */ 61 @Override 62 public String getServletName() { 63 return "MOCK_SERVLET"; 64 } 65 66 /** {@inheritDoc} */ 67 @Override 68 public ServletContext getServletContext() { 69 return null; 70 } 71 } 72