|
| 1 | +/* |
| 2 | + * Copyright 2026 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.spockframework.smoke.mock |
| 18 | + |
| 19 | +import org.spockframework.runtime.ConditionNotSatisfiedError |
| 20 | +import spock.lang.FailsWith |
| 21 | +import spock.lang.Issue |
| 22 | +import spock.lang.Specification |
| 23 | + |
| 24 | +import java.util.function.Function |
| 25 | + |
| 26 | +@Issue("https://github.com/spockframework/spock/issues/616") |
| 27 | +class GlobalInteractionsInCleanup extends Specification { |
| 28 | + def mock = Mock(Function) |
| 29 | + def mock2 = Mock(Function) { |
| 30 | + apply("a") >> { "c" } |
| 31 | + } |
| 32 | + def mock3 = Mock(Function) |
| 33 | + |
| 34 | + def setup() { |
| 35 | + mock.apply("a") >> { "b" } |
| 36 | + } |
| 37 | + |
| 38 | + def cleanup() { |
| 39 | + verifyAll { |
| 40 | + mock.apply("a") == "b" |
| 41 | + mock2.apply("a") == "c" |
| 42 | + mock3.apply("a") == "d" |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + def "run a successful test"() { |
| 47 | + given: |
| 48 | + mock3.apply("a") >> { "d" } |
| 49 | + |
| 50 | + expect: |
| 51 | + true |
| 52 | + } |
| 53 | + |
| 54 | + @FailsWith(ConditionNotSatisfiedError) |
| 55 | + def "run a failing test"() { |
| 56 | + given: |
| 57 | + mock3.apply("a") >> { "d" } |
| 58 | + |
| 59 | + expect: |
| 60 | + false |
| 61 | + } |
| 62 | +} |
0 commit comments