@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((getConstructor() == null) ? 0 : getConstructor().hashCode()); result = prime * result + ((getMethod() == null) ? 0 : getMethod().hashCode()); return result; }
public String getName() { return getMethod() != null ? getMethod().getName() : getConstructor().getName(); }
public Class[] getParameterTypes() { return getMethod() != null ? getMethod().getParameterTypes() : getConstructor().getParameterTypes(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ConstructorOrMethod other = (ConstructorOrMethod) obj; if (getConstructor() == null) { if (other.getConstructor() != null) return false; } else if (!getConstructor().equals(other.getConstructor())) return false; if (getMethod() == null) { if (other.getMethod() != null) return false; } else if (!getMethod().equals(other.getMethod())) return false; return true; }
public Class<?> getDeclaringClass() { return getMethod() != null ? getMethod().getDeclaringClass() : getConstructor().getDeclaringClass(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ConstructorOrMethod other = (ConstructorOrMethod) obj; if (getConstructor() == null) { if (other.getConstructor() != null) return false; } else if (!getConstructor().equals(other.getConstructor())) return false; if (getMethod() == null) { if (other.getMethod() != null) return false; } else if (!getMethod().equals(other.getMethod())) return false; return true; }
@Override public <A extends IAnnotation> A findAnnotation(ConstructorOrMethod com, Class<A> annotationClass) { if (com.getConstructor() != null) { return findAnnotation(com.getConstructor(), annotationClass); } if (com.getMethod() != null) { return findAnnotation(com.getMethod(), annotationClass); } return null; }
public Class[] getParameterTypes() { return getMethod() != null ? getMethod().getParameterTypes() : getConstructor().getParameterTypes(); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((getConstructor() == null) ? 0 : getConstructor().hashCode()); result = prime * result + ((getMethod() == null) ? 0 : getMethod().hashCode()); return result; }
public Class<?> getDeclaringClass() { return getMethod() != null ? getMethod().getDeclaringClass() : getConstructor().getDeclaringClass(); }
public String getName() { return getMethod() != null ? getMethod().getName() : getConstructor().getName(); }
@Override public <A extends IAnnotation> A findAnnotation( ConstructorOrMethod com, Class<A> annotationClass) { if (com.getConstructor() != null) { return findAnnotation(com.getConstructor(), annotationClass); } if (com.getMethod() != null) { return findAnnotation(com.getMethod(), annotationClass); } return null; }
parameters.add(com.getMethod()); } else if (cls.equals(Constructor.class)) { parameters.add(com.getConstructor()); } else if (cls.equals(ConstructorOrMethod.class)) { parameters.add(com);
@DataProvider(name = "dp1") public static Object[][] createData1(ConstructorOrMethod cOrM) { Assert.assertEquals(cOrM.getDeclaringClass(), ConstructorOrMethodSample.class); Assert.assertNull(cOrM.getMethod()); Assert.assertNotNull(cOrM.getConstructor()); Constructor c = cOrM.getConstructor(); Assert.assertNotNull(c.getAnnotation(Factory.class)); Assert.assertEquals(c.getParameterTypes().length, 1); Assert.assertEquals(c.getParameterTypes()[0], String.class); return new Object[][] {{"0"}, {"1"}}; }
@DataProvider(name = "dp2") public Object[][] createData2(ConstructorOrMethod cOrM) { Assert.assertEquals(cOrM.getDeclaringClass(), ConstructorOrMethodSample.class); Assert.assertNotNull(cOrM.getMethod()); Assert.assertNull(cOrM.getConstructor()); Method m = cOrM.getMethod(); Assert.assertEquals(m.getName(), "test2"); return new Object[][] {{"Cedric" + s}, {"Alois" + s}}; }
private static Parameter[] extractParameters(ConstructorOrMethod method) { if (method.getMethod() != null) { return ReflectionRecipes.getMethodParameters(method.getMethod()); } return ReflectionRecipes.getConstructorParameters(method.getConstructor()); }
private static String[] extractOptionalValues( IAnnotationFinder finder, ConstructorOrMethod consMethod) { if (consMethod.getMethod() != null) { return finder.findOptionalValues(consMethod.getMethod()); } return finder.findOptionalValues(consMethod.getConstructor()); }
@DataProvider(name = "cookie-master") public static Object[][] cookies(ConstructorOrMethod method) { TestInfo value; if (method.getConstructor() != null) { value = (TestInfo) method.getConstructor().getAnnotation(TestInfo.class); } else { value = method.getMethod().getAnnotation(TestInfo.class); } String name = value.name(); if ("glutton".equalsIgnoreCase(name)) { return new Object[][] {{"oreo", 200}}; } if ("nibbler".equalsIgnoreCase(name)) { return new Object[][] {{"marie-gold", 10}}; } return new Object[][] { {"oreo", 200}, {"marie-gold", 10} }; } }
Object instance; if (objectFactory instanceof IObjectFactory) { instance = ((IObjectFactory) objectFactory).newInstance(com.getConstructor(), parameters); } else if (objectFactory instanceof IObjectFactory2) { instance = ((IObjectFactory2) objectFactory).newInstance(com.getDeclaringClass());
result = AnnotationHelper.findFactory(finder, m.getConstructor());