Class: JavaClass

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.camelize_lower(s) ⇒ Object



33
34
35
# File 'lib/java_testing_guff/qdox_extensions.rb', line 33

def self.camelize_lower(s)
    s.first.downcase + s.camelize()[1..-1]
end

Instance Method Details

#add_easy_mock_methods_to(generated_class) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/java_testing_guff/qdox_extensions.rb', line 52

def add_easy_mock_methods_to(generated_class)
    mockable_methods.each do |method|
        if (!generated_class.already_visited?(method))
            method.add_easy_mock_builder_to(generated_class)
            generated_class.mark_visited(method)
        end
    end
end

#add_field_definitions_to(generated_class) ⇒ Object



76
77
78
79
80
# File 'lib/java_testing_guff/qdox_extensions.rb', line 76

def add_field_definitions_to(generated_class)
    instance_fields.each do |field|
        field.add_definition_to(generated_class)
    end
end

#add_jmock_methods_to(generated_class) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/java_testing_guff/qdox_extensions.rb', line 61

def add_jmock_methods_to(generated_class)
    mockable_methods.each do |method|
        if (!generated_class.already_visited?(method))
            method.add_jmock_builder_to(generated_class)
            generated_class.mark_visited(method)
        end
    end
end

#add_reflective_field_assignments_to(variable_name, body) ⇒ Object



100
101
102
103
104
# File 'lib/java_testing_guff/qdox_extensions.rb', line 100

def add_reflective_field_assignments_to(variable_name, body)
    instance_fields.each do |field|
        field.add_reflective_assignments_to(variable_name, body)
    end
end

#add_setter_method_definitions_to(method_name_prefix, generated_class) ⇒ Object



88
89
90
91
92
# File 'lib/java_testing_guff/qdox_extensions.rb', line 88

def add_setter_method_definitions_to(method_name_prefix, generated_class)
    instance_fields.each do |field|
        field.add_setter_method_definitions_to(method_name_prefix, generated_class)
    end
end

#add_simplest_instantiation_line_to(body) ⇒ Object



94
95
96
97
98
# File 'lib/java_testing_guff/qdox_extensions.rb', line 94

def add_simplest_instantiation_line_to(body)
    variable_name=JavaClass.camelize_lower(name)
    body.line("#{fully_qualified_name} #{variable_name} = #{smallest_constructor_call};")
    variable_name
end

#constructorsObject



106
107
108
109
110
# File 'lib/java_testing_guff/qdox_extensions.rb', line 106

def constructors
    methods.select {|method|
        method.constructor? && method.public?
    }
end

#instance_fieldsObject



82
83
84
85
86
# File 'lib/java_testing_guff/qdox_extensions.rb', line 82

def instance_fields
    fields.select {|field|
        !field.static
    }
end

#mockable_methodsObject



70
71
72
73
74
# File 'lib/java_testing_guff/qdox_extensions.rb', line 70

def mockable_methods
    methods.select {|m|
        m.public? && !m.static? && !m.constructor?
    }
end

#selector_method_nameObject



37
38
39
# File 'lib/java_testing_guff/qdox_extensions.rb', line 37

def selector_method_name
    JavaClass::camelize_lower(name)
end

#smallest_constructor_callObject



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/java_testing_guff/qdox_extensions.rb', line 112

def smallest_constructor_call
    sorted_constructors=constructors.sort {|a, b|
        a.parameters.length <=> b.parameters.length
    }
    args=[]
    if (!sorted_constructors.empty?)
        smallest_constructor=sorted_constructors.first
        smallest_constructor.parameters.each do |parameter|
            args << parameter.any_old_permitted_value
        end
    end
    "new #{fully_qualified_name}(#{args.join(',')})"
end

#with_self_and_supers(&proc) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/java_testing_guff/qdox_extensions.rb', line 41

def with_self_and_supers(&proc)
    proc.call(self)
    if (interface?)
        implemented_interfaces.each do |interface|
            interface.with_self_and_supers &proc
        end
    elsif (super_class.fully_qualified_name != "java.lang.Object")
        super_java_class.with_self_and_supers &proc
    end
end