|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 3 | + * the License. You may obtain a copy of the License at |
| 4 | + * |
| 5 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 8 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 9 | + * specific language governing permissions and limitations under the License. |
| 10 | + * |
| 11 | + * Copyright 2012-2021 the original author or authors. |
| 12 | + */ |
| 13 | +package org.assertj.core.internal.paths; |
| 14 | + |
| 15 | +import static java.nio.file.Files.createDirectory; |
| 16 | +import static java.nio.file.Files.createFile; |
| 17 | +import static org.assertj.core.api.BDDAssertions.then; |
| 18 | +import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; |
| 19 | +import static org.assertj.core.error.ShouldExist.shouldExist; |
| 20 | +import static org.assertj.core.error.ShouldHaveNoExtension.shouldHaveNoExtension; |
| 21 | +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; |
| 22 | +import static org.assertj.core.util.FailureMessages.actualIsNull; |
| 23 | + |
| 24 | +import java.io.IOException; |
| 25 | +import java.nio.file.Path; |
| 26 | + |
| 27 | +import org.assertj.core.internal.PathsBaseTest; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | +import org.junit.jupiter.params.ParameterizedTest; |
| 30 | +import org.junit.jupiter.params.provider.ValueSource; |
| 31 | + |
| 32 | +class Paths_assertHasNoExtension_Test extends PathsBaseTest { |
| 33 | + |
| 34 | + @Test |
| 35 | + void should_fail_if_actual_is_null() { |
| 36 | + // GIVEN |
| 37 | + Path actual = null; |
| 38 | + // WHEN |
| 39 | + AssertionError error = expectAssertionError(() -> paths.assertHasNoExtension(info, actual)); |
| 40 | + // THEN |
| 41 | + then(error).hasMessage(actualIsNull()); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + void should_fail_if_actual_does_not_exist() { |
| 46 | + // GIVEN |
| 47 | + Path actual = tempDir.resolve("non-existent"); |
| 48 | + // WHEN |
| 49 | + AssertionError error = expectAssertionError(() -> paths.assertHasNoExtension(info, actual)); |
| 50 | + // THEN |
| 51 | + then(error).hasMessage(shouldExist(actual).create()); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void should_fail_if_actual_is_not_a_regular_file() throws IOException { |
| 56 | + // GIVEN |
| 57 | + Path actual = createDirectory(tempDir.resolve("directory")); |
| 58 | + // WHEN |
| 59 | + AssertionError error = expectAssertionError(() -> paths.assertHasNoExtension(info, actual)); |
| 60 | + // THEN |
| 61 | + then(error).hasMessage(shouldBeRegularFile(actual).create()); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + void should_fail_if_actual_has_extension() throws IOException { |
| 66 | + // GIVEN |
| 67 | + Path actual = createFile(tempDir.resolve("file.txt")); |
| 68 | + // WHEN |
| 69 | + AssertionError error = expectAssertionError(() -> paths.assertHasNoExtension(info, actual)); |
| 70 | + // THEN |
| 71 | + then(error).hasMessage(shouldHaveNoExtension(actual, "txt").create()); |
| 72 | + } |
| 73 | + |
| 74 | + @ParameterizedTest |
| 75 | + @ValueSource(strings = { "file", "file." }) |
| 76 | + void should_pass_if_actual_has_no_extension(String filename) throws IOException { |
| 77 | + // GIVEN |
| 78 | + Path actual = createFile(tempDir.resolve(filename)); |
| 79 | + // WHEN/THEN |
| 80 | + paths.assertHasNoExtension(info, actual); |
| 81 | + } |
| 82 | + |
| 83 | +} |
0 commit comments