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

Skip to content

Commit 7f5f775

Browse files
New design for the expectations tests
1 parent 4a5fad4 commit 7f5f775

5 files changed

Lines changed: 118 additions & 64 deletions

File tree

test/core/expectations/test_expect_not_to_be_null.pkb

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,152 @@
11
create or replace package body test_expect_not_to_be_null
22
is
3-
4-
procedure execute_expectation(a_data_type in varchar2,
5-
a_data_value in varchar2)
6-
is
7-
l_execute varchar2(32000);
8-
begin
9-
-- arrange
10-
l_execute := ' declare
11-
l_expected '||a_data_type||' := '||a_data_value||';
12-
begin
13-
--act - execute the expectation
14-
ut3.ut.expect(l_expected).not_to_be_null();
15-
end;';
16-
17-
execute immediate l_execute;
18-
end;
19-
20-
procedure test_success_expectacion(a_data_type in varchar2,
21-
a_data_value in varchar2)
22-
is
23-
begin
24-
execute_expectation(a_data_type, a_data_value);
25-
26-
--assert - check that expectation was executed successfully
27-
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_success);
28-
29-
-- cleanup
30-
ut3.ut_expectation_processor.clear_expectations();
31-
end;
32-
33-
procedure test_failure_expectacion(a_data_type in varchar2,
34-
a_data_value in varchar2)
35-
is
36-
begin
37-
execute_expectation(a_data_type, a_data_value);
38-
39-
--assert - check that expectation was a failure
40-
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_failure);
41-
42-
-- cleanup
43-
ut3.ut_expectation_processor.clear_expectations();
44-
end;
45-
463
procedure blob_not_null
474
is
485
begin
49-
test_success_expectacion('blob', 'to_blob(''abc'')');
6+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'blob', 'to_blob(''abc'')');
7+
expectations_helpers.test_success_expectacion;
508
end;
519

5210
procedure blob_0_lengt
5311
is
5412
begin
55-
test_success_expectacion('blob', 'empty_blob()');
13+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'blob', 'empty_blob()');
14+
expectations_helpers.test_success_expectacion;
5615
end;
5716

5817
procedure boolean_not_null
5918
is
6019
begin
61-
test_success_expectacion('boolean', 'true');
20+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'boolean', 'true');
21+
expectations_helpers.test_success_expectacion;
6222
end;
6323

6424
procedure clob_not_null
6525
is
6626
begin
67-
test_success_expectacion('clob', 'to_clob(''abc'')');
27+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'clob', 'to_clob(''abc'')');
28+
expectations_helpers.test_success_expectacion;
6829
end;
6930

7031

7132
procedure clob_0_lengt
7233
is
7334
begin
74-
test_success_expectacion('clob', 'empty_clob()');
35+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'clob', 'empty_clob()');
36+
expectations_helpers.test_success_expectacion;
7537
end;
7638

7739
procedure date_not_null
7840
is
7941
begin
80-
test_success_expectacion('date', 'sysdate');
42+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'date', 'sysdate');
43+
expectations_helpers.test_success_expectacion;
8144
end;
8245

8346
procedure number_not_null
8447
is
8548
begin
86-
test_success_expectacion('number', '1234');
49+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'number', '1234');
50+
expectations_helpers.test_success_expectacion;
8751
end;
8852

8953
procedure timestamp_not_null
9054
is
9155
begin
92-
test_success_expectacion('timestamp', 'systimestamp');
56+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'timestamp', 'systimestamp');
57+
expectations_helpers.test_success_expectacion;
9358
end;
9459

9560
procedure timestamp_with_ltz_not_null
9661
is
9762
begin
98-
test_success_expectacion('timestamp with local time zone', 'systimestamp');
63+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'timestamp with local time zone', 'systimestamp');
64+
expectations_helpers.test_success_expectacion;
9965
end;
10066

10167
procedure timestamp_with_tz_not_null
10268
is
10369
begin
104-
test_success_expectacion('timestamp with time zone', 'systimestamp');
70+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'timestamp with time zone', 'systimestamp');
71+
expectations_helpers.test_success_expectacion;
10572
end;
10673

10774
procedure varchar2_not_null
10875
is
10976
begin
110-
test_success_expectacion('varchar2(4000)', '''abc''');
77+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'varchar2(4000)', '''abc''');
78+
expectations_helpers.test_success_expectacion;
11179
end;
11280

11381
procedure null_blob
11482
is
11583
begin
116-
test_failure_expectacion('blob', 'null');
84+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'blob', 'null');
85+
expectations_helpers.test_failure_expectacion;
11786
end;
11887

11988

12089
procedure null_boolean
12190
is
12291
begin
123-
test_failure_expectacion('boolean', 'null');
92+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'boolean', 'null');
93+
expectations_helpers.test_failure_expectacion;
12494
end;
12595

12696

12797
procedure null_clob
12898
is
12999
begin
130-
test_failure_expectacion('clob', 'null');
100+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'clob', 'null');
101+
expectations_helpers.test_failure_expectacion;
131102
end;
132103

133104

134105
procedure null_date
135106
is
136107
begin
137-
test_failure_expectacion('date', 'null');
108+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'date', 'null');
109+
expectations_helpers.test_failure_expectacion;
138110
end;
139111

140112

141113
procedure null_number
142114
is
143115
begin
144-
test_failure_expectacion('number', 'null');
116+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'number', 'null');
117+
expectations_helpers.test_failure_expectacion;
145118
end;
146119

147120

148121
procedure null_timestamp
149122
is
150123
begin
151-
test_failure_expectacion('timestamp', 'null');
124+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'timestamp', 'null');
125+
expectations_helpers.test_failure_expectacion;
152126
end;
153127

154128

155129
procedure null_timestamp_with_ltz
156130
is
157131
begin
158-
test_failure_expectacion('timestamp with local time zone', 'null');
132+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'timestamp with local time zone', 'null');
133+
expectations_helpers.test_failure_expectacion;
159134
end;
160135

161136

162137
procedure null_timestamp_with_tz
163138
is
164139
begin
165-
test_failure_expectacion('timestamp with time zone', 'null');
140+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'timestamp with time zone', 'null');
141+
expectations_helpers.test_failure_expectacion;
166142
end;
167143

168144

169145
procedure null_varchar2
170146
is
171147
begin
172-
test_failure_expectacion('varchar2(4000)', 'null');
148+
expectations_helpers.execute_unary_expectation('not_to_be_null', 'varchar2(4000)', 'null');
149+
expectations_helpers.test_failure_expectacion;
173150
end;
174151

175152
end test_expect_not_to_be_null;

test/core/expectations/test_expect_not_to_be_null.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
create or replace package test_expect_not_to_be_null
22
is
33
--%suite(expectations - not_to_be_null)
4-
--%suitepath(utplsql.core.expectations.not_to_be_null)
4+
--%suitepath(utplsql.core.expectations.unary)
55

66
--%test(Gives success for not null blob)
77
procedure blob_not_null;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
create or replace package body expectations_helpers
2+
is
3+
procedure execute_unary_expectation(a_matcher_name in varchar2,
4+
a_data_type in varchar2,
5+
a_data_value in varchar2)
6+
is
7+
l_execute varchar2(32000);
8+
begin
9+
l_execute := ' declare
10+
l_expected '||a_data_type||' := '||a_data_value||';
11+
begin
12+
--act - execute the expectation
13+
ut3.ut.expect(l_expected).'||a_matcher_name||'();
14+
end;';
15+
16+
execute immediate l_execute;
17+
end;
18+
19+
procedure execute_binary_expectation(a_matcher_name in varchar2,
20+
a_data_type_1 in varchar2,
21+
a_data_value_1 in varchar2,
22+
a_data_type_2 in varchar2,
23+
a_data_value_2 in varchar2)
24+
is
25+
l_execute varchar2(32000);
26+
begin
27+
l_execute := ' declare
28+
l_expected_1 '||a_data_type_1||' := '||a_data_value_1||';
29+
l_expected_2 '||a_data_type_2||' := '||a_data_value_2||';
30+
begin
31+
--act - execute the expectation
32+
ut3.ut.expect(l_expected_1).'||a_matcher_name||'(l_expected_2);
33+
end;';
34+
35+
execute immediate l_execute;
36+
end;
37+
38+
procedure test_success_expectacion
39+
is
40+
begin
41+
--assert - check that expectation was a success
42+
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_success);
43+
44+
-- cleanup
45+
ut3.ut_expectation_processor.clear_expectations();
46+
end;
47+
48+
procedure test_failure_expectacion
49+
is
50+
begin
51+
--assert - check that expectation was a failure
52+
ut.expect(ut3.ut_expectation_processor.get_status()).to_equal(ut3.ut_utils.tr_failure);
53+
54+
-- cleanup
55+
ut3.ut_expectation_processor.clear_expectations();
56+
end;
57+
end expectations_helpers;
58+
/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
create or replace package expectations_helpers
2+
is
3+
procedure execute_unary_expectation(a_matcher_name in varchar2,
4+
a_data_type in varchar2,
5+
a_data_value in varchar2);
6+
7+
procedure execute_binary_expectation(a_matcher_name in varchar2,
8+
a_data_type_1 in varchar2,
9+
a_data_value_1 in varchar2,
10+
a_data_type_2 in varchar2,
11+
a_data_value_2 in varchar2);
12+
13+
procedure test_success_expectacion;
14+
15+
procedure test_failure_expectacion;
16+
end expectations_helpers;
17+
/

test/install_tests.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ whenever oserror exit failure rollback
99
@@helpers/ut_without_body.pks
1010
@@helpers/ut_with_invalid_body.pks
1111
@@helpers/ut_with_invalid_body.pkb
12+
@@helpers/expectations_helpers.pks
13+
@@helpers/expectations_helpers.pkb
1214

1315
--Install tests
1416
@@core.pks

0 commit comments

Comments
 (0)