2 * Copyright 2005-2011 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.xmlrouter.impl;
18 import static junit.framework.Assert.*;
19 import static org.mockito.Mockito.*;
21 import java.util.concurrent.atomic.AtomicLong;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.wamblee.xmlrouter.common.Id;
26 import org.wamblee.xmlrouter.config.Config;
27 import org.wamblee.xmlrouter.config.Identifiable;
29 public class ConfigImplTest {
31 private static final String CONFIG_TYPE = "transformation";
33 private static interface MyType extends Identifiable {
37 private static class MyTypeWrapper implements MyType {
38 private String prefix;
41 public MyTypeWrapper(String aPrefix, MyType aType) {
46 public MyType getType() {
52 return new Id(prefix + type.getId().getId());
56 private AtomicLong sequence;
57 private ExtendedConfig<MyType> config;
61 sequence = new AtomicLong(1L);
62 config = new ConfigImpl<MyType>(new Id<Config>(CONFIG_TYPE)) {
64 public MyType wrap(String aPrefix, MyType aT) {
65 return new MyTypeWrapper(aPrefix, aT);
71 public void testAdd() {
72 MyType type1 = mock(MyType.class);
73 when(type1.getId()).thenReturn(new Id("type1"));
77 assertEquals(1, config.values().size());
78 assertTrue(config.values().get(0) instanceof MyTypeWrapper);
79 assertSame(type1, ((MyTypeWrapper) config.values().get(0)).getType());
80 assertEquals(CONFIG_TYPE + "." + type1.getId().getId(), config.values()
81 .get(0).getId().getId());
84 MyType type2 = mock(MyType.class);
85 when(type2.getId()).thenReturn(new Id("type2"));
88 assertEquals(2, config.values().size());
92 public void testRemove() {
93 MyType type1 = mock(MyType.class);
94 when(type1.getId()).thenReturn(new Id("type1"));
98 assertEquals(1, config.values().size());
100 assertTrue(config.remove(new Id(CONFIG_TYPE + "." + "type1")));
101 assertTrue(config.values().isEmpty());
104 @Test(expected = UnsupportedOperationException.class)
105 public void testUnmodifiable() {
106 config.values().add(mock(MyType.class));