public void testPrototypeFactoryPublicBad() { Object proto = new Object(); try { Factory factory = FactoryUtils.prototypeFactory(proto); } catch (IllegalArgumentException ex) { return; } fail(); }
public void testPrototypeFactoryNull() { assertSame(ConstantFactory.NULL_INSTANCE, FactoryUtils.prototypeFactory(null)); }
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 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 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(); }