@Test public void testNewTrackerWrongNumArguments() throws Exception { thrown.expectMessage("Must have a single argument"); DoFnSignatures.analyzeNewTrackerMethod( errors(), TypeDescriptor.of(FakeDoFn.class), new AnonymousMethod() { private SomeRestrictionTracker method(SomeRestriction restriction, Object extra) { return null; } }.getMethod()); }
@Test public void testNewTrackerInconsistent() throws Exception { thrown.expectMessage( "Returns SomeRestrictionTracker, " + "but must return a subtype of RestrictionTracker<String, ?>"); DoFnSignatures.analyzeNewTrackerMethod( errors(), TypeDescriptor.of(FakeDoFn.class), new AnonymousMethod() { private SomeRestrictionTracker method(String restriction) { return null; } }.getMethod()); } }
static DoFnSignature.ProcessElementMethod analyzeProcessElementMethod(AnonymousMethod method) throws Exception { return DoFnSignatures.analyzeProcessElementMethod( errors(), TypeDescriptor.of(FakeDoFn.class), method.getMethod(), TypeDescriptor.of(Integer.class), TypeDescriptor.of(String.class), FnAnalysisContext.create()); } }
@Test public void testSplitRestrictionReturnsWrongType() throws Exception { thrown.expectMessage( "Third argument must be DoFn.OutputReceiver<SomeRestriction>, " + "but is DoFn.OutputReceiver<String>"); DoFnSignatures.analyzeSplitRestrictionMethod( errors(), TypeDescriptor.of(FakeDoFn.class), new AnonymousMethod() { void method( Integer element, SomeRestriction restriction, DoFn.OutputReceiver<String> receiver) {} }.getMethod(), TypeDescriptor.of(Integer.class)); }
@Test public void testSplitRestrictionWrongNumArguments() throws Exception { thrown.expectMessage("Must have exactly 3 arguments"); DoFnSignatures.analyzeSplitRestrictionMethod( errors(), TypeDescriptor.of(FakeDoFn.class), new AnonymousMethod() { private void method( Integer element, SomeRestriction restriction, DoFn.OutputReceiver<SomeRestriction> receiver, Object extra) {} }.getMethod(), TypeDescriptor.of(Integer.class)); }
@Test public void testSplitRestrictionWrongElementArgument() throws Exception { class BadFn { private List<SomeRestriction> splitRestriction(String element, SomeRestriction restriction) { return null; } } thrown.expectMessage("First argument must be the element type Integer"); DoFnSignatures.analyzeSplitRestrictionMethod( errors(), TypeDescriptor.of(FakeDoFn.class), new AnonymousMethod() { void method( String element, SomeRestriction restriction, DoFn.OutputReceiver<SomeRestriction> receiver) {} }.getMethod(), TypeDescriptor.of(Integer.class)); }
@Test public void testBadExtraContext() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage( "Must take a single argument of type DoFn<Integer, String>.StartBundleContext"); DoFnSignatures.analyzeStartBundleMethod( errors(), TypeDescriptor.of(FakeDoFn.class), new DoFnSignaturesTestUtils.AnonymousMethod() { void method(DoFn<Integer, String>.StartBundleContext c, int n) {} }.getMethod(), TypeDescriptor.of(Integer.class), TypeDescriptor.of(String.class)); }