Class: VertxUnit::TestContext

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/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)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


20
21
22
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 20

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

+ (Object) j_api_type



29
30
31
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 29

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



32
33
34
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 32

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

+ (Object) unwrap(obj)



26
27
28
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 26

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

+ (Object) wrap(obj)



23
24
25
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 23

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

Instance Method Details

- (self) assertEquals(expected, actual) - (self) assertEquals(expected, actual, message)

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.

Overloads:

  • - (self) assertEquals(expected, actual)

    Parameters:

    • expected (Object)
      the object the actual object is supposedly equals to
    • actual (Object)
      the actual object to test
  • - (self) assertEquals(expected, actual, message)

    Parameters:

    • expected (Object)
      the object the actual object is supposedly equals to
    • actual (Object)
      the actual object to test
    • message (String)
      the failure message

Returns:

  • (self)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 119

def assert_equals(*args)
  if ::Vertx::Util::unknown_type.accept?(args[0]) && ::Vertx::Util::unknown_type.accept?(args[1]) && !block_given? && args[2] == nil
    @j_del.java_method(:assertEquals, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(args[0]),::Vertx::Util::Utils.to_object(args[1]))
    return self
  elsif ::Vertx::Util::unknown_type.accept?(args[0]) && ::Vertx::Util::unknown_type.accept?(args[1]) && args[2].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(args[0]),::Vertx::Util::Utils.to_object(args[1]),args[2])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling assert_equals(#{args[0]},#{args[1]},#{args[2]})"
  end
end

- (self) assertFalse(condition) - (self) assertFalse(condition, message)

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

Overloads:

  • - (self) assertFalse(condition)

    Parameters:

    • condition (true, false)
      the condition to assert
  • - (self) assertFalse(condition, message)

    Parameters:

    • condition (true, false)
      the condition to assert
    • message (String)
      the failure message

Returns:

  • (self)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 70

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

- (self) assertInRange(expected, actual, delta) - (self) assertInRange(expected, actual, delta, message)

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.

Overloads:

  • - (self) assertInRange(expected, actual, delta)

    Parameters:

    • expected (Float)
      the object the actual object is supposedly equals to
    • actual (Float)
      the actual object to test
    • delta (Float)
      the maximum delta
  • - (self) assertInRange(expected, actual, delta, message)

    Parameters:

    • expected (Float)
      the object the actual object is supposedly equals to
    • actual (Float)
      the actual object to test
    • delta (Float)
      the maximum delta
    • message (String)
      the failure message

Returns:

  • (self)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 48

def assert_in_range(*args)
  if args[0].class == Float && args[1].class == Float && args[2].class == Float && !block_given? && args[3] == nil
    @j_del.java_method(:assertInRange, [Java::double.java_class,Java::double.java_class,Java::double.java_class]).call(::Vertx::Util::Utils.to_double(args[0]),::Vertx::Util::Utils.to_double(args[1]),::Vertx::Util::Utils.to_double(args[2]))
    return self
  elsif args[0].class == Float && args[1].class == Float && args[2].class == Float && args[3].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(args[0]),::Vertx::Util::Utils.to_double(args[1]),::Vertx::Util::Utils.to_double(args[2]),args[3])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling assert_in_range(#{args[0]},#{args[1]},#{args[2]},#{args[3]})"
  end
end

- (self) assertNotEquals(first, second) - (self) assertNotEquals(first, second, message)

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.

Overloads:

  • - (self) assertNotEquals(first, second)

    Parameters:

    • first (Object)
      the first object to test
    • second (Object)
      the second object to test
  • - (self) assertNotEquals(first, second, message)

    Parameters:

    • first (Object)
      the first object to test
    • second (Object)
      the second object to test
    • message (String)
      the failure message

Returns:

  • (self)


369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 369

def assert_not_equals(*args)
  if ::Vertx::Util::unknown_type.accept?(args[0]) && ::Vertx::Util::unknown_type.accept?(args[1]) && !block_given? && args[2] == nil
    @j_del.java_method(:assertNotEquals, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(args[0]),::Vertx::Util::Utils.to_object(args[1]))
    return self
  elsif ::Vertx::Util::unknown_type.accept?(args[0]) && ::Vertx::Util::unknown_type.accept?(args[1]) && args[2].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(args[0]),::Vertx::Util::Utils.to_object(args[1]),args[2])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling assert_not_equals(#{args[0]},#{args[1]},#{args[2]})"
  end
end

- (self) assertNotNull(expected) - (self) assertNotNull(expected, message)

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

Overloads:

  • - (self) assertNotNull(expected)

    Parameters:

    • expected (Object)
      the argument being asserted to be not null
  • - (self) assertNotNull(expected, message)

    Parameters:

    • expected (Object)
      the argument being asserted to be not null
    • message (String)
      the failure message

Returns:

  • (self)


281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 281

def assert_not_null(*args)
  if ::Vertx::Util::unknown_type.accept?(args[0]) && !block_given? && args[1] == nil
    @j_del.java_method(:assertNotNull, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(args[0]))
    return self
  elsif ::Vertx::Util::unknown_type.accept?(args[0]) && args[1].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(args[0]),args[1])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling assert_not_null(#{args[0]},#{args[1]})"
  end
end

- (self) assertNull(expected) - (self) assertNull(expected, message)

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

Overloads:

  • - (self) assertNull(expected)

    Parameters:

    • expected (Object)
      the argument being asserted to be null
  • - (self) assertNull(expected, message)

    Parameters:

    • expected (Object)
      the argument being asserted to be null
    • message (String)
      the failure message

Returns:

  • (self)


237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 237

def assert_null(*args)
  if ::Vertx::Util::unknown_type.accept?(args[0]) && !block_given? && args[1] == nil
    @j_del.java_method(:assertNull, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(args[0]))
    return self
  elsif ::Vertx::Util::unknown_type.accept?(args[0]) && args[1].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(args[0]),args[1])
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling assert_null(#{args[0]},#{args[1]})"
  end
end

- (self) assertTrue(condition) - (self) assertTrue(condition, message)

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

Overloads:

  • - (self) assertTrue(condition)

    Parameters:

    • condition (true, false)
      the condition to assert
  • - (self) assertTrue(condition, message)

    Parameters:

    • condition (true, false)
      the condition to assert
    • message (String)
      the failure message

Returns:

  • (self)


259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 259

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

- (::VertxUnit::Async) async - (::VertxUnit::Async) async(count)

Create and returns a new async object, the returned async controls the completion of the test. This async operation completes when the Async#count_down 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.

Overloads:

Returns:



196
197
198
199
200
201
202
203
204
205
206
207
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 196

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

- (Proc) asyncAssertFailure - (Proc) asyncAssertFailure(causeHandler) { ... }

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.

Overloads:

  • - (Proc) asyncAssertFailure(causeHandler) { ... }

    Yields:

    • the cause handler

Returns:

  • (Proc)
    the async result handler


335
336
337
338
339
340
341
342
343
344
345
346
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 335

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 true
    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)) unless !block_given? }))) { |val| ::Vertx::Util::Utils.to_object(val) }
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling async_assert_failure()"
  end
end

- (Proc) asyncAssertSuccess - (Proc) asyncAssertSuccess(resultHandler) { ... }

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.

Overloads:

  • - (Proc) asyncAssertSuccess(resultHandler) { ... }

    Yields:

    • the result handler

Returns:

  • (Proc)
    the async result handler


97
98
99
100
101
102
103
104
105
106
107
108
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 97

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 true
    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)) unless !block_given? }))) { |val| ::Vertx::Util::Utils.to_object(val) }
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling async_assert_success()"
  end
end

- (Proc) exceptionHandler

Returns an exception handler that will fail this context

Returns:

  • (Proc)
    an exception handler that will fail this context


349
350
351
352
353
354
355
356
357
358
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 349

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
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling exception_handler()"
  end
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


215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 215

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

- (Object) get(key)

Get some data from the context.

Parameters:

  • key (String)
    the key of the data

Returns:

  • (Object)
    the data


299
300
301
302
303
304
305
306
307
308
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 299

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

- (Object) put(key, value)

Put some data in the context.

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

Parameters:

  • key (String)
    the key of the data
  • value (Object)
    the data

Returns:

  • (Object)
    the previous object when it exists


175
176
177
178
179
180
181
182
183
184
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 175

def put(*args)
  if args[0].class == String && ::Vertx::Util::unknown_type.accept?(args[1]) && !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(args[0],::Vertx::Util::Utils.to_object(args[1])))
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling put(#{args[0]},#{args[1]})"
  end
end

- (Object) remove(key)

Remove some data from the context.

Parameters:

  • key (String)
    the key to remove

Returns:

  • (Object)
    the removed object when it exists


158
159
160
161
162
163
164
165
166
167
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 158

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

- (::VertxUnit::Async) strictAsync(count)

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

If Async#count_down is called more than count times, an IllegalStateException is thrown.

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)

Returns:



144
145
146
147
148
149
150
151
152
153
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 144

def strict_async(*args)
  if args[0].class == Fixnum && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:strictAsync, [Java::int.java_class]).call(args[0]),::VertxUnit::Async)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling strict_async(#{args[0]})"
  end
end

- (self) verify(block) { ... }

Execute the provided handler, which may contain assertions, possibly from any third-party assertion framework. Any AssertionError thrown will be caught (and propagated) in order to fulfill potential expected async completeness.

Yields:

  • block of code to be executed

Returns:

  • (self)


315
316
317
318
319
320
321
322
323
324
325
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-unit/test_context.rb', line 315

def verify
  if true
    @j_del.java_method(:verify, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(nil) unless !block_given? }))
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling verify()"
  end
end