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 interface MyType extends Identifiable {
35 private static class MyTypeWrapper implements MyType {
38 public MyTypeWrapper(MyType aType) {
42 public MyType getType() {
52 private AtomicLong sequence;
53 private ExtendedConfig<MyType> config;
57 sequence = new AtomicLong(1L);
58 config = new ConfigImpl<MyType>(new Id<Config>("mytype")) {
60 public MyType wrap(MyType aT) {
61 return new MyTypeWrapper(aT);
67 public void testAdd() {
68 MyType type1 = mock(MyType.class);
69 when(type1.getId()).thenReturn(new Id("type1"));
73 assertEquals(1, config.values().size());
74 assertTrue(config.values().get(0) instanceof MyTypeWrapper);
75 assertSame(type1, ((MyTypeWrapper) config.values().get(0)).getType());
78 MyType type2 = mock(MyType.class);
79 when(type2.getId()).thenReturn(new Id("type2"));
82 assertEquals(2, config.values().size());
86 public void testRemove() {
87 MyType type1 = mock(MyType.class);
88 when(type1.getId()).thenReturn(new Id("type1"));
92 assertEquals(1, config.values().size());
94 assertTrue(config.remove(new Id("type1")));
95 assertTrue(config.values().isEmpty());
98 @Test(expected = UnsupportedOperationException.class)
99 public void testUnmodifiable() {
100 config.values().add(mock(MyType.class));