1 16 package org.apache.commons.collections; 17 18 import junit.framework.Test; 19 20 import org.apache.commons.collections.bag.HashBag; 21 import org.apache.commons.collections.bag.PredicatedBag; 22 import org.apache.commons.collections.bag.PredicatedSortedBag; 23 import org.apache.commons.collections.bag.SynchronizedBag; 24 import org.apache.commons.collections.bag.SynchronizedSortedBag; 25 import org.apache.commons.collections.bag.TransformedBag; 26 import org.apache.commons.collections.bag.TransformedSortedBag; 27 import org.apache.commons.collections.bag.TreeBag; 28 import org.apache.commons.collections.bag.UnmodifiableBag; 29 import org.apache.commons.collections.bag.UnmodifiableSortedBag; 30 31 38 public class TestBagUtils extends BulkTest { 39 40 public TestBagUtils(String name) { 41 super(name); 42 } 43 44 45 public static Test suite() { 46 return BulkTest.makeSuite(TestBagUtils.class); 47 } 48 49 51 protected Class stringClass = this.getName().getClass(); 52 protected Predicate truePredicate = PredicateUtils.truePredicate(); 53 protected Transformer nopTransformer = TransformerUtils.nopTransformer(); 54 55 57 public void testSynchronizedBag() { 58 Bag bag = BagUtils.synchronizedBag(new HashBag()); 59 assertTrue("Returned object should be a SynchronizedBag.", 60 bag instanceof SynchronizedBag); 61 try { 62 bag = BagUtils.synchronizedBag(null); 63 fail("Expecting IllegalArgumentException for null bag."); 64 } catch (IllegalArgumentException ex) { 65 } 67 } 68 69 public void testUnmodifiableBag() { 70 Bag bag = BagUtils.unmodifiableBag(new HashBag()); 71 assertTrue("Returned object should be an UnmodifiableBag.", 72 bag instanceof UnmodifiableBag); 73 try { 74 bag = BagUtils.unmodifiableBag(null); 75 fail("Expecting IllegalArgumentException for null bag."); 76 } catch (IllegalArgumentException ex) { 77 } 79 } 80 81 public void testPredicatedBag() { 82 Bag bag = BagUtils.predicatedBag(new HashBag(), truePredicate); 83 assertTrue("Returned object should be a PredicatedBag.", 84 bag instanceof PredicatedBag); 85 try { 86 bag = BagUtils.predicatedBag(null,truePredicate); 87 fail("Expecting IllegalArgumentException for null bag."); 88 } catch (IllegalArgumentException ex) { 89 } 91 try { 92 bag = BagUtils.predicatedBag(new HashBag(), null); 93 fail("Expecting IllegalArgumentException for null predicate."); 94 } catch (IllegalArgumentException ex) { 95 } 97 } 98 99 public void testTypedBag() { 100 Bag bag = BagUtils.typedBag(new HashBag(), stringClass); 101 assertTrue("Returned object should be a TypedBag.", 102 bag instanceof PredicatedBag); 103 try { 104 bag = BagUtils.typedBag(null, stringClass); 105 fail("Expecting IllegalArgumentException for null bag."); 106 } catch (IllegalArgumentException ex) { 107 } 109 try { 110 bag = BagUtils.typedBag(new HashBag(), null); 111 fail("Expecting IllegalArgumentException for null type."); 112 } catch (IllegalArgumentException ex) { 113 } 115 } 116 117 public void testTransformedBag() { 118 Bag bag = BagUtils.transformedBag(new HashBag(), nopTransformer); 119 assertTrue("Returned object should be an TransformedBag.", 120 bag instanceof TransformedBag); 121 try { 122 bag = BagUtils.transformedBag(null, nopTransformer); 123 fail("Expecting IllegalArgumentException for null bag."); 124 } catch (IllegalArgumentException ex) { 125 } 127 try { 128 bag = BagUtils.transformedBag(new HashBag(), null); 129 fail("Expecting IllegalArgumentException for null transformer."); 130 } catch (IllegalArgumentException ex) { 131 } 133 } 134 135 public void testSynchronizedSortedBag() { 136 Bag bag = BagUtils.synchronizedSortedBag(new TreeBag()); 137 assertTrue("Returned object should be a SynchronizedSortedBag.", 138 bag instanceof SynchronizedSortedBag); 139 try { 140 bag = BagUtils.synchronizedSortedBag(null); 141 fail("Expecting IllegalArgumentException for null bag."); 142 } catch (IllegalArgumentException ex) { 143 } 145 } 146 147 public void testUnmodifiableSortedBag() { 148 Bag bag = BagUtils.unmodifiableSortedBag(new TreeBag()); 149 assertTrue("Returned object should be an UnmodifiableSortedBag.", 150 bag instanceof UnmodifiableSortedBag); 151 try { 152 bag = BagUtils.unmodifiableSortedBag(null); 153 fail("Expecting IllegalArgumentException for null bag."); 154 } catch (IllegalArgumentException ex) { 155 } 157 } 158 159 public void testPredicatedSortedBag() { 160 Bag bag = BagUtils.predicatedSortedBag(new TreeBag(), truePredicate); 161 assertTrue("Returned object should be a PredicatedSortedBag.", 162 bag instanceof PredicatedSortedBag); 163 try { 164 bag = BagUtils.predicatedSortedBag(null, truePredicate); 165 fail("Expecting IllegalArgumentException for null bag."); 166 } catch (IllegalArgumentException ex) { 167 } 169 try { 170 bag = BagUtils.predicatedSortedBag(new TreeBag(), null); 171 fail("Expecting IllegalArgumentException for null predicate."); 172 } catch (IllegalArgumentException ex) { 173 } 175 } 176 177 public void testTypedSortedBag() { 178 Bag bag = BagUtils.typedSortedBag(new TreeBag(), stringClass); 179 assertTrue("Returned object should be a TypedSortedBag.", 180 bag instanceof PredicatedSortedBag); 181 try { 182 bag = BagUtils.typedSortedBag(null, stringClass); 183 fail("Expecting IllegalArgumentException for null bag."); 184 } catch (IllegalArgumentException ex) { 185 } 187 try { 188 bag = BagUtils.typedSortedBag(new TreeBag(), null); 189 fail("Expecting IllegalArgumentException for null type."); 190 } catch (IllegalArgumentException ex) { 191 } 193 } 194 195 public void testTransformedSortedBag() { 196 Bag bag = BagUtils.transformedSortedBag(new TreeBag(), nopTransformer); 197 assertTrue("Returned object should be an TransformedSortedBag", 198 bag instanceof TransformedSortedBag); 199 try { 200 bag = BagUtils.transformedSortedBag(null, nopTransformer); 201 fail("Expecting IllegalArgumentException for null bag."); 202 } catch (IllegalArgumentException ex) { 203 } 205 try { 206 bag = BagUtils.transformedSortedBag(new TreeBag(), null); 207 fail("Expecting IllegalArgumentException for null transformer."); 208 } catch (IllegalArgumentException ex) { 209 } 211 } 212 } 213 214 215 | Popular Tags |