|
| 1 | +/* |
| 2 | + * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. |
| 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 | + * http://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 com.palantir.docker.compose; |
| 18 | + |
| 19 | +import static org.assertj.core.api.Assertions.assertThat; |
| 20 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 21 | + |
| 22 | +import com.palantir.docker.compose.configuration.DockerComposeFiles; |
| 23 | +import com.palantir.docker.compose.connection.waiting.ClusterWait; |
| 24 | +import com.palantir.docker.compose.events.EventConsumer; |
| 25 | +import java.io.IOException; |
| 26 | +import java.util.List; |
| 27 | +import java.util.concurrent.atomic.AtomicInteger; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | +import org.junit.jupiter.api.extension.ExtensionContext; |
| 30 | +import org.mockito.Mockito; |
| 31 | + |
| 32 | +public class DockerComposeExtensionTest { |
| 33 | + |
| 34 | + @Test |
| 35 | + public void calls_after_only_once() throws IOException, InterruptedException { |
| 36 | + AtomicInteger count = new AtomicInteger(); |
| 37 | + DockerComposeExtension dockerComposeExtension = new DockerComposeExtension() { |
| 38 | + |
| 39 | + @Override |
| 40 | + public void before() { |
| 41 | + throw new IllegalStateException("some error"); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public void after() { |
| 46 | + count.incrementAndGet(); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public DockerComposeFiles files() { |
| 51 | + return null; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected List<ClusterWait> clusterWaits() { |
| 56 | + return null; |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + protected List<EventConsumer> eventConsumers() { |
| 61 | + return null; |
| 62 | + } |
| 63 | + }; |
| 64 | + |
| 65 | + ExtensionContext extensionContext = Mockito.mock(ExtensionContext.class); |
| 66 | + assertThatThrownBy(() -> dockerComposeExtension.beforeAll(extensionContext)) |
| 67 | + .isInstanceOf(IllegalStateException.class); |
| 68 | + dockerComposeExtension.afterAll(extensionContext); |
| 69 | + assertThat(count.get()).isEqualTo(1); |
| 70 | + } |
| 71 | +} |
0 commit comments