public void setUp() throws Exception {
intf = mock(MyInterface.class);
lookup = mock(Lookup.class);
-
+
LookupProxyFactory<MyInterface> factory = new LookupProxyFactory<MyInterface>(
- MyInterface.class, lookup);
+ MyInterface.class, lookup);
proxy = factory.getProxy();
}
@Test(expected = LookupException.class)
public void testNotFoundAtJndi() throws Exception {
- when(lookup.lookup()).thenThrow(new RuntimeException("Object not found"));
+ when(lookup.lookup()).thenThrow(
+ new RuntimeException("Object not found"));
proxy.execute();
}
assertEquals(NAA_NA_NA_NAA_NA, e.getMessage());
}
}
-
- private static final class MyLookup implements Lookup {
-
+
+ private static final class MyLookup implements Lookup {
+
@Override
public Object lookup() throws Exception {
return new MyInterface() {
-
+
@Override
public int execute() {
return 10;
};
}
}
-
- @Test
+
+ @Test
public void testProxyMustBerializable() throws Exception {
lookup = new MyLookup();
LookupProxyFactory<MyInterface> factory = new LookupProxyFactory<MyInterface>(
- MyInterface.class, lookup);
+ MyInterface.class, lookup);
proxy = factory.getProxy();
-
+
+ assertEquals(10, proxy.execute());
+
+ assertTrue(proxy instanceof Serializable);
+
+ proxy = ObjectSerializationUtils.deserialize(ObjectSerializationUtils
+ .serialize(proxy), MyInterface.class);
+
+ // and it should still work
assertEquals(10, proxy.execute());
-
- assertTrue(proxy instanceof Serializable);
-
- proxy = ObjectSerializationUtils.deserialize(ObjectSerializationUtils.serialize(proxy),
- MyInterface.class);
-
- // and it should still work
- assertEquals(10, proxy.execute());
}
-
}