Class: JavaMethod::StubMethodWriter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/java_testing_guff/qdox_extensions.rb

Instance Method Summary collapse

Constructor Details

#initialize(underlying_method) ⇒ StubMethodWriter

Returns a new instance of StubMethodWriter.



291
292
293
# File 'lib/java_testing_guff/qdox_extensions.rb', line 291

def initialize(underlying_method)
    @underlying_method=underlying_method
end

Instance Method Details

#add_getter_stub_to(generated_clazz) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/java_testing_guff/qdox_extensions.rb', line 318

def add_getter_stub_to(generated_clazz)
    gotten_field_name = JavaClass.camelize_lower(name.sub(/^get/, "").sub(/^has/, "").sub(/^is/, ""))
    if (returns.boolean?)
        generated_method = generated_clazz.add_method("#{JavaClass.camelize_lower(gotten_field_name)}").returns('T')
        append_throws_clause_if_necessary(generated_method)
        generated_method.body {|body|
            add_boolean_getter_stub_positive_case_to(body)
            body.line('return (T) this;')
        }
        generated_method = generated_clazz.add_method("not#{gotten_field_name.camelize}").returns('T')
        append_throws_clause_if_necessary(generated_method)
        generated_method.body {|body|
            add_boolean_getter_stub_negative_case_to(body)
            body.line('return (T) this;')
        }
    else
        method_builder = generated_clazz.add_method("with#{gotten_field_name.camelize}").returns('T').takes(gotten_field_name, returns.fully_qualified_name)
        append_throws_clause_if_necessary(method_builder)
        method_builder.body {|body|
            add_nonboolean_getter_stub_to(body, gotten_field_name)
            body.line('return (T) this;')
        }
    end
end

#add_stub_methods_to(generated_clazz) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/java_testing_guff/qdox_extensions.rb', line 299

def add_stub_methods_to(generated_clazz)
    if (setter?)
        return
    end

    if (getter?)
        add_getter_stub_to(generated_clazz)
    else
        method_builder = generated_clazz.add_method("with#{name.camelize}").returns('T')
        with_parameters_and_return do |p|
            p.add_takes_clause_to(method_builder)
        end
        with_exceptions do |e|
            e.add_throws_clause_to(method_builder)
        end
        add_nongetter_stub_to(method_builder)
    end
end

#append_throws_clause_if_necessary(generated_method) ⇒ Object



343
344
345
# File 'lib/java_testing_guff/qdox_extensions.rb', line 343

def  append_throws_clause_if_necessary(generated_method)

end

#underlying_methodObject



295
296
297
# File 'lib/java_testing_guff/qdox_extensions.rb', line 295

def underlying_method
    @underlying_method
end