/* * Copyright 2005-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.xmlrouter.impl; import static junit.framework.Assert.*; import static org.mockito.Mockito.*; import org.junit.Before; import org.junit.Test; import org.wamblee.xmlrouter.common.Id; import org.wamblee.xmlrouter.config.ConfigException; import org.wamblee.xmlrouter.config.Identifiable; public class RobustIdentifiableTest { private Identifiable ident; @Before public void setUp() { ident = mock(Identifiable.class); } @Test(expected = ConfigException.class) public void testIdIsNull() { when(ident.getId()).thenReturn(null); RobustIdentifiable robust = new RobustIdentifiable( "prefix", ident); } @Test(expected = ConfigException.class) public void testIdThrowsException() { doThrow(new RuntimeException("xxx")).when(ident).getId(); RobustIdentifiable robust = new RobustIdentifiable( "prefix", ident); } @Test public void testNormalCase() { when(ident.getId()).thenReturn(new Id("myid")); RobustIdentifiable robust = new RobustIdentifiable( "prefix.", ident); assertEquals("prefix.myid", robust.getId().toString()); // changes later do not have any effect, the id should be immutable. when(ident.getId()).thenReturn(new Id("myid2")); assertEquals("prefix.myid", robust.getId().toString()); } }