public static void main(String[] args) { try { MyFactory f = new MyFactory(); MyInterface inter = f.produceOne(); inter.print(); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testVoid() { MyInterface myInterface = mock(MyInterface.class); try { myInterface.put(new Object()); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testProxyThrows() throws Exception { MyInterface impl = (MyInterface) DuckTypeProxy.getProxy( MyInterface.class, Lists.newArrayList(new Object()), DuckTypeProxy.THROW); try { impl.getString(); fail("should have thrown USOE"); } catch (UnsupportedOperationException yay) { } }
@Test public void testNullParameter() throws Exception { Object obj = new Object() { public String get(String string) { return "how about: " + string; } }; MyInterface impl = (MyInterface) DuckTypeProxy.getProxy(MyInterface.class, Lists.newArrayList(obj), DuckTypeProxy.THROW); assertEquals("how about: null", impl.get((String) null)); }
@Test public void testProxyReturns() throws Exception { Object obj = new Object() { public String getString() { return "who's you're daddy?"; } }; MyInterface impl = (MyInterface) DuckTypeProxy.getProxy(MyInterface.class, Lists.newArrayList(obj), DuckTypeProxy.THROW); assertEquals("who's you're daddy?", impl.getString()); }
@Test public void testDependencyFromInterface(MyInterface myInterface) { assertEquals(10, myInterface.getValue()); }