Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 655e5e9

Browse files
Added test for new behaviour when closed cursor is passed to expectation
1 parent 23659ac commit 655e5e9

3 files changed

Lines changed: 50 additions & 29 deletions

File tree

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ create or replace type body ut_data_value_refcursor as
9090
elsif not a_value%isopen then
9191
raise cursor_not_open;
9292
end if;
93-
else
94-
null;
9593
end if;
9694
exception
9795
when cursor_not_open then
98-
raise_application_error(-20000, 'Cursor is not open');
96+
raise_application_error(-20155, 'Cursor is not open');
9997
when others then
10098
ut_expectation_processor.reset_nls_params();
10199
if a_value%isopen then

test/core/expectations/test_expectations_cursor.pkb

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,45 @@ create or replace package body test_expectations_cursor is
101101
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_success);
102102
end;
103103

104-
procedure success_is_null
104+
procedure success_to_be_null
105105
as
106106
l_actual sys_refcursor;
107107
begin
108108
--Act
109109
ut3.ut.expect( l_actual ).to_be_null();
110+
--Assert
111+
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_success);
112+
end;
113+
114+
procedure success_not_to_be_not_null
115+
as
116+
l_actual sys_refcursor;
117+
begin
118+
--Act
110119
ut3.ut.expect( l_actual ).not_to_be_not_null();
111120
--Assert
112121
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_success);
113122
end;
114123

115-
procedure success_is_not_null
124+
procedure success_not_to_be_null
125+
as
126+
l_actual sys_refcursor;
127+
begin
128+
--Arrange
129+
open l_actual for select * from dual;
130+
--Act
131+
ut3.ut.expect( l_actual ).to_be_not_null();
132+
--Assert
133+
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_success);
134+
end;
135+
136+
procedure success_to_be_not_null
116137
as
117138
l_actual sys_refcursor;
118139
begin
119140
--Arrange
120141
open l_actual for select * from dual;
121142
--Act
122-
ut3.ut.expect( l_actual ).not_to_be_null();
123143
ut3.ut.expect( l_actual ).to_be_not_null();
124144
--Assert
125145
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_success);
@@ -331,7 +351,7 @@ procedure fail_on_different_column_order
331351
l_expected sys_refcursor;
332352
begin
333353
--Arrange
334-
open l_actual for select a.*, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from all_objects a where rownum < 4;
354+
open l_actual for select a.*, 'a' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from all_objects a where rownum < 4;
335355
open l_expected for select a.*, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from all_objects a where rownum < 4;
336356
--Act
337357
ut3.ut.expect(l_actual).to_equal(l_expected, a_exclude=>ut3.ut_varchar2_list('A_COLUMN','Some_Col'));
@@ -515,22 +535,20 @@ was expected to equal:%
515535
end;
516536
end;
517537

518-
procedure reports_on_closed_cursor
519-
as
520-
l_actual sys_refcursor;
521-
l_error_code integer := -19202; --Error occurred in XML processing
538+
procedure exception_when_closed_cursor
539+
is
540+
l_actual sys_refcursor;
541+
l_error_code constant integer := -20155;
522542
begin
523-
--Act
524-
open l_actual for select 1 as value from dual connect by level < 10;
543+
--Arrange
544+
open l_actual for select * from dual;
525545
close l_actual;
526-
begin
527-
ut3.ut.expect(l_actual).to_be_empty();
528-
--Assert
529-
ut.fail('Expected '||l_error_code||' but nothing was raised');
530-
exception
531-
when others then
532-
ut.expect(sqlcode).to_equal(l_error_code);
533-
end;
546+
--Act
547+
ut3.ut.expect( l_actual ).not_to_be_null;
548+
exception
549+
when others then
550+
--Assert
551+
ut.expect(sqlcode).to_equal(l_error_code);
534552
end;
535553

536554
procedure compares_over_1000_rows

test/core/expectations/test_expectations_cursor.pks

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ create or replace package test_expectations_cursor is
2323
--%test(Gives success when both cursors are null)
2424
procedure success_on_both_null;
2525

26-
--%test(Gives success on is_null if cursor is null)
27-
procedure success_is_null;
26+
--%test(Gives success on to_be_null if cursor is null)
27+
procedure success_to_be_null;
2828

29-
--%test(Gives success on is_not_null if cursor is not null)
30-
procedure success_is_not_null;
29+
--%test(Gives succes on not_to_be_not_null if cursor is null)
30+
procedure success_not_to_be_not_null;
31+
32+
--%test(Gives success on not_to_be_null if cursor is not null)
33+
procedure success_not_to_be_null;
34+
35+
--%test(Gives success on to_be_not_null if cursor is not null)
36+
procedure success_to_be_not_null;
3137

3238
--%test(Gives success on is_empty if cursor is empty)
3339
procedure success_is_empty;
@@ -107,12 +113,11 @@ create or replace package test_expectations_cursor is
107113
--%test(Reports exception when cursor raises exception)
108114
procedure reports_on_exception_in_cursor;
109115

110-
--%test(Reports exception when cursor is closed)
111-
--%disabled
112-
procedure reports_on_closed_cursor;
116+
--%test(Reports an exception when cursor is closed)
117+
procedure exception_when_closed_cursor;
113118

114119
--%test(Compares cursors with more than 1000 rows)
115120
procedure compares_over_1000_rows;
116121

117122
end;
118-
/
123+
/

0 commit comments

Comments
 (0)