public void testExceptionFactory() { assertNotNull(FactoryUtils.exceptionFactory()); assertSame(FactoryUtils.exceptionFactory(), FactoryUtils.exceptionFactory()); try { FactoryUtils.exceptionFactory().create(); } catch (FunctorException ex) { try { FactoryUtils.exceptionFactory().create(); } catch (FunctorException ex2) { return; } } fail(); }
public void testInstantiateFactoryNoConstructor() { try { Factory factory = FactoryUtils.instantiateFactory(Date.class, new Class[] {Long.class}, new Object[] {null}); } catch (IllegalArgumentException ex) { return; } fail(); }
public void testPrototypeFactoryPublicBad() { Object proto = new Object(); try { Factory factory = FactoryUtils.prototypeFactory(proto); } catch (IllegalArgumentException ex) { return; } fail(); }
public void testConstantFactoryConstant() { Integer constant = new Integer(9); Factory factory = FactoryUtils.constantFactory(constant); assertNotNull(factory); Object created = factory.create(); assertSame(constant, created); }
public void testNullFactory() { Factory factory = FactoryUtils.nullFactory(); assertNotNull(factory); Object created = factory.create(); assertNull(created); }
public void testConstantFactoryNull() { Factory factory = FactoryUtils.constantFactory(null); assertNotNull(factory); Object created = factory.create(); assertNull(created); }
public void testFactoryTransformer() { assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(null)); assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cObject)); assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cString)); assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cInteger)); try { TransformerUtils.asTransformer((Factory) null); } catch (IllegalArgumentException ex) { return; } fail(); }
public void testInstantiateFactoryMismatch() { try { Factory factory = FactoryUtils.instantiateFactory(Date.class, null, new Object[] {null}); } catch (IllegalArgumentException ex) { return; } fail(); }
public void testPrototypeFactoryNull() { assertSame(ConstantFactory.NULL_INSTANCE, FactoryUtils.prototypeFactory(null)); }
public void testLazyMapFactory() { Factory factory = FactoryUtils.constantFactory(new Integer(5)); Map map = MapUtils.lazyMap(new HashMap(), factory); assertTrue(map instanceof LazyMap);
public void testInstantiateFactoryNull() { try { Factory factory = FactoryUtils.instantiateFactory(null); } catch (IllegalArgumentException ex) { return; } fail(); }
public void testPrototypeFactoryPublicSerialization() throws Exception { Integer proto = new Integer(9); Factory factory = FactoryUtils.prototypeFactory(proto); assertNotNull(factory); Object created = factory.create(); assertTrue(proto != created); assertEquals(proto, created); // check serialisation works - if enabled System.setProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY, "true"); try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(buffer); out.writeObject(factory); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); Object dest = in.readObject(); in.close(); } finally { System.setProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY, "false"); } }
public void testInstantiateFactoryComplex() { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); // 2nd Jan 1970 Factory factory = FactoryUtils.instantiateFactory(Date.class, new Class[] {Integer.TYPE, Integer.TYPE, Integer.TYPE}, new Object[] {new Integer(70), new Integer(0), new Integer(2)}); assertNotNull(factory); Object created = factory.create(); assertTrue(created instanceof Date); // long time of 1 day (== 2nd Jan 1970) assertEquals(new Date(1000 * 60 * 60 * 24), created); }
public void testPrototypeFactoryPublicCopyConstructor() throws Exception { Mock1 proto = new Mock1(6); Factory factory = PrototypeFactory.getInstance(proto); assertNotNull(factory); Object created = factory.create(); assertTrue(proto != created); assertEquals(proto, created); // check serialisation works - if enabled System.setProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY, "true"); try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(buffer); try { out.writeObject(factory); } catch (NotSerializableException ex) { out.close(); } factory = FactoryUtils.prototypeFactory(new Mock2("S")); buffer = new ByteArrayOutputStream(); out = new ObjectOutputStream(buffer); out.writeObject(factory); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); Object dest = in.readObject(); in.close(); } finally { System.setProperty(FunctorUtils.UNSAFE_SERIALIZABLE_PROPERTY, "false"); } }
public void testInstantiateFactorySimple() { Factory factory = FactoryUtils.instantiateFactory(Mock3.class); assertNotNull(factory); Object created = factory.create(); assertEquals(0, ((Mock3) created).getValue()); created = factory.create(); assertEquals(1, ((Mock3) created).getValue()); }
public void testPrototypeFactoryPublicSerializationError() { Mock2 proto = new Mock2(new Object()); Factory factory = FactoryUtils.prototypeFactory(proto); assertNotNull(factory); try { Object created = factory.create(); } catch (FunctorException ex) { assertTrue(ex.getCause() instanceof IOException); return; } fail(); }