001: /*
002: * Copyright (c) 2004-2005 SLF4J.ORG
003: * Copyright (c) 2004-2005 QOS.ch
004: *
005: * All rights reserved.
006: *
007: * Permission is hereby granted, free of charge, to any person obtaining
008: * a copy of this software and associated documentation files (the
009: * "Software"), to deal in the Software without restriction, including
010: * without limitation the rights to use, copy, modify, merge, publish,
011: * distribute, and/or sell copies of the Software, and to permit persons
012: * to whom the Software is furnished to do so, provided that the above
013: * copyright notice(s) and this permission notice appear in all copies of
014: * the Software and that both the above copyright notice(s) and this
015: * permission notice appear in supporting documentation.
016: *
017: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
018: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
019: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
020: * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
021: * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
022: * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
023: * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
024: * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
025: * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
026: *
027: * Except as contained in this notice, the name of a copyright holder
028: * shall not be used in advertising or otherwise to promote the sale, use
029: * or other dealings in this Software without prior written authorization
030: * of the copyright holder.
031: *
032: */
033: package org.slf4j;
034:
035: import java.util.Iterator;
036:
037: import junit.framework.TestCase;
038:
039: import org.slf4j.helpers.BasicMarkerFactory;
040:
041: /**
042: * Unit test BasicMarker
043: *
044: * @author Ceki Gülcü
045: * @author Joern Huxhorn
046: */
047: public class BasicMarkerTest extends TestCase {
048: static final String BLUE_STR = "BLUE";
049: static final String RED_STR = "RED";
050: static final String GREEN_STR = "GREEN";
051: static final String COMP_STR = "COMP";
052: static final String MULTI_COMP_STR = "MULTI_COMP";
053: static final String PARENT_MARKER_STR = "PARENT_MARKER";
054: static final String CHILD_MARKER_STR = "CHILD_MARKER";
055:
056: final IMarkerFactory factory;
057: final Marker blue;
058: final Marker red;
059: final Marker green;
060: final Marker comp;
061: final Marker multiComp;
062:
063: public BasicMarkerTest() {
064: factory = new BasicMarkerFactory();
065:
066: blue = factory.getMarker(BLUE_STR);
067: red = factory.getMarker(RED_STR);
068: green = factory.getMarker(GREEN_STR);
069: comp = factory.getMarker(COMP_STR);
070: comp.add(blue);
071:
072: multiComp = factory.getMarker(MULTI_COMP_STR);
073: multiComp.add(green);
074: multiComp.add(comp);
075: }
076:
077: public void testPrimitive() {
078: assertEquals(BLUE_STR, blue.getName());
079: assertTrue(blue.contains(blue));
080:
081: Marker blue2 = factory.getMarker(BLUE_STR);
082: assertEquals(BLUE_STR, blue2.getName());
083: assertEquals(blue, blue2);
084: assertTrue(blue.contains(blue2));
085: assertTrue(blue2.contains(blue));
086: }
087:
088: public void testPrimitiveByName() {
089: assertTrue(blue.contains(BLUE_STR));
090: }
091:
092: public void testComposite() {
093: assertTrue(comp.contains(comp));
094: assertTrue(comp.contains(blue));
095: }
096:
097: public void testCompositeByName() {
098: assertTrue(comp.contains(COMP_STR));
099: assertTrue(comp.contains(BLUE_STR));
100: }
101:
102: public void testMultiComposite() {
103: assertTrue(multiComp.contains(comp));
104: assertTrue(multiComp.contains(blue));
105: assertTrue(multiComp.contains(green));
106: assertFalse(multiComp.contains(red));
107: }
108:
109: public void testMultiCompositeByName() {
110: assertTrue(multiComp.contains(COMP_STR));
111: assertTrue(multiComp.contains(BLUE_STR));
112: assertTrue(multiComp.contains(GREEN_STR));
113: assertFalse(multiComp.contains(RED_STR));
114: }
115:
116: public void testMultiAdd() {
117: Marker parent = factory.getMarker(PARENT_MARKER_STR);
118: Marker child = factory.getMarker(CHILD_MARKER_STR);
119: for (int i = 0; i < 10; i++) {
120: parent.add(child);
121: }
122:
123: // check that the child was added once and only once
124: Iterator iterator = parent.iterator();
125: assertTrue(iterator.hasNext());
126: assertEquals(CHILD_MARKER_STR, iterator.next().toString());
127: assertFalse(iterator.hasNext());
128: }
129:
130: public void testAddRemove() {
131: final String NEW_PREFIX = "NEW_";
132: Marker parent = factory.getMarker(NEW_PREFIX
133: + PARENT_MARKER_STR);
134: Marker child = factory.getMarker(NEW_PREFIX + CHILD_MARKER_STR);
135: assertFalse(parent.contains(child));
136: assertFalse(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
137: assertFalse(parent.remove(child));
138:
139: parent.add(child);
140:
141: assertTrue(parent.contains(child));
142: assertTrue(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
143:
144: assertTrue(parent.remove(child));
145:
146: assertFalse(parent.contains(child));
147: assertFalse(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
148: assertFalse(parent.remove(child));
149: }
150:
151: }
|