/**
* Copyright (c) 2010 Alois Glomann gnalff@lucubrators.net
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package net.lucubrators.honeycomb.registry;
import junit.framework.Assert;
import net.lucubrators.honeycomb.core.Comb;
import net.lucubrators.honeycomb.xml.registry.DefaultCombRegistry;
import net.lucubrators.honeycomb.xml.registry.exceptions.CombNotFoundException;
import net.lucubrators.honeycomb.xml.registry.exceptions.DuplicateCombException;
import org.junit.Before;
import org.junit.Test;
public class DefaultCombRegistryTest {
private DefaultCombRegistry registry;
@Before
public void setUp() throws Exception {
registry = new DefaultCombRegistry();
}
@Test
public void testHasComb() {
boolean contains = registry.contains("arg");
Assert.assertFalse(contains);
registry.register(new Comb("arg", new Object()));
Assert.assertTrue(registry.contains("arg"));
}
@Test(expected = CombNotFoundException.class)
public void testGetByIdThrowsException() {
registry.getById("arg");
Assert.fail("there should be an exception");
}
@Test
public void testThatRegisteredCombIsReturned() {
registry.register(new Comb("arg", new Object()));
Comb found = registry.getById("arg");
Assert.assertEquals("arg", found.getId());
}
@Test(expected = DuplicateCombException.class)
public void testThatRegisteringACombTwiceFails() {
registry.register(new Comb("arg", new Object()));
registry.register(new Comb("arg", new Object()));
Assert.fail("Duplicate combs are not allowed");
}
@Test
public void testSize() {
Assert.assertEquals(0, registry.size());
registry.register(new Comb("arg", new Object()));
Assert.assertEquals(1, registry.size());
registry.register(new Comb("arg1", new Object()));
Assert.assertEquals(2, registry.size());
}
}
|