Skip to content

Commit 7081dae

Browse files
committed
Add tests for PathFileObjectAssert
1 parent e7a6603 commit 7081dae

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (C) 2022 - 2023, 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+
* 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+
package io.github.ascopes.jct.tests.unit.assertions;
17+
18+
import io.github.ascopes.jct.assertions.PathFileObjectAssert;
19+
import io.github.ascopes.jct.filemanagers.PathFileObject;
20+
import org.junit.jupiter.api.DisplayName;
21+
import org.junit.jupiter.api.Nested;
22+
import org.junit.jupiter.api.Test;
23+
24+
import static io.github.ascopes.jct.tests.helpers.Fixtures.someAbsolutePath;
25+
import static io.github.ascopes.jct.tests.helpers.Fixtures.someRelativePath;
26+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
27+
import static org.assertj.core.api.Assertions.assertThatNoException;
28+
import static org.mockito.Mockito.mock;
29+
import static org.mockito.Mockito.when;
30+
31+
/**
32+
* {@link PathFileObjectAssert} tests.
33+
*
34+
* @author Ashley Scopes
35+
*/
36+
@DisplayName("PathFileObjectAssert tests")
37+
class PathFileObjectAssertTest {
38+
39+
@DisplayName("PathFileObjectAssert#relativePath tests")
40+
@Nested
41+
class RelativePathTest {
42+
43+
@DisplayName(".relativePath() fails if the path file object is null")
44+
@Test
45+
void relativePathFailsIfThePathFileObjectIsNull() {
46+
// Given
47+
var assertions = new PathFileObjectAssert(null);
48+
49+
// Then
50+
assertThatExceptionOfType(AssertionError.class)
51+
.isThrownBy(assertions::relativePath);
52+
}
53+
54+
@DisplayName(".relativePath() returns assertions on the relative path")
55+
@Test
56+
void relativePathReturnsAssertionsOnTheRelativePath() {
57+
// Given
58+
var path = someRelativePath();
59+
var pathFileObject = mock(PathFileObject.class);
60+
when(pathFileObject.getRelativePath()).thenReturn(path);
61+
var assertions = new PathFileObjectAssert(pathFileObject);
62+
63+
// Then
64+
assertThatNoException()
65+
.isThrownBy(() -> assertions.relativePath().isSameAs(path));
66+
}
67+
}
68+
69+
@DisplayName("PathFileObjectAssert#fullPath tests")
70+
@Nested
71+
@SuppressWarnings("removal")
72+
class FullPathTest {
73+
74+
@DisplayName(".fullPath() fails if the path file object is null")
75+
@Test
76+
void fullPathFailsIfThePathFileObjectIsNull() {
77+
// Given
78+
var assertions = new PathFileObjectAssert(null);
79+
80+
// Then
81+
assertThatExceptionOfType(AssertionError.class)
82+
.isThrownBy(assertions::fullPath);
83+
}
84+
85+
@DisplayName(".fullPath() returns assertions on the absolute path")
86+
@Test
87+
void fullPathReturnsAssertionsOnTheFullPath() {
88+
// Given
89+
var path = someAbsolutePath();
90+
var pathFileObject = mock(PathFileObject.class);
91+
when(pathFileObject.getFullPath()).thenReturn(path);
92+
var assertions = new PathFileObjectAssert(pathFileObject);
93+
94+
// Then
95+
assertThatNoException()
96+
.isThrownBy(() -> assertions.fullPath().isSameAs(path));
97+
}
98+
}
99+
100+
@DisplayName("PathFileObjectAssert#absolutePath tests")
101+
@Nested
102+
class AbsolutePathTest {
103+
104+
@DisplayName(".absolutePath() fails if the path file object is null")
105+
@Test
106+
void absolutePathFailsIfThePathFileObjectIsNull() {
107+
// Given
108+
var assertions = new PathFileObjectAssert(null);
109+
110+
// Then
111+
assertThatExceptionOfType(AssertionError.class)
112+
.isThrownBy(assertions::absolutePath);
113+
}
114+
115+
@DisplayName(".absolutePath() returns assertions on the absolute path")
116+
@Test
117+
void absolutePathReturnsAssertionsOnTheAbsolutePath() {
118+
// Given
119+
var path = someAbsolutePath();
120+
var pathFileObject = mock(PathFileObject.class);
121+
when(pathFileObject.getAbsolutePath()).thenReturn(path);
122+
var assertions = new PathFileObjectAssert(pathFileObject);
123+
124+
// Then
125+
assertThatNoException()
126+
.isThrownBy(() -> assertions.absolutePath().isSameAs(path));
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)