• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17class VerificationMode {
18
19    private doTimes: number
20
21    constructor(times: number) {
22        this.doTimes = times;
23    }
24
25    times(count: number) {
26        if(count !== this.doTimes) {
27            throw Error(`expect ${count} actual ${this.doTimes}`);
28        }
29    }
30
31    never() {
32        if (this.doTimes !== 0) {
33            throw Error(`expect 0 actual ${this.doTimes}`);
34        }
35    }
36
37    once() {
38        if (this.doTimes !== 1) {
39            throw Error(`expect 1 actual ${this.doTimes}`);
40        }
41    }
42
43    atLeast(count: number) {
44        if (count > this.doTimes) {
45            throw Error('failed ' + count + ' greater than the actual execution times of method');
46        }
47    }
48
49    atMost(count: number) {
50        if (count < this.doTimes) {
51            throw Error('failed ' + count + ' less than the actual execution times of method');
52        }
53    }
54}
55
56export default VerificationMode;