Class BTest

java.lang.Object
org.blocktest.BTest

public class BTest extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static BTest
     
  • Method Summary

    Modifier and Type
    Method
    Description
    args(Object... value)
    For a given lambda test, provide a list of values as the arguments to the lambda function.
    static BTest
    Declares a block test.
    static BTest
    Declares a block test with a name.
    checkEq(Object actual, Object expected)
    Check that the actual object is equal to the expected object.
    checkEq(Object actual, Object expected, Object delta)
    Check that the actual object is equal to the expected object within a delta.
    Check that the given value or expression is false.
    checkFlow(Flow... value)
    Check the flow of the block under test, as a sequence of Flow objects.
    Checks that the return value of the block under test is equal to the expected value.
    checkReturnEq(Object expected, Object delta)
    Checks that the return value of the block under test is equal to the expected value within a delta.
    Check that the return value of the block or lambda is false.
    Check that the return value of the block or lambda is true.
    Check that the given value or expression is true.
    delay(long time)
    TODO: Need a real example, not sure what this does.
    end()
    TODO: What is the purpose of this?
    end(Object value)
    Deprecated, use end(EndAt value) instead.
    end(Object value, boolean endAfter)
    Deprecated, use end(EndAt value, boolean endAfter) instead.
    end(EndAt value)
    Set the stoppoint of the block test to be at the value specified by the EndAt enum.
    end(EndAt value, boolean endAfter)
    Set the stoppoint of the block test to be at the value specified by the EndAt enum, and decide whether to include the construct specified by the EndAt enum.
    end(EndAt value, int at)
    Set the stoppoint of the block test to be at the value specified by the EndAt enum, and at the specified instance.
    end(EndAt value, int at, boolean endAfter)
    Set the stoppoint of the block test to be at the value specified by the EndAt enum, and at the specified instance, and decide whether to include the construct specified by the EndAt enum.
    expect(Object value)
    Check that the block or lambda under test throws an exception.
    given(Object variable, Object value)
    Assigns a value to a variable that is used in the block under test.
    given(Object variable, Object value, Object type)
    Assigns a value to a variable that is used in the block under test, with a specified type.
    static boolean
    TODO: Never seen this used.
    static BTest
    Declares a lambda test.
    static BTest
    Declares a lambda test with a name.
    mock(Object... value)
    Mock the method calls of the block or lambda under test.
    mockStr(Object... value)
    TODO: What does this do?
    noInit(Object... variables)
    Specifies that for the given list of variables, do not initialize their values by inferring from context.
    setup(Runnable setupFunction)
    Set up the right environment to test a block or lambda by executing the Runnable.
    setup(String setupFunction)
     
    start(Object value)
    Deprecated, use start(EndAt value) instead.
    start(Object value, boolean endAfter)
    Deprecated, use start(EndAt value, boolean endAfter) instead.
    start(EndAt value)
    Set the start point of the block test to be at the value specified by the EndAt enum.
    start(EndAt value, boolean endAfter)
    Set the start point of the block test to be at the value specified by the EndAt enum, and decide whether to include the construct specified by the EndAt enum.
    start(EndAt value, int at)
    Set the start point of the block test to be at the value specified by the EndAt enum, and at the specified instance.
    start(EndAt value, int at, boolean endAfter)
    Set the start point of the block test to be at the value specified by the EndAt enum, and at the specified instance, and decide whether to include the construct specified by the EndAt enum.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • btest

      public static BTest btest
  • Method Details

    • blocktest

      public static BTest blocktest()
      Declares a block test. It should be followed by assignment and assertions.
      Returns:
      a BTest object to chain assignment, assertions, and stoppoints.
    • lambdatest

      public static BTest lambdatest()
      Declares a lambda test. It should be followed by assignment and assertions.
      Returns:
      a BTest object to chain assignment, assertions, and stoppoints.
    • blocktest

      public static BTest blocktest(String name)
      Declares a block test with a name. e.g. blocktest("test addition")
      Parameters:
      name - the name of the test.
      Returns:
      a BTest object to chain assignment, assertions, and stoppoints.
    • lambdatest

      public static BTest lambdatest(String name)
      Declares a lambda test with a name. e.g. lambdatest("test transformation")
      Parameters:
      name - the name of the test.
      Returns:
      a BTest object to chain assignment, assertions, and stoppoints.
    • checkEq

      public BTest checkEq(Object actual, Object expected)
      Check that the actual object is equal to the expected object. e.g. checkEq(lastChunkSize, 1048576) Sometimes the actual object is a variable that is not yet declared in the original code, one can use a String variable representing its name to refer to it. e.g. checkEq("lastChunkSize", 1048576)
      Parameters:
      actual - the actual object, or a String representing the name of the actual object.
      expected - the expected object.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • checkEq

      public BTest checkEq(Object actual, Object expected, Object delta)
      Check that the actual object is equal to the expected object within a delta. e.g. checkEq(A[4][1], -136, 1)
      Parameters:
      actual - the actual object, or a String representing the name of the actual object.
      expected - the expected object.
      delta - the delta within which the actual and expected objects should be equal.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • checkReturnEq

      public BTest checkReturnEq(Object expected)
      Checks that the return value of the block under test is equal to the expected value. e.g. checkReturnEq(-1)
      Parameters:
      expected - the expected return value.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • checkReturnEq

      public BTest checkReturnEq(Object expected, Object delta)
      Checks that the return value of the block under test is equal to the expected value within a delta. e.g. checkReturnEq(-2, 0.5)
      Parameters:
      expected - the expected return value.
      delta - the delta within which the return value should be equal to the expected value.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • given

      public BTest given(Object variable, Object value)
      Assigns a value to a variable that is used in the block under test. e.g. given(bufferSize, 4096)
      Parameters:
      variable - the variable to assign the value to.
      value - the value to assign to the variable.
      Returns:
      a BTest object to chain additional assignments, assertions, and stoppoints.
    • noInit

      public BTest noInit(Object... variables)
      Specifies that for the given list of variables, do not initialize their values by inferring from context. e.g. noInit(lineReader, context)
      Parameters:
      variables - a list of variables that should not be initialized.
      Returns:
      a BTest object to chain additional assignments, assertions, and stoppoints.
    • args

      public BTest args(Object... value)
      For a given lambda test, provide a list of values as the arguments to the lambda function. (Not sure if I understand it correctly). e.g. args(new File(path), true)
      Parameters:
      value -
      Returns:
    • given

      public BTest given(Object variable, Object value, Object type)
      Assigns a value to a variable that is used in the block under test, with a specified type. This is because sometimes the type cannot be easily inferred. Usually used for lambda tests. e.g. given("config", Configuration.getDefault(), "Configuration")
      Parameters:
      variable - the variable to assign the value to.
      value - the value to assign to the variable.
      type - the type of the variable, currently using Strings to represent types.
      Returns:
      a BTest object to chain additional assignments, assertions, and stoppoints.
    • setup

      public BTest setup(String setupFunction)
    • setup

      public BTest setup(Runnable setupFunction)
      Set up the right environment to test a block or lambda by executing the Runnable. e.g. setup(() -> { setupOnce(); setupTwice(); })
      Parameters:
      setupFunction - a Runnable object that contains necessary setups for the block or lambda under test.
      Returns:
      a BTest object to chain additional assignments, assertions, and stoppoints.
    • checkTrue

      public BTest checkTrue(Object value)
      Check that the given value or expression is true. e.g. checkTrue(isEmpty(list))
      Parameters:
      value - the value or expression to check.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • checkFalse

      public BTest checkFalse(Object value)
      Check that the given value or expression is false. e.g. checkFalse(threshold > 0 && threshold < 1)
      Parameters:
      value - the value or expression to check.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • checkReturnTrue

      public BTest checkReturnTrue()
      Check that the return value of the block or lambda is true. e.g. blocktest().checkReturnTrue() TODO: Never seen a real usage of this case.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • checkReturnFalse

      public BTest checkReturnFalse()
      Check that the return value of the block or lambda is false. e.g. blocktest().checkReturnFalse() TODO: Never seen a real usage of this case.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • checkFlow

      public BTest checkFlow(Flow... value)
      Check the flow of the block under test, as a sequence of Flow objects. For instance, for this example:
       // Block test location
       if (first) {
           if (second) {
               // do something A
           } else {
               // do something B
           }
       } else {
           // do something C
       }
       
      One can write a block test like this: blocktest().given(first, true).given(second, false).checkFlow(IfStmt().Then().IfStmt().Else()) to check that the flow of the block under test is: 1) Check the first condition; 2) Execute the then branch of the first if statement; 3) Check the second condition; 4) Execute the else branch of the second if statement;
      Parameters:
      value - a sequence of Flow objects representing the expected flow.
      Returns:
      aBTest object to chain additional assertions and stoppoints.
    • expect

      public BTest expect(Object value)
      Check that the block or lambda under test throws an exception. e.g. blocktest().expect(RuntimeException.class)
      Parameters:
      value - the expected exception class.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • end

      public BTest end()
      TODO: What is the purpose of this? Ending the btest at a default location?
    • end

      public BTest end(Object value)
      Deprecated, use end(EndAt value) instead.
      Parameters:
      value -
      Returns:
    • end

      public BTest end(EndAt value)
      Set the stoppoint of the block test to be at the value specified by the EndAt enum. Block tests using .end(..) should be declared right before the block or lambda under test. e.g. blocktest()....end(FIRST_ASSIGN)
      Parameters:
      value - the end point of the block test.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • end

      public BTest end(EndAt value, int at)
      Set the stoppoint of the block test to be at the value specified by the EndAt enum, and at the specified instance. e.g. blocktest()....end(FIRST_ASSIGN, 2) means that the block test should stop at the second assignment.
      Parameters:
      value - the end point of the block test.
      at - the instance of the end point.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • end

      public BTest end(Object value, boolean endAfter)
      Deprecated, use end(EndAt value, boolean endAfter) instead.
      Parameters:
      value -
      endAfter -
      Returns:
    • end

      public BTest end(EndAt value, boolean endAfter)
      Set the stoppoint of the block test to be at the value specified by the EndAt enum, and decide whether to include the construct specified by the EndAt enum. e.g. blocktest()....end(FIRST_BLOCK, true) means that the block test should stop after the first block. Otherwise, it will stop right before the first block that follows.
      Parameters:
      value - the end point of the block test.
      endAfter - whether to include the construct specified by the EndAt enum.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • end

      public BTest end(EndAt value, int at, boolean endAfter)
      Set the stoppoint of the block test to be at the value specified by the EndAt enum, and at the specified instance, and decide whether to include the construct specified by the EndAt enum. e.g. blocktest()....end(FIRST_BLOCK, 2, true) means that the block test should stop after the second block.
      Parameters:
      value - the end point of the block test.
      at - the instance of the end point.
      endAfter - whether to include the construct specified by the EndAt enum.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • start

      public BTest start(Object value)
      Deprecated, use start(EndAt value) instead.
      Parameters:
      value -
      Returns:
    • start

      public BTest start(EndAt value)
      Set the start point of the block test to be at the value specified by the EndAt enum. e.g. blocktest()....start(FIRST_ASSIGN)
      Parameters:
      value - the start point of the block test.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • start

      public BTest start(EndAt value, int at)
      Set the start point of the block test to be at the value specified by the EndAt enum, and at the specified instance. e.g. blocktest()....start(FIRST_ASSIGN, 2) means that the block test should start at the second assignment.
      Parameters:
      value - the start point of the block test.
      at - the instance of the start point.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • start

      public BTest start(Object value, boolean endAfter)
      Deprecated, use start(EndAt value, boolean endAfter) instead.
      Parameters:
      value -
      endAfter -
      Returns:
    • start

      public BTest start(EndAt value, boolean endAfter)
      Set the start point of the block test to be at the value specified by the EndAt enum, and decide whether to include the construct specified by the EndAt enum. e.g. blocktest()....start(FIRST_BLOCK, true) means that the block test should start after the first block.
      Parameters:
      value - the start point of the block test.
      endAfter - whether to include the construct specified by the EndAt enum.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • start

      public BTest start(EndAt value, int at, boolean endAfter)
      Set the start point of the block test to be at the value specified by the EndAt enum, and at the specified instance, and decide whether to include the construct specified by the EndAt enum. e.g. blocktest()....start(FIRST_BLOCK, 2, true) means that the block test should start after the second block.
      Parameters:
      value - the start point of the block test.
      at - the instance of the start point.
      endAfter - whether to include the construct specified by the EndAt enum.
      Returns:
      a BTest object to chain additional assertions and stoppoints.
    • mock

      public BTest mock(Object... value)
      Mock the method calls of the block or lambda under test. This is similar to the given clause, but for method calls. e.g. blocktest().given(a, 1).mock("someCall(p)", 1).checkReturnTrue();
      Parameters:
      value - the method calls to mock.
      Returns:
      a BTest object to chain additional assignments, assertions, and stoppoints.
    • mockStr

      public BTest mockStr(Object... value)
      TODO: What does this do?
    • delay

      public BTest delay(long time)
      TODO: Need a real example, not sure what this does.
    • group

      public static boolean group()
      TODO: Never seen this used. And what does group() mean for block tests, where there might be multiple conditions in different places?