SitePathsTest: Convert to use Google Truth
Convert the tests to use Google Truth instead of junit.Assert. Add a new PathSubject to perform assertions about Path objects. Change-Id: I8016daeebc6f8cb291f9a767441f5e1a52ea5097
This commit is contained in:
parent
553878ce95
commit
c75d2749dc
@ -224,6 +224,7 @@ junit_tests(
|
||||
"//gerrit-common:annotations",
|
||||
"//gerrit-patch-jgit:server",
|
||||
"//gerrit-server/src/main/prolog:common",
|
||||
"//gerrit-test-util:test_util",
|
||||
"//lib:args4j",
|
||||
"//lib:grappa",
|
||||
"//lib:gson",
|
||||
|
@ -14,12 +14,9 @@
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.extensions.common.PathSubject;
|
||||
import com.google.gerrit.server.util.HostPlatform;
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
import java.io.IOException;
|
||||
@ -34,9 +31,9 @@ public class SitePathsTest extends GerritBaseTests {
|
||||
public void create_NotExisting() throws IOException {
|
||||
final Path root = random();
|
||||
final SitePaths site = new SitePaths(root);
|
||||
assertTrue(site.isNew);
|
||||
assertEquals(root, site.site_path);
|
||||
assertEquals(root.resolve("etc"), site.etc_dir);
|
||||
assertThat(site.isNew).isTrue();
|
||||
PathSubject.assertThat(site.site_path).isEqualTo(root);
|
||||
PathSubject.assertThat(site.etc_dir).isEqualTo(root.resolve("etc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -46,8 +43,8 @@ public class SitePathsTest extends GerritBaseTests {
|
||||
Files.createDirectory(root);
|
||||
|
||||
final SitePaths site = new SitePaths(root);
|
||||
assertTrue(site.isNew);
|
||||
assertEquals(root, site.site_path);
|
||||
assertThat(site.isNew).isTrue();
|
||||
PathSubject.assertThat(site.site_path).isEqualTo(root);
|
||||
} finally {
|
||||
Files.delete(root);
|
||||
}
|
||||
@ -62,8 +59,8 @@ public class SitePathsTest extends GerritBaseTests {
|
||||
Files.createFile(txt);
|
||||
|
||||
final SitePaths site = new SitePaths(root);
|
||||
assertFalse(site.isNew);
|
||||
assertEquals(root, site.site_path);
|
||||
assertThat(site.isNew).isFalse();
|
||||
PathSubject.assertThat(site.site_path).isEqualTo(root);
|
||||
} finally {
|
||||
Files.delete(txt);
|
||||
Files.delete(root);
|
||||
@ -87,15 +84,16 @@ public class SitePathsTest extends GerritBaseTests {
|
||||
final Path root = random();
|
||||
final SitePaths site = new SitePaths(root);
|
||||
|
||||
assertNull(site.resolve(null));
|
||||
assertNull(site.resolve(""));
|
||||
PathSubject.assertThat(site.resolve(null)).isNull();
|
||||
PathSubject.assertThat(site.resolve("")).isNull();
|
||||
|
||||
assertNotNull(site.resolve("a"));
|
||||
assertEquals(root.resolve("a").toAbsolutePath().normalize(), site.resolve("a"));
|
||||
PathSubject.assertThat(site.resolve("a")).isNotNull();
|
||||
PathSubject.assertThat(site.resolve("a"))
|
||||
.isEqualTo(root.resolve("a").toAbsolutePath().normalize());
|
||||
|
||||
final String pfx = HostPlatform.isWin32() ? "C:/" : "/";
|
||||
assertNotNull(site.resolve(pfx + "a"));
|
||||
assertEquals(Paths.get(pfx + "a"), site.resolve(pfx + "a"));
|
||||
PathSubject.assertThat(site.resolve(pfx + "a")).isNotNull();
|
||||
PathSubject.assertThat(site.resolve(pfx + "a")).isEqualTo(Paths.get(pfx + "a"));
|
||||
}
|
||||
|
||||
private static Path random() throws IOException {
|
||||
|
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertAbout;
|
||||
|
||||
import com.google.common.truth.FailureStrategy;
|
||||
import com.google.common.truth.Subject;
|
||||
import com.google.common.truth.SubjectFactory;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class PathSubject extends Subject<PathSubject, Path> {
|
||||
private static final SubjectFactory<PathSubject, Path> PATH_SUBJECT_FACTORY =
|
||||
new SubjectFactory<PathSubject, Path>() {
|
||||
@Override
|
||||
public PathSubject getSubject(FailureStrategy failureStrategy, Path path) {
|
||||
return new PathSubject(failureStrategy, path);
|
||||
}
|
||||
};
|
||||
|
||||
private PathSubject(FailureStrategy failureStrategy, Path path) {
|
||||
super(failureStrategy, path);
|
||||
}
|
||||
|
||||
public static PathSubject assertThat(Path path) {
|
||||
return assertAbout(PATH_SUBJECT_FACTORY).that(path);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user