Class LambdaAndReferenceTck

java.lang.Object
io.micronaut.sourcegen.bytecode.tck.AbstractByteCodeWriterTck
io.micronaut.sourcegen.bytecode.tck.LambdaAndReferenceTck

public abstract class LambdaAndReferenceTck extends AbstractByteCodeWriterTck
Lambdas and method references: the functional interface method they implement, the receiver they capture and the scope of the type variables they use.

A backend runs these tests by extending this class and implementing AbstractByteCodeWriterTck.write(io.micronaut.sourcegen.model.ObjectDef).

Since:
2.3
  • Constructor Details

    • LambdaAndReferenceTck

      public LambdaAndReferenceTck()
  • Method Details

    • referencesCaptureTheirReceiverBeforeItChanges

      @ParameterizedTest(name="a reference to a {0} receiver captures it before it changes, calling next() {1} time(s)") @CsvSource({"field, 0","local, 0","result, 1"}) public void referencesCaptureTheirReceiverBeforeItChanges(String kind, int receiverReads) throws Exception
      A bound method reference evaluates its receiver once, where it is created, so replacing the receiver later does not change what the reference calls. A receiver that is the result of a call is read exactly once.
      Parameters:
      kind - What the receiver is: a field, a local or the result of a call
      receiverReads - How many times creating the reference calls the method that returns the receiver
      Throws:
      Exception - If the generated program cannot be loaded or invoked
      Since:
      2.3
    • varargsReferenceBoundToAFieldCapturesItsValue

      @Test public void varargsReferenceBoundToAFieldCapturesItsValue() throws Exception
      A reference to a method of variable arity bound to a field - Function<String, String> f = this.format::formatted - reads the field once, where it is created: assigning the field afterwards does not change what the reference calls, and a null field fails where it is created.
      Throws:
      Exception - If the generated class cannot be used
      Since:
      2.3
    • boundReferenceRejectsANullReceiverWhereItIsCreated

      @Test public void boundReferenceRejectsANullReceiverWhereItIsCreated() throws Exception
      A bound reference checks its receiver where it is created, as `target::apply` does in source, not where the reference is invoked.
      Throws:
      Exception - If the generated class cannot be used
      Since:
      2.3
    • superReferenceCallsTheMethodOfTheSuperclass

      @Test public void superReferenceCallsTheMethodOfTheSuperclass() throws Exception
      A reference through `super` calls the method of the superclass, not the override of the class that creates it.
      Throws:
      Exception - If the generated class cannot be used
      Since:
      2.3
    • superReferenceCanDiscardTheReferencedResult

      @Test public void superReferenceCanDiscardTheReferencedResult() throws Exception
      A void functional target discards the result of a reference through super.
      Throws:
      Exception - If the generated reference cannot be used
      Since:
      2.3
    • explicitGenericMethodReferenceKeepsErasedDescriptor

      @Test public void explicitGenericMethodReferenceKeepsErasedDescriptor() throws Exception
      Throws:
      Exception
    • boundMethodReferenceUsesTheTargetsClassScope

      @Test public void boundMethodReferenceUsesTheTargetsClassScope() throws Exception
      Throws:
      Exception
    • staticMethodReferenceUsesTheTargetsMethodScope

      @Test public void staticMethodReferenceUsesTheTargetsMethodScope() throws Exception
      Throws:
      Exception
    • lambdaCaptureRetainsTheEnclosingMethodsBound

      @Test public void lambdaCaptureRetainsTheEnclosingMethodsBound() throws Exception
      Throws:
      Exception
    • genericConstructorReferenceUsesConstructorScope

      @Test public void genericConstructorReferenceUsesConstructorScope() throws Exception
      Throws:
      Exception
    • genericMethodBoundReferenceAcceptsATypeVariableReceiver

      @Test public void genericMethodBoundReferenceAcceptsATypeVariableReceiver() throws Exception
      Throws:
      Exception
    • genericVarargsMethodReferencePacksItsArguments

      @Test public void genericVarargsMethodReferencePacksItsArguments() throws Exception
      Throws:
      Exception
    • voidAdaptedGenericSuperReferenceDiscardsItsReturnValue

      @Test public void voidAdaptedGenericSuperReferenceDiscardsItsReturnValue() throws Exception
      Throws:
      Exception
    • methodReferenceSamUsesTheEnclosingMethodBound

      @Test public void methodReferenceSamUsesTheEnclosingMethodBound() throws Exception
      Throws:
      Exception
    • methodReferenceSamMethodBoundShadowsClassBound

      @Test public void methodReferenceSamMethodBoundShadowsClassBound() throws Exception
      Throws:
      Exception
    • lambdaSamUsesTheEnclosingMethodBound

      @Test public void lambdaSamUsesTheEnclosingMethodBound() throws Exception
      Throws:
      Exception
    • methodReferenceByNameToAnObjectMethodOfAnInterfaceReceiver

      @Test public void methodReferenceByNameToAnObjectMethodOfAnInterfaceReceiver() throws Exception
      Throws:
      Exception
    • methodReferenceByNameToAMethodWithABridge

      @Test public void methodReferenceByNameToAMethodWithABridge() throws Exception
      Throws:
      Exception