chrismair | 00dc7bd | 2014-05-11 21:21:28 +0000 | [diff] [blame] | 1 | /*
|
| 2 | * Copyright 2008 the original author or authors.
|
| 3 | *
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 | * you may not use this file except in compliance with the License.
|
| 6 | * You may obtain a copy of the License at
|
| 7 | *
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 9 | *
|
| 10 | * Unless required by applicable law or agreed to in writing, software
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 | * See the License for the specific language governing permissions and
|
| 14 | * limitations under the License.
|
| 15 | */
|
| 16 | package org.mockftpserver.test
|
| 17 |
|
| 18 | /**
|
| 19 | * Stub implementation of ResourceBundle for testing. Provide an optional Map of entries in the constructor,
|
| 20 | * and allow dynamic adding or changing of map contents. Automatically define default value for key if no entry
|
| 21 | * exists for the key.
|
| 22 | */
|
| 23 | class StubResourceBundle extends ResourceBundle {
|
| 24 |
|
| 25 | Map map
|
| 26 |
|
| 27 | StubResourceBundle(Map map = [:]) {
|
| 28 | this.map = map
|
| 29 | }
|
| 30 |
|
| 31 | void put(String key, String value) {
|
| 32 | map.put(key, value)
|
| 33 | }
|
| 34 |
|
| 35 | Object handleGetObject(String key) {
|
| 36 | // Return default if no entry is defined
|
| 37 | return map[key] ?: "key=$key arg0={0} arg1={1}".toString()
|
| 38 | }
|
| 39 |
|
| 40 | public Enumeration getKeys() {
|
| 41 | return new Vector(map.keySet()).elements()
|
| 42 | }
|
| 43 |
|
| 44 | } |