Ejemplo n.º 1
0
 public static void main(String[] args) {
   try {
     MyFactory f = new MyFactory();
     MyInterface inter = f.produceOne();
     inter.print();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 2
0
 @Test
 public void testVoid() {
   MyInterface myInterface = mock(MyInterface.class);
   try {
     myInterface.put(new Object());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 3
0
 @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) {
   }
 }
Ejemplo n.º 4
0
 @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));
 }
Ejemplo n.º 5
0
 @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());
 }