Skip to content

Commit eee8f36

Browse files
committed
[test] fix 9.1 compatibility - no longer a new on Java interfaces
1 parent db27f46 commit eee8f36

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

src/test/ruby/pkcs7/test_smime.rb

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ module PKCS7Test
44
class TestSMIME < TestCase
55
def test_read_pkcs7_should_raise_error_when_parsing_headers_fails
66
bio = BIO.new
7-
mime = Mime.new
8-
mime.stubs(:parseHeaders).returns(nil)
7+
mime = Mime.impl { |name, *args| name == :parseHeaders ? nil : raise }
98

109
begin
1110
SMIME.new(mime).readPKCS7(bio, nil)
@@ -19,7 +18,7 @@ def test_read_pkcs7_should_raise_error_when_parsing_headers_fails
1918

2019
def test_read_pkcs7_should_raise_error_when_content_type_is_not_there
2120
bio = BIO.new
22-
mime = Mime.new
21+
mime = Mime.impl {}
2322

2423
headers = ArrayList.new
2524
mime.expects(:parseHeaders).with(bio).returns(headers)
@@ -34,7 +33,7 @@ def test_read_pkcs7_should_raise_error_when_content_type_is_not_there
3433
assert_equal PKCS7::R_NO_CONTENT_TYPE, e.get_reason
3534
end
3635

37-
mime = Mime.new
36+
mime = Mime.impl {}
3837
mime.expects(:parseHeaders).with(bio).returns(headers)
3938
mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", nil))
4039

@@ -49,20 +48,18 @@ def test_read_pkcs7_should_raise_error_when_content_type_is_not_there
4948
end
5049

5150
def test_read_pkcs7_should_set_the_second_arguments_contents_to_null_if_its_there
52-
mime = Mime.new
53-
mime.stubs(:parseHeaders).raises("getOutOfJailForFree")
51+
mime = Mime.impl { |name, *args| name == :parseHeaders ? raise("parseHeaders") : raise }
5452

5553
bio2 = BIO.new
5654
arr = [bio2].to_java BIO
5755

5856
begin
5957
SMIME.new(mime).readPKCS7(nil, arr)
60-
rescue
58+
rescue => e
59+
assert_equal 'parseHeaders', e.message
6160
end
6261

6362
assert_nil arr[0]
64-
65-
6663
arr = [bio2, bio2].to_java BIO
6764
begin
6865
SMIME.new(mime).readPKCS7(nil, arr)
@@ -75,11 +72,18 @@ def test_read_pkcs7_should_set_the_second_arguments_contents_to_null_if_its_ther
7572

7673
def test_read_pkcs7_should_call_methods_on_mime
7774
bio = BIO.new
78-
mime = Mime.new
7975

80-
headers = ArrayList.new
81-
mime.expects(:parseHeaders).with(bio).returns(headers)
82-
mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", "application/pkcs7-mime"))
76+
mime = Mime.impl do |name, *args|
77+
case name
78+
when :parseHeaders then ArrayList.new
79+
when :findHeader then
80+
if args[1] == 'content-type'
81+
MimeHeader.new(args[1], "application/pkcs7-mime")
82+
else
83+
raise args.inspect
84+
end
85+
end
86+
end
8387

8488
begin
8589
SMIME.new(mime).readPKCS7(bio, nil)
@@ -90,11 +94,17 @@ def test_read_pkcs7_should_call_methods_on_mime
9094

9195
def test_read_pkcs7_throws_correct_exception_if_wrong_content_type
9296
bio = BIO.new
93-
mime = Mime.new
94-
95-
headers = ArrayList.new
96-
mime.expects(:parseHeaders).with(bio).returns(headers)
97-
mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", "foo"))
97+
mime = Mime.impl do |name, *args|
98+
case name
99+
when :parseHeaders then ArrayList.new
100+
when :findHeader then
101+
if args[1] == 'content-type'
102+
MimeHeader.new(args[1], "foo")
103+
else
104+
raise args.inspect
105+
end
106+
end
107+
end
98108

99109
begin
100110
SMIME.new(mime).readPKCS7(bio, nil)
@@ -109,13 +119,19 @@ def test_read_pkcs7_throws_correct_exception_if_wrong_content_type
109119

110120
def test_read_pkcs7_with_multipart_should_fail_if_no_boundary_found
111121
bio = BIO.new
112-
mime = Mime.new
113-
114-
headers = ArrayList.new
115122
hdr = MimeHeader.new("content-type", "multipart/signed")
116-
mime.expects(:parseHeaders).with(bio).returns(headers)
117-
mime.expects(:findHeader).with(headers, "content-type").returns(hdr)
118-
123+
mime = Mime.impl do |name, *args|
124+
case name
125+
when :parseHeaders then ArrayList.new
126+
when :findHeader then
127+
if args[1] == 'content-type'
128+
hdr
129+
else
130+
raise args.inspect
131+
end
132+
end
133+
end
134+
hdr = MimeHeader.new("content-type", "multipart/signed")
119135
mime.expects(:findParam).with(hdr, "boundary").returns(nil)
120136

121137
begin
@@ -130,7 +146,7 @@ def test_read_pkcs7_with_multipart_should_fail_if_no_boundary_found
130146

131147
def test_read_pkcs7_with_multipart_should_fail_if_null_boundary_value
132148
bio = BIO.new
133-
mime = Mime.new
149+
mime = Mime.impl {}
134150

135151
headers = ArrayList.new
136152
hdr = MimeHeader.new("content-type", "multipart/signed")
@@ -152,7 +168,7 @@ def test_read_pkcs7_with_multipart_should_fail_if_null_boundary_value
152168
# TODO: redo this test to be an integration test
153169
def _test_read_pkcs7_happy_path_without_multipart
154170
bio = BIO.new
155-
mime = Mime.new
171+
mime = Mime.impl {}
156172

157173
headers = ArrayList.new
158174
mime.expects(:parseHeaders).with(bio).returns(headers)
@@ -164,19 +180,20 @@ def _test_read_pkcs7_happy_path_without_multipart
164180
def test_read_pkcs7_happy_path_multipart
165181
bio = BIO::from_string(MultipartSignedString)
166182
mime = Mime::DEFAULT
167-
p7 = SMIME.new(mime).readPKCS7(bio, nil)
183+
SMIME.new(mime).readPKCS7(bio, nil)
168184
end
169185

170186
def test_read_pkcs7_happy_path_without_multipart_enveloped
171187
bio = BIO::from_string(MimeEnvelopedString)
172188
mime = Mime::DEFAULT
173-
p7 = SMIME.new(mime).readPKCS7(bio, nil)
189+
SMIME.new(mime).readPKCS7(bio, nil)
174190
end
175191

176192
def test_read_pkcs7_happy_path_without_multipart_signed
177193
bio = BIO::from_string(MimeSignedString)
178194
mime = Mime::DEFAULT
179-
p7 = SMIME.new(mime).readPKCS7(bio, nil)
195+
SMIME.new(mime).readPKCS7(bio, nil)
180196
end
197+
181198
end
182199
end

0 commit comments

Comments
 (0)