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;
27 public class ConfigImplTest {
29 private static interface MyType {
33 private static class MyTypeWrapper implements MyType {
34 private Id<MyType> id;
37 public MyTypeWrapper(Id<MyType> aId, MyType aType) {
42 public MyType getType() {
47 private AtomicLong sequence;
48 private ExtendedConfig<MyType> config;
52 sequence = new AtomicLong(1L);
53 config = new ConfigImpl<MyType>(sequence) {
55 public MyType wrap(Id<MyType> aId, MyType aT) {
56 return new MyTypeWrapper(aId, aT);
62 public void testAdd() {
63 MyType type1 = mock(MyType.class);
65 Id<MyType> id1 = config.add(type1);
68 assertEquals(1, config.map().size());
69 assertTrue(config.map().get(id1) instanceof MyTypeWrapper);
70 assertSame(type1, ((MyTypeWrapper) config.map().get(id1)).getType());
73 MyType type2 = mock(MyType.class);
74 Id<MyType> id2 = config.add(type2);
76 assertEquals(2, config.map().size());
77 assertFalse(id1.equals(id2));
81 public void testRemove() {
82 MyType type1 = mock(MyType.class);
83 Id<MyType> id1 = config.add(type1);
86 assertEquals(1, config.map().size());
89 assertTrue(config.map().isEmpty());
92 @Test(expected = UnsupportedOperationException.class)
93 public void testUnmodifiable() {
94 config.map().put(new Id<MyType>(100L), mock(MyType.class));