Skip to content

Commit

Permalink
Add tests for inherited ScalarFn subclasses.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibzib committed Dec 23, 2020
1 parent 3b593dc commit b8d6204
Showing 1 changed file with 46 additions and 0 deletions.
Expand Up @@ -44,6 +44,16 @@ public void testGetApplyMethod() throws InvocationTargetException, IllegalAccess
assertEquals(Long.valueOf(25L), result);
}

@Test
@SuppressWarnings("nullness") // If result is null, test will fail as expected.
public void testGetApplyMethodOverride()
throws InvocationTargetException, IllegalAccessException {
IncrementFnChild incrementFn = new IncrementFnChild();
Method method = ScalarFnReflector.getApplyMethod(incrementFn);
@Nullable Object result = method.invoke(incrementFn, Long.valueOf(24L));
assertEquals(Long.valueOf(26L), result);
}

@Test
@SuppressWarnings("nullness") // If result is null, test will fail as expected.
public void testGetApplyMethodStatic() throws InvocationTargetException, IllegalAccessException {
Expand All @@ -52,6 +62,20 @@ public void testGetApplyMethodStatic() throws InvocationTargetException, Illegal
assertEquals(Long.valueOf(25L), result);
}

@Test
public void testDifferentMethodNameThrowsIllegalArgumentException() {
thrown.expect(instanceOf(IllegalArgumentException.class));
thrown.expectMessage("Found multiple methods annotated with @ApplyMethod.");
ScalarFnReflector.getApplyMethod(new IncrementFnDifferentMethodName());
}

@Test
public void testDifferentMethodSignatureThrowsIllegalArgumentException() {
thrown.expect(instanceOf(IllegalArgumentException.class));
thrown.expectMessage("Found multiple methods annotated with @ApplyMethod.");
ScalarFnReflector.getApplyMethod(new IncrementFnDifferentSignature());
}

@Test
public void testMissingAnnotationThrowsIllegalArgumentException() {
thrown.expect(instanceOf(IllegalArgumentException.class));
Expand All @@ -73,13 +97,35 @@ public Long increment(Long i) {
}
}

static class IncrementFnChild extends IncrementFn {
@ApplyMethod
@Override
public Long increment(Long i) {
return i + 2;
}
}

static class IncrementFnWithStaticMethod extends ScalarFn {
@ApplyMethod
public static Long increment(Long i) {
return i + 1;
}
}

static class IncrementFnDifferentMethodName extends IncrementFn {
@ApplyMethod
public Long differentMethod(Long i) {
return i + 2;
}
}

static class IncrementFnDifferentSignature extends IncrementFn {
@ApplyMethod
public Long increment(String s) {
return 0L;
}
}

static class IncrementFnMissingAnnotation extends ScalarFn {
public Long increment(Long i) {
return i + 1;
Expand Down

0 comments on commit b8d6204

Please sign in to comment.