Class List Method List File List

# Class: VertxUnit::TestContext

Inherits:
  Object
  - Object
  - VertxUnit::TestContext
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb

## Overview

The test context is used for performing test assertions and manage the completion of the test. This context is provided by vertx-unit as argument of the test case.

## Constant Summary

@@j_api_type =

      Object.new

## Class Method Summary (collapse)

- + (Boolean) accept?(obj)
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)

## Instance Method Summary (collapse)

- - (self) assert_equals(expected = nil, actual = nil, message = nil)
  Assert the expected argument is equals to the actual argument.
- - (self) assert_false(condition = nil, message = nil)
  Assert the specified condition is false.
- - (self) assert_in_range(expected = nil, actual = nil, delta = nil, message = nil)
  Asserts that the expected double argument is equals to the actual double argument within a positive delta.
- - (self) assert_not_equals(first = nil, second = nil, message = nil)
  Assert the first argument is not equals to the second argument.
- - (self) assert_not_null(expected = nil, message = nil)
  Assert the expected argument is not null.
- - (self) assert_null(expected = nil, message = nil)
  Assert the expected argument is null.
- - (self) assert_true(condition = nil, message = nil)
  Assert the specified condition is true.
- - (::VertxUnit::Async) async(count = nil)
  Create and returns a new async object, the returned async controls the completion of the test.
- - (Proc) async_assert_failure { ... }
  Creates and returns a new async handler, the returned handler controls the completion of the test.
- - (Proc) async_assert_success { ... }
  Creates and returns a new async handler, the returned handler controls the completion of the test.
- - (Proc) exception_handler
  An exception handler that will fail this context.
- - (void) fail(param_1 = nil)
  Throw a failure with the specified failure cause.
- - (Object) get(key = nil)
  Get some data from the context.
- - (Object) put(key = nil, value = nil)
  Put some data in the context.
- - (Object) remove(key = nil)
  Remove some data from the context.

## Class Method Details

### + (`Boolean`) accept?(obj)

Returns:

- (`Boolean`)

    19
    20
    21
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 19

    def @@j_api_type.accept?(obj)
      obj.class == TestContext
    end

### + (`Object`) j_api_type

    28
    29
    30
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 28

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

    31
    32
    33
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 31

    def self.j_class
      Java::IoVertxExtUnit::TestContext.java_class
    end

### + (`Object`) unwrap(obj)

    25
    26
    27
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 25

    def @@j_api_type.unwrap(obj)
      obj.j_del
    end

### + (`Object`) wrap(obj)

    22
    23
    24
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 22

    def @@j_api_type.wrap(obj)
      TestContext.new(obj)
    end

## Instance Method Details

### - (`self`) assert_equals(expected = nil, actual = nil, message = nil)

Assert the `expected` argument is equals to the `actual` argument. If the arguments are not equals an assertion error is thrown otherwise the execution continue.

Parameters:

- expected (`Object`) (defaults to: `nil`) —
  the object the actual object is supposedly equals to
- actual (`Object`) (defaults to: `nil`) —
  the actual object to test
- message (`String`) (defaults to: `nil`) —
  the failure message

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 130

    def assert_equals(expected=nil,actual=nil,message=nil)
      if ::Vertx::Util::unknown_type.accept?(expected) && ::Vertx::Util::unknown_type.accept?(actual) && !block_given? && message == nil
        @j_del.java_method(:assertEquals, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(expected),::Vertx::Util::Utils.to_object(actual))
        return self
      elsif ::Vertx::Util::unknown_type.accept?(expected) && ::Vertx::Util::unknown_type.accept?(actual) && message.class == String && !block_given?
        @j_del.java_method(:assertEquals, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class,Java::java.lang.String.java_class]).call(::Vertx::Util::Utils.to_object(expected),::Vertx::Util::Utils.to_object(actual),message)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling assert_equals(#{expected},#{actual},#{message})"
    end

### - (`self`) assert_false(condition = nil, message = nil)

Assert the specified `condition` is `false`. If the condition is `true`, an assertion error is thrown otherwise the execution continue.

Parameters:

- condition (`true`, `false`) (defaults to: `nil`) —
  the condition to assert
- message (`String`) (defaults to: `nil`) —
  the failure message

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 114

    def assert_false(condition=nil,message=nil)
      if (condition.class == TrueClass || condition.class == FalseClass) && !block_given? && message == nil
        @j_del.java_method(:assertFalse, [Java::boolean.java_class]).call(condition)
        return self
      elsif (condition.class == TrueClass || condition.class == FalseClass) && message.class == String && !block_given?
        @j_del.java_method(:assertFalse, [Java::boolean.java_class,Java::java.lang.String.java_class]).call(condition,message)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling assert_false(#{condition},#{message})"
    end

### - (`self`) assert_in_range(expected = nil, actual = nil, delta = nil, message = nil)

Asserts that the `expected` double argument is equals to the `actual` double argument within a positive delta. If the arguments do not satisfy this, an assertion error is thrown otherwise the execution continue.

Parameters:

- expected (`Float`) (defaults to: `nil`) —
  the object the actual object is supposedly equals to
- actual (`Float`) (defaults to: `nil`) —
  the actual object to test
- delta (`Float`) (defaults to: `nil`) —
  the maximum delta
- message (`String`) (defaults to: `nil`) —
  the failure message

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 148

    def assert_in_range(expected=nil,actual=nil,delta=nil,message=nil)
      if expected.class == Float && actual.class == Float && delta.class == Float && !block_given? && message == nil
        @j_del.java_method(:assertInRange, [Java::double.java_class,Java::double.java_class,Java::double.java_class]).call(::Vertx::Util::Utils.to_double(expected),::Vertx::Util::Utils.to_double(actual),::Vertx::Util::Utils.to_double(delta))
        return self
      elsif expected.class == Float && actual.class == Float && delta.class == Float && message.class == String && !block_given?
        @j_del.java_method(:assertInRange, [Java::double.java_class,Java::double.java_class,Java::double.java_class,Java::java.lang.String.java_class]).call(::Vertx::Util::Utils.to_double(expected),::Vertx::Util::Utils.to_double(actual),::Vertx::Util::Utils.to_double(delta),message)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling assert_in_range(#{expected},#{actual},#{delta},#{message})"
    end

### - (`self`) assert_not_equals(first = nil, second = nil, message = nil)

Assert the `first` argument is not equals to the `second` argument. If the arguments are equals an assertion error is thrown otherwise the execution continue.

Parameters:

- first (`Object`) (defaults to: `nil`) —
  the first object to test
- second (`Object`) (defaults to: `nil`) —
  the second object to test
- message (`String`) (defaults to: `nil`) —
  the failure message

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 164

    def assert_not_equals(first=nil,second=nil,message=nil)
      if ::Vertx::Util::unknown_type.accept?(first) && ::Vertx::Util::unknown_type.accept?(second) && !block_given? && message == nil
        @j_del.java_method(:assertNotEquals, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(first),::Vertx::Util::Utils.to_object(second))
        return self
      elsif ::Vertx::Util::unknown_type.accept?(first) && ::Vertx::Util::unknown_type.accept?(second) && message.class == String && !block_given?
        @j_del.java_method(:assertNotEquals, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class,Java::java.lang.String.java_class]).call(::Vertx::Util::Utils.to_object(first),::Vertx::Util::Utils.to_object(second),message)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling assert_not_equals(#{first},#{second},#{message})"
    end

### - (`self`) assert_not_null(expected = nil, message = nil)

Assert the `expected` argument is not `null`. If the argument is `null`, an assertion error is thrown otherwise the execution continue.

Parameters:

- expected (`Object`) (defaults to: `nil`) —
  the argument being asserted to be not null
- message (`String`) (defaults to: `nil`) —
  the failure message

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 84

    def assert_not_null(expected=nil,message=nil)
      if ::Vertx::Util::unknown_type.accept?(expected) && !block_given? && message == nil
        @j_del.java_method(:assertNotNull, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(expected))
        return self
      elsif ::Vertx::Util::unknown_type.accept?(expected) && message.class == String && !block_given?
        @j_del.java_method(:assertNotNull, [Java::java.lang.Object.java_class,Java::java.lang.String.java_class]).call(::Vertx::Util::Utils.to_object(expected),message)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling assert_not_null(#{expected},#{message})"
    end

### - (`self`) assert_null(expected = nil, message = nil)

Assert the `expected` argument is `null`. If the argument is not, an assertion error is thrown otherwise the execution continue.

Parameters:

- expected (`Object`) (defaults to: `nil`) —
  the argument being asserted to be null
- message (`String`) (defaults to: `nil`) —
  the failure message

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 69

    def assert_null(expected=nil,message=nil)
      if ::Vertx::Util::unknown_type.accept?(expected) && !block_given? && message == nil
        @j_del.java_method(:assertNull, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(expected))
        return self
      elsif ::Vertx::Util::unknown_type.accept?(expected) && message.class == String && !block_given?
        @j_del.java_method(:assertNull, [Java::java.lang.Object.java_class,Java::java.lang.String.java_class]).call(::Vertx::Util::Utils.to_object(expected),message)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling assert_null(#{expected},#{message})"
    end

### - (`self`) assert_true(condition = nil, message = nil)

Assert the specified `condition` is `true`. If the condition is `false`, an assertion error is thrown otherwise the execution continue.

Parameters:

- condition (`true`, `false`) (defaults to: `nil`) —
  the condition to assert
- message (`String`) (defaults to: `nil`) —
  the failure message

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 99

    def assert_true(condition=nil,message=nil)
      if (condition.class == TrueClass || condition.class == FalseClass) && !block_given? && message == nil
        @j_del.java_method(:assertTrue, [Java::boolean.java_class]).call(condition)
        return self
      elsif (condition.class == TrueClass || condition.class == FalseClass) && message.class == String && !block_given?
        @j_del.java_method(:assertTrue, [Java::boolean.java_class,Java::java.lang.String.java_class]).call(condition,message)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling assert_true(#{condition},#{message})"
    end

### - (`::VertxUnit::Async`) async(count = nil)

Create and returns a new async object, the returned async controls the completion of the test. This async operation completes when the Async#complete is called `count` times.

The test case will complete when all the async objects have their Async#complete method called at least once.

This method shall be used for creating asynchronous exit points for the executed test.

Parameters:

- count (`Fixnum`) (defaults to: `nil`)

Returns:

- (`::VertxUnit::Async`) —
  the async instance

Raises:

- (`ArgumentError`)

    200
    201
    202
    203
    204
    205
    206
    207
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 200

    def async(count=nil)
      if !block_given? && count == nil
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:async, []).call(),::VertxUnit::Async)
      elsif count.class == Fixnum && !block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:async, [Java::int.java_class]).call(count),::VertxUnit::Async)
      end
      raise ArgumentError, "Invalid arguments when calling async(#{count})"
    end

### - (`Proc`) async_assert_failure { ... }

Creates and returns a new async handler, the returned handler controls the completion of the test.

When the returned handler is called back with a failed result it completes the async operation.

When the returned handler is called back with a succeeded result it fails the test.

Yields:

- the cause handler

Returns:

- (`Proc`) —
  the async result handler

Raises:

- (`ArgumentError`)

    234
    235
    236
    237
    238
    239
    240
    241
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 234

    def async_assert_failure
      if !block_given?
        return ::Vertx::Util::Utils.to_async_result_handler_proc(@j_del.java_method(:asyncAssertFailure, []).call()) { |val| ::Vertx::Util::Utils.to_object(val) }
      elsif block_given?
        return ::Vertx::Util::Utils.to_async_result_handler_proc(@j_del.java_method(:asyncAssertFailure, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)) }))) { |val| ::Vertx::Util::Utils.to_object(val) }
      end
      raise ArgumentError, "Invalid arguments when calling async_assert_failure()"
    end

### - (`Proc`) async_assert_success { ... }

Creates and returns a new async handler, the returned handler controls the completion of the test.

When the returned handler is called back with a succeeded result it invokes the `resultHandler` argument with the async result. The test completes after the result handler is invoked and does not fails.

When the returned handler is called back with a failed result it fails the test with the cause of the failure.

Note that the result handler can create other async objects during its invocation that would postpone the completion of the test case until those objects are resolved.

Yields:

- the result handler

Returns:

- (`Proc`) —
  the async result handler

Raises:

- (`ArgumentError`)

    219
    220
    221
    222
    223
    224
    225
    226
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 219

    def async_assert_success
      if !block_given?
        return ::Vertx::Util::Utils.to_async_result_handler_proc(@j_del.java_method(:asyncAssertSuccess, []).call()) { |val| ::Vertx::Util::Utils.to_object(val) }
      elsif block_given?
        return ::Vertx::Util::Utils.to_async_result_handler_proc(@j_del.java_method(:asyncAssertSuccess, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_object(event)) }))) { |val| ::Vertx::Util::Utils.to_object(val) }
      end
      raise ArgumentError, "Invalid arguments when calling async_assert_success()"
    end

### - (`Proc`) exception_handler

Returns an exception handler that will fail this context

Returns:

- (`Proc`) —
  an exception handler that will fail this context

Raises:

- (`ArgumentError`)

    243
    244
    245
    246
    247
    248
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 243

    def exception_handler
      if !block_given?
        return ::Vertx::Util::Utils.to_handler_proc(@j_del.java_method(:exceptionHandler, []).call()) { |val| ::Vertx::Util::Utils.to_throwable(val) }
      end
      raise ArgumentError, "Invalid arguments when calling exception_handler()"
    end

### - (`void`) fail - (`void`) fail(message) - (`void`) fail(cause)

This method returns an undefined value.

Throw a failure with the specified failure `cause`.

Overloads:

- - (`void`) fail(message)

  Parameters:

  - message (`String`) —
    the failure message
- - (`void`) fail(cause)

  Parameters:

  - cause (`Exception`) —
    the failure cause

Raises:

- (`ArgumentError`)

    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 181

    def fail(param_1=nil)
      if !block_given? && param_1 == nil
        return @j_del.java_method(:fail, []).call()
      elsif param_1.class == String && !block_given?
        return @j_del.java_method(:fail, [Java::java.lang.String.java_class]).call(param_1)
      elsif param_1.is_a?(Exception) && !block_given?
        return @j_del.java_method(:fail, [Java::JavaLang::Throwable.java_class]).call(::Vertx::Util::Utils.to_throwable(param_1))
      end
      raise ArgumentError, "Invalid arguments when calling fail(#{param_1})"
    end

### - (`Object`) get(key = nil)

Get some data from the context.

Parameters:

- key (`String`) (defaults to: `nil`) —
  the key of the data

Returns:

- (`Object`) —
  the data

Raises:

- (`ArgumentError`)

    37
    38
    39
    40
    41
    42
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 37

    def get(key=nil)
      if key.class == String && !block_given?
        return ::Vertx::Util::Utils.from_object(@j_del.java_method(:get, [Java::java.lang.String.java_class]).call(key))
      end
      raise ArgumentError, "Invalid arguments when calling get(#{key})"
    end

### - (`Object`) put(key = nil, value = nil)

Put some data in the context.

This can be used to share data between different tests and before/after phases.

Parameters:

- key (`String`) (defaults to: `nil`) —
  the key of the data
- value (`Object`) (defaults to: `nil`) —
  the data

Returns:

- (`Object`) —
  the previous object when it exists

Raises:

- (`ArgumentError`)

    49
    50
    51
    52
    53
    54
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 49

    def put(key=nil,value=nil)
      if key.class == String && ::Vertx::Util::unknown_type.accept?(value) && !block_given?
        return ::Vertx::Util::Utils.from_object(@j_del.java_method(:put, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class]).call(key,::Vertx::Util::Utils.to_object(value)))
      end
      raise ArgumentError, "Invalid arguments when calling put(#{key},#{value})"
    end

### - (`Object`) remove(key = nil)

Remove some data from the context.

Parameters:

- key (`String`) (defaults to: `nil`) —
  the key to remove

Returns:

- (`Object`) —
  the removed object when it exists

Raises:

- (`ArgumentError`)

    58
    59
    60
    61
    62
    63
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-unit/test_context.rb', line 58

    def remove(key=nil)
      if key.class == String && !block_given?
        return ::Vertx::Util::Utils.from_object(@j_del.java_method(:remove, [Java::java.lang.String.java_class]).call(key))
      end
      raise ArgumentError, "Invalid arguments when calling remove(#{key})"
    end