1886da342Sopenharmony_ci/* 2886da342Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3886da342Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4886da342Sopenharmony_ci * you may not use this file except in compliance with the License. 5886da342Sopenharmony_ci * You may obtain a copy of the License at 6886da342Sopenharmony_ci * 7886da342Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8886da342Sopenharmony_ci * 9886da342Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10886da342Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11886da342Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12886da342Sopenharmony_ci * See the License for the specific language governing permissions and 13886da342Sopenharmony_ci * limitations under the License. 14886da342Sopenharmony_ci */ 15886da342Sopenharmony_ciclass VerificationMode { 16886da342Sopenharmony_ci constructor(times) { 17886da342Sopenharmony_ci this.doTimes = times; 18886da342Sopenharmony_ci } 19886da342Sopenharmony_ci times(count) { 20886da342Sopenharmony_ci if (count !== this.doTimes) { 21886da342Sopenharmony_ci throw Error(`expect ${count} actual ${this.doTimes}`); 22886da342Sopenharmony_ci } 23886da342Sopenharmony_ci } 24886da342Sopenharmony_ci never() { 25886da342Sopenharmony_ci if (this.doTimes !== 0) { 26886da342Sopenharmony_ci throw Error(`expect 0 actual ${this.doTimes}`); 27886da342Sopenharmony_ci } 28886da342Sopenharmony_ci } 29886da342Sopenharmony_ci once() { 30886da342Sopenharmony_ci if (this.doTimes !== 1) { 31886da342Sopenharmony_ci throw Error(`expect 1 actual ${this.doTimes}`); 32886da342Sopenharmony_ci } 33886da342Sopenharmony_ci } 34886da342Sopenharmony_ci atLeast(count) { 35886da342Sopenharmony_ci if (count > this.doTimes) { 36886da342Sopenharmony_ci throw Error('failed ' + count + ' greater than the actual execution times of method'); 37886da342Sopenharmony_ci } 38886da342Sopenharmony_ci } 39886da342Sopenharmony_ci atMost(count) { 40886da342Sopenharmony_ci if (count < this.doTimes) { 41886da342Sopenharmony_ci throw Error('failed ' + count + ' less than the actual execution times of method'); 42886da342Sopenharmony_ci } 43886da342Sopenharmony_ci } 44886da342Sopenharmony_ci} 45886da342Sopenharmony_ciexport default VerificationMode; 46