Best Assertj code snippet using org.assertj.core.api.AbstractFileAssert.hasName
Source:AssemblyManagerCreateDockerTarArchiveTest.java
...73 // Then74 ArchiveAssertions.assertThat(result)75 .isFile()76 .hasSize(1536)77 .hasName("changed-files.tar")78 .fileTree()79 .containsExactly("test-0.1.0.jar");80 }81 @Test82 public void withoutDockerfile() throws IOException {83 // Given84 final JKubeConfiguration jKubeConfiguration = createJKubeConfiguration();85 final BuildConfiguration buildConfiguration = BuildConfiguration.builder().build();86 // When87 File dockerArchiveFile = assemblyManager.createDockerTarArchive(88 "test-image", jKubeConfiguration, buildConfiguration, prefixedLogger, null);89 // Then90 assertTargetHasDockerDirectories("test-image");91 ArchiveAssertions.assertThat(dockerArchiveFile)92 .isFile().hasName("docker-build.tar").hasSize(4096)93 .fileTree()94 .containsExactlyInAnyOrder(95 "Dockerfile",96 "jkube-generated-layer-final-artifact/",97 "jkube-generated-layer-final-artifact/maven/",98 "jkube-generated-layer-final-artifact/maven/test-0.1.0.jar",99 "maven/");100 assertDockerFile("test-image").hasContent(DOCKERFILE_DEFAULT_FALLBACK_CONTENT);101 assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder(102 "Dockerfile",103 "jkube-generated-layer-final-artifact",104 "jkube-generated-layer-final-artifact/maven",105 "jkube-generated-layer-final-artifact/maven/test-0.1.0.jar",106 "maven"107 );108 }109 @Test110 public void withoutDockerfileAndFinalCustomizer() throws IOException {111 // Given112 final JKubeConfiguration jKubeConfiguration = createJKubeConfiguration();113 final BuildConfiguration buildConfiguration = BuildConfiguration.builder().build();114 final AtomicBoolean customized = new AtomicBoolean(false);115 final ArchiverCustomizer finalCustomizer = ac -> {116 customized.set(true);117 return ac;118 };119 // When120 File dockerArchiveFile = assemblyManager.createDockerTarArchive(121 "no-docker-file-and-customizer", jKubeConfiguration, buildConfiguration, prefixedLogger, finalCustomizer);122 // Then123 assertTargetHasDockerDirectories("no-docker-file-and-customizer");124 ArchiveAssertions.assertThat(dockerArchiveFile)125 .isFile().hasName("docker-build.tar").hasSize(4096)126 .fileTree()127 .containsExactlyInAnyOrder(128 "Dockerfile",129 "jkube-generated-layer-final-artifact/",130 "jkube-generated-layer-final-artifact/maven/",131 "jkube-generated-layer-final-artifact/maven/test-0.1.0.jar",132 "maven/");133 assertDockerFile("no-docker-file-and-customizer").hasContent(DOCKERFILE_DEFAULT_FALLBACK_CONTENT);134 assertBuildDirectoryFileTree("no-docker-file-and-customizer").containsExactlyInAnyOrder(135 "Dockerfile",136 "jkube-generated-layer-final-artifact",137 "jkube-generated-layer-final-artifact/maven",138 "jkube-generated-layer-final-artifact/maven/test-0.1.0.jar",139 "maven");140 assertThat(customized).isTrue();141 }142 @Test143 public void withoutDockerfileAndAlreadyExistingFileInAssemblyGetsOverwritten() throws IOException {144 final JKubeConfiguration jKubeConfiguration = createJKubeConfiguration();145 final BuildConfiguration buildConfiguration = BuildConfiguration.builder().build();146 File dockerArchiveFile;147 // When148 assemblyManager.createDockerTarArchive(149 "modified-image", jKubeConfiguration, buildConfiguration, prefixedLogger, null);150 // Modify file contents151 writeLineToFile(jKubeConfiguration.getProject().getArtifact(), "Modified content");152 dockerArchiveFile = assemblyManager.createDockerTarArchive(153 "modified-image", jKubeConfiguration, buildConfiguration, prefixedLogger, null);154 // Then155 assertTargetHasDockerDirectories("modified-image");156 ArchiveAssertions.assertThat(dockerArchiveFile)157 .isFile().hasName("docker-build.tar").hasSize(4608)158 .fileTree()159 .containsExactlyInAnyOrder(160 "Dockerfile",161 "jkube-generated-layer-final-artifact/",162 "jkube-generated-layer-final-artifact/maven/",163 "jkube-generated-layer-final-artifact/maven/test-0.1.0.jar",164 "maven/");165 assertDockerFile("modified-image").hasContent(DOCKERFILE_DEFAULT_FALLBACK_CONTENT);166 assertBuildDirectoryFileTree("modified-image").containsExactlyInAnyOrder(167 "Dockerfile",168 "jkube-generated-layer-final-artifact",169 "jkube-generated-layer-final-artifact/maven",170 "jkube-generated-layer-final-artifact/maven/test-0.1.0.jar",171 "maven");172 assertThat(resolveDockerBuild("modified-image")173 .resolve("jkube-generated-layer-final-artifact").resolve("maven").resolve("test-0.1.0.jar"))174 .exists().isRegularFile()175 .hasContent("Modified content");176 }177 @Test178 public void withDockerfileInBaseDirectory() throws IOException {179 // Given180 final File dockerFile = new File(baseDirectory, "Dockerfile");181 writeLineToFile(dockerFile, "FROM openjdk:jre");182 final JKubeConfiguration configuration = createJKubeConfiguration();183 final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder()184 .dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).build();185 // When186 File dockerArchiveFile = assemblyManager.createDockerTarArchive("test-image", configuration, jKubeBuildConfiguration, prefixedLogger, null);187 // Then188 assertTargetHasDockerDirectories("test-image");189 ArchiveAssertions.assertThat(dockerArchiveFile)190 .isFile().hasName("docker-build.tar").hasSize(5120)191 .fileTree()192 .containsExactlyInAnyOrder(193 "Dockerfile",194 "maven/",195 "maven/Dockerfile",196 "maven/test-0.1.0.jar",197 "maven/target/",198 "maven/target/test-0.1.0.jar");199 assertDockerFile("test-image").hasContent("FROM openjdk:jre\n");200 assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder(201 "Dockerfile",202 "maven",203 "maven/Dockerfile",204 "maven/test-0.1.0.jar",205 "maven/target",206 "maven/target/test-0.1.0.jar");207 }208 @Test209 public void withDockerfileInBaseDirectoryAndAssemblyFile() throws IOException {210 // Given211 final File dockerFile = new File(baseDirectory, "Dockerfile");212 writeLineToFile(dockerFile, "FROM busybox");213 final File assemblyFile = temporaryFolder.newFile("extra-file-1.txt");214 writeLineToFile(assemblyFile, "HELLO");215 AssemblyConfiguration assemblyConfig = AssemblyConfiguration.builder()216 .inline(Assembly.builder()217 .file(AssemblyFile.builder()218 .source(assemblyFile)219 .outputDirectory(new File("."))220 .build())221 .build())222 .build();223 final JKubeConfiguration configuration = createJKubeConfiguration();224 final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder()225 .dockerFileFile(dockerFile).dockerFile(dockerFile.getPath())226 .assembly(assemblyConfig)227 .build();228 // When229 final File dockerArchiveFile = assemblyManager.createDockerTarArchive(230 "dockerfile-and-assembly-file", configuration, jKubeBuildConfiguration, prefixedLogger, null);231 // Then232 assertTargetHasDockerDirectories("dockerfile-and-assembly-file");233 assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSize(6144);234 assertDockerFile("dockerfile-and-assembly-file").hasContent("FROM busybox\n");235 assertBuildDirectoryFileTree("dockerfile-and-assembly-file").containsExactlyInAnyOrder(236 "Dockerfile",237 "maven",238 "maven/Dockerfile",239 "maven/test-0.1.0.jar",240 "maven/extra-file-1.txt",241 "maven/target",242 "maven/target/test-0.1.0.jar");243 }244 @Test245 public void withDockerfileInBaseDirectoryAndDockerInclude() throws IOException {246 // Given247 final File dockerFile = new File(baseDirectory, "Dockerfile");248 writeLineToFile(dockerFile, "FROM openjdk:jre");249 writeLineToFile(new File(baseDirectory, ".jkube-dockerinclude"), "**/*.txt");250 writeLineToFile(new File(targetDirectory, "ill-be-included.txt"), "Hello");251 writeLineToFile(new File(targetDirectory, "ill-wont-be-included"), "Hello");252 final JKubeConfiguration configuration = createJKubeConfiguration();253 final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder()254 .dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).build();255 // When256 final File dockerArchiveFile = assemblyManager.createDockerTarArchive(257 "test-image", configuration, jKubeBuildConfiguration, prefixedLogger, null);258 // Then259 assertTargetHasDockerDirectories("test-image");260 assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSize(4608);261 assertDockerFile("test-image").hasContent("FROM openjdk:jre\n");262 assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder(263 "Dockerfile",264 "maven",265 "maven/test-0.1.0.jar",266 "maven/target",267 "maven/target/ill-be-included.txt");268 }269 @Test270 public void withDockerfileInBaseDirectoryAndDockerExclude() throws IOException {271 // Given272 final File dockerFile = new File(baseDirectory, "Dockerfile");273 writeLineToFile(dockerFile, "FROM openjdk:jre");274 writeLineToFile(new File(baseDirectory, ".jkube-dockerexclude"), "**/*.txt");275 writeLineToFile(new File(targetDirectory, "ill-wont-be-included.txt"), "Hello");276 writeLineToFile(new File(targetDirectory, "ill-be-included"), "Hello");277 final JKubeConfiguration configuration = createJKubeConfiguration();278 final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder()279 .dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).build();280 // When281 final File dockerArchiveFile = assemblyManager.createDockerTarArchive(282 "test-image", configuration, jKubeBuildConfiguration, prefixedLogger, null);283 // Then284 assertTargetHasDockerDirectories("test-image");285 assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSize(6144);286 assertDockerFile("test-image").hasContent("FROM openjdk:jre\n");287 assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder(288 "Dockerfile",289 "maven",290 "maven/Dockerfile",291 "maven/test-0.1.0.jar",292 "maven/target",293 "maven/target/test-0.1.0.jar",294 "maven/target/ill-be-included");295 }296 @Test297 public void withDockerfileInBaseDirectoryAndDockerIgnore() throws IOException {298 // Given299 final File dockerFile = new File(baseDirectory, "Dockerfile");300 writeLineToFile(dockerFile, "FROM openjdk:jre");301 writeLineToFile(new File(baseDirectory, ".jkube-dockerignore"), "**/*.txt\ntarget/ill-be-ignored-too");302 writeLineToFile(new File(targetDirectory, "ill-be-ignored.txt"), "Hello");303 writeLineToFile(new File(targetDirectory, "ill-be-ignored-too"), "Hello");304 writeLineToFile(new File(targetDirectory, "i-wont-be-ignored"), "Hello");305 final JKubeConfiguration configuration = createJKubeConfiguration();306 final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder()307 .dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).build();308 // When309 File dockerArchiveFile = assemblyManager.createDockerTarArchive("test-image", configuration, jKubeBuildConfiguration, prefixedLogger, null);310 // Then311 assertTargetHasDockerDirectories("test-image");312 assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSize(6144);313 assertDockerFile("test-image").hasContent("FROM openjdk:jre\n");314 assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder(315 "Dockerfile",316 "maven",317 "maven/Dockerfile",318 "maven/test-0.1.0.jar",319 "maven/target",320 "maven/target/test-0.1.0.jar",321 "maven/target/i-wont-be-ignored");322 }323 private void assertTargetHasDockerDirectories(String imageDirName) {324 assertThat(targetDirectory.toPath().resolve("docker").resolve(imageDirName))325 .isDirectory().exists()326 .isDirectoryContaining(p -> p.toFile().isDirectory() && p.toFile().getName().equals("build"))...
Source:AbstractFileAssert.java
...304 * <pre><code class='java'> File xFile = new File("somewhere/xFile.java");305 * File xDirectory = new File("somewhere/xDirectory");306 * 307 * // assertion will pass308 * assertThat(xFile).hasName("xFile.java");309 * assertThat(xDirectory).hasName("xDirectory");310 * 311 * // assertion will fail312 * assertThat(xFile).hasName("xFile");313 * assertThat(xDirectory).hasName("somewhere");</code></pre>314 * 315 * </p>316 * 317 * @param expected the expected {@code File} name.318 * @return {@code this} assertion object.319 * @throws NullPointerException if the expected name is {@code null}.320 * @throws AssertionError if the actual {@code File} is {@code null}.321 * @throws AssertionError if the actual {@code File} does not have the expected name.322 * 323 * @see java.io.File#getName() name definition.324 */325 public S hasName(String expected) {326 files.assertHasName(info, actual, expected);327 return myself;328 }329 /**330 * Verifies that the actual {@code File} does not have a parent.331 * 332 * <p>333 * Example:334 * <pre><code class='java'> File xFile = new File("somewhere/xFile.java");335 * File xDirectory = new File("xDirectory");336 * 337 * // assertion will pass338 * assertThat(xDirectory).hasNoParent();339 * ...
hasName
Using AI Code Generation
1package org.assertj.core.api;2public class AssertjFileAssert extends AbstractFileAssert<AssertjFileAssert> {3 public AssertjFileAssert(java.io.File actual) {4 super(actual, AssertjFileAssert.class);5 }6}7package org.assertj.core.api;8public class Assertions {9 public static AssertjFileAssert assertThat(java.io.File actual) {10 return new AssertjFileAssert(actual);11 }12}13import org.assertj.core.api.Assertions;14public class Test {15 public static void main(String[] args) {16 Assertions.assertThat(new java.io.File("foo")).hasName("foo");17 }18}19import org.assertj.core.api.Assertions;20public class Test {21 public static void main(String[] args) {22 Assertions.assertThat(new java.io.File("foo")).hasName("foo");23 }24}25import org.assertj.core.api.Assertions;26public class Test {27 public static void main(String[] args) {28 Assertions.assertThat(new java.io.File("foo")).hasName("foo");29 }30}31import org.assertj.core.api.Assertions;32public class Test {33 public static void main(String[] args) {34 Assertions.assertThat(new java.io.File("foo")).hasName("foo");35 }36}37import org.assertj.core.api.Assertions;38public class Test {39 public static void main(String[] args) {40 Assertions.assertThat(new java.io.File("foo")).hasName("foo");41 }42}43import org.assertj.core.api.Assertions;44public class Test {45 public static void main(String[] args) {46 Assertions.assertThat(new java.io.File("foo")).hasName("foo");47 }48}49import org.assertj.core.api.Assertions;50public class Test {51 public static void main(String[] args) {52 Assertions.assertThat(new java.io.File("foo")).hasName("foo");53 }54}55import org.assertj.core.api.Assertions;56public class Test {57 public static void main(String[] args) {58 Assertions.assertThat(new java.io.File("foo")).hasName("foo");59 }60}61import org.assertj.core.api.Assertions;62public class Test {63 public static void main(String[] args) {64 Assertions.assertThat(new java.io.File("foo")).has
hasName
Using AI Code Generation
1import org.assertj.core.api.Assertions;2import org.assertj.core.api.AbstractFileAssert;3import java.io.File;4public class Test {5 public static void main(String[] args) {6 File file = new File("C:\\Users\\Admin\\Desktop\\test.txt");7 AbstractFileAssert<?> fileAssert = Assertions.assertThat(file);8 fileAssert.hasName("test.txt");9 }10}
hasName
Using AI Code Generation
1import org.assertj.core.api.AbstractFileAssert;2import java.io.File;3public class Test {4 public static void main(String[] args) {5 File file = new File("/home/user/Desktop/test.txt");6 AbstractFileAssert<?> fileAssert = new AbstractFileAssert<>(file, AbstractFileAssert.class);7 fileAssert.hasName("test.txt");8 }9}
hasName
Using AI Code Generation
1import static org.assertj.core.api.Assertions.assertThat;2import java.io.File;3public class AssertJFileAssert {4 public static void main(String[] args) {5 File file = new File("C:\\Users\\user\\Desktop\\test.txt");6 assertThat(file).hasName("test.txt");7 }8}
hasName
Using AI Code Generation
1import org.assertj.core.api.*;2import java.io.File;3public class 1 {4public static void main(String[] args) {5File file = new File("test.txt");6AbstractFileAssert<?> fileAssert = org.assertj.core.api.Assertions.assertThat(file);7fileAssert.hasName("test.txt");8}9}
hasName
Using AI Code Generation
1import org.assertj.core.api.*;2import org.junit.Test;3import java.io.File;4public class AssertJExample {5 public void testAssertJ() {6 Assertions.assertThat(file).hasName("Chrysanthemum.jpg");7 }8}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!