How to use assertHasDigest method of org.assertj.core.internal.Paths class

Best Assertj code snippet using org.assertj.core.internal.Paths.assertHasDigest

Source:Paths_assertHasDigest_AlgorithmBytes_Test.java Github

copy

Full Screen

...28import org.junit.jupiter.api.Test;29import org.mockito.BDDMockito;30import org.mockito.Mockito;31/**32 * Tests for <code>{@link Paths#assertHasDigest(AssertionInfo, Path, String, byte[])}</code>33 *34 * @author Valeriy Vyrva35 */36public class Paths_assertHasDigest_AlgorithmBytes_Test extends MockPathsBaseTest {37 private final String algorithm = "MD5";38 private final byte[] expected = new byte[0];39 private final String real = "3AC1AFA2A89B7E4F1866502877BF1DC5";40 @Test41 public void should_fail_if_actual_is_null() {42 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasDigest(info, null, algorithm, expected)).withMessage(FailureMessages.actualIsNull());43 }44 @Test45 public void should_fail_with_should_exist_error_if_actual_does_not_exist() {46 // GIVEN47 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(false);48 // WHEN49 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));50 // THEN51 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldExist.shouldExist(actual));52 }53 @Test54 public void should_fail_if_actual_exists_but_is_not_file() {55 // GIVEN56 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);57 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(false);58 // WHEN59 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));60 // THEN61 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldBeRegularFile.shouldBeRegularFile(actual));62 }63 @Test64 public void should_fail_if_actual_exists_but_is_not_readable() {65 // GIVEN66 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);67 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);68 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(false);69 // WHEN70 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));71 // THEN72 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldBeReadable.shouldBeReadable(actual));73 }74 @Test75 public void should_throw_error_if_digest_is_null() {76 Assertions.assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, null, ((MessageDigest) (null)), expected)).withMessage("The message digest algorithm should not be null");77 }78 @Test79 public void should_throw_error_if_expected_is_null() {80 Assertions.assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, null, algorithm, ((byte[]) (null)))).withMessage("The binary representation of digest to compare to should not be null");81 }82 @Test83 public void should_throw_error_wrapping_catched_IOException() throws IOException {84 // GIVEN85 IOException cause = new IOException();86 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);87 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);88 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(true);89 BDDMockito.given(nioFilesWrapper.newInputStream(actual)).willThrow(cause);90 // WHEN91 Throwable error = Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));92 // THEN93 Assertions.assertThat(error).isInstanceOf(UncheckedIOException.class).hasCause(cause);94 }95 @Test96 public void should_throw_error_wrapping_catched_NoSuchAlgorithmException() {97 // GIVEN98 String unknownDigestAlgorithm = "UnknownDigestAlgorithm";99 // WHEN100 Throwable error = Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, unknownDigestAlgorithm, expected));101 // THEN102 Assertions.assertThat(error).isInstanceOf(IllegalStateException.class).hasMessage("Unable to find digest implementation for: <UnknownDigestAlgorithm>");103 }104 @Test105 public void should_fail_if_actual_does_not_have_expected_digest() throws IOException, NoSuchAlgorithmException {106 // GIVEN107 InputStream stream = getClass().getResourceAsStream("/red.png");108 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);109 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);110 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(true);111 BDDMockito.given(nioFilesWrapper.newInputStream(actual)).willReturn(stream);112 // WHEN113 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));114 // THEN115 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldHaveDigest.shouldHaveDigest(actual, new DigestDiff(real, "", MessageDigest.getInstance(algorithm))));116 MockPathsBaseTest.failIfStreamIsOpen(stream);117 }118 @Test119 public void should_pass_if_actual_has_expected_digest() throws IOException {120 // GIVEN121 InputStream stream = getClass().getResourceAsStream("/red.png");122 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);123 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);124 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(true);125 BDDMockito.given(nioFilesWrapper.newInputStream(actual)).willReturn(stream);126 // WHEN127 paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, Digests.fromHex(real));128 // THEN129 MockPathsBaseTest.failIfStreamIsOpen(stream);130 }131}...

Full Screen

Full Screen

Source:Paths_assertHasDigest_AlgorithmString_Test.java Github

copy

Full Screen

...28import org.junit.jupiter.api.Test;29import org.mockito.BDDMockito;30import org.mockito.Mockito;31/**32 * Tests for <code>{@link Paths#assertHasDigest(AssertionInfo, Path, String, String)}</code>33 *34 * @author Valeriy Vyrva35 */36public class Paths_assertHasDigest_AlgorithmString_Test extends MockPathsBaseTest {37 private final String algorithm = "MD5";38 private final String expected = "";39 private final String real = "3AC1AFA2A89B7E4F1866502877BF1DC5";40 @Test41 public void should_fail_if_actual_is_null() {42 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasDigest(info, null, algorithm, expected)).withMessage(FailureMessages.actualIsNull());43 }44 @Test45 public void should_fail_with_should_exist_error_if_actual_does_not_exist() {46 // GIVEN47 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(false);48 // WHEN49 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));50 // THEN51 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldExist.shouldExist(actual));52 }53 @Test54 public void should_fail_if_actual_exists_but_is_not_file() {55 // GIVEN56 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);57 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(false);58 // WHEN59 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));60 // THEN61 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldBeRegularFile.shouldBeRegularFile(actual));62 }63 @Test64 public void should_fail_if_actual_exists_but_is_not_readable() {65 // GIVEN66 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);67 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);68 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(false);69 // WHEN70 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));71 // THEN72 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldBeReadable.shouldBeReadable(actual));73 }74 @Test75 public void should_throw_error_if_digest_is_null() {76 Assertions.assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, null, ((MessageDigest) (null)), expected)).withMessage("The message digest algorithm should not be null");77 }78 @Test79 public void should_throw_error_if_expected_is_null() {80 Assertions.assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, null, algorithm, ((byte[]) (null)))).withMessage("The binary representation of digest to compare to should not be null");81 }82 @Test83 public void should_throw_error_wrapping_catched_IOException() throws IOException {84 // GIVEN85 IOException cause = new IOException();86 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);87 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);88 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(true);89 BDDMockito.given(nioFilesWrapper.newInputStream(actual)).willThrow(cause);90 // WHEN91 Throwable error = Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));92 // THEN93 Assertions.assertThat(error).isInstanceOf(UncheckedIOException.class).hasCause(cause);94 }95 @Test96 public void should_throw_error_wrapping_catched_NoSuchAlgorithmException() {97 // GIVEN98 String unknownDigestAlgorithm = "UnknownDigestAlgorithm";99 // WHEN100 Throwable error = Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, unknownDigestAlgorithm, expected));101 // THEN102 Assertions.assertThat(error).isInstanceOf(IllegalStateException.class).hasMessage("Unable to find digest implementation for: <UnknownDigestAlgorithm>");103 }104 @Test105 public void should_fail_if_actual_does_not_have_expected_digest() throws IOException, NoSuchAlgorithmException {106 // GIVEN107 InputStream stream = getClass().getResourceAsStream("/red.png");108 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);109 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);110 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(true);111 BDDMockito.given(nioFilesWrapper.newInputStream(actual)).willReturn(stream);112 // WHEN113 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, expected));114 // THEN115 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldHaveDigest.shouldHaveDigest(actual, new DigestDiff(real, "", MessageDigest.getInstance(algorithm))));116 MockPathsBaseTest.failIfStreamIsOpen(stream);117 }118 @Test119 public void should_pass_if_actual_has_expected_digest() throws IOException {120 // GIVEN121 InputStream stream = getClass().getResourceAsStream("/red.png");122 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);123 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);124 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(true);125 BDDMockito.given(nioFilesWrapper.newInputStream(actual)).willReturn(stream);126 // WHEN127 paths.assertHasDigest(MockPathsBaseTest.INFO, actual, algorithm, Digests.fromHex(real));128 // THEN129 MockPathsBaseTest.failIfStreamIsOpen(stream);130 }131}...

Full Screen

Full Screen

Source:Paths_assertHasDigest_DigestBytes_Test.java Github

copy

Full Screen

...26import org.junit.jupiter.api.Test;27import org.mockito.BDDMockito;28import org.mockito.Mockito;29/**30 * Tests for <code>{@link Paths#assertHasDigest(AssertionInfo, Path, MessageDigest, byte[])}</code>31 *32 * @author Valeriy Vyrva33 */34public class Paths_assertHasDigest_DigestBytes_Test extends MockPathsBaseTest {35 private final MessageDigest digest = Mockito.mock(MessageDigest.class);36 private final byte[] expected = new byte[0];37 @Test38 public void should_fail_if_actual_is_null() {39 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasDigest(info, null, digest, expected)).withMessage(FailureMessages.actualIsNull());40 }41 @Test42 public void should_fail_with_should_exist_error_if_actual_does_not_exist() {43 // GIVEN44 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(false);45 // WHEN46 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, digest, expected));47 // THEN48 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldExist.shouldExist(actual));49 }50 @Test51 public void should_fail_if_actual_exists_but_is_not_file() {52 // GIVEN53 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);54 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(false);55 // WHEN56 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, digest, expected));57 // THEN58 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldBeRegularFile.shouldBeRegularFile(actual));59 }60 @Test61 public void should_fail_if_actual_exists_but_is_not_readable() {62 // GIVEN63 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);64 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);65 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(false);66 // WHEN67 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, digest, expected));68 // THEN69 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldBeReadable.shouldBeReadable(actual));70 }71 @Test72 public void should_throw_error_if_digest_is_null() {73 Assertions.assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, null, ((MessageDigest) (null)), expected)).withMessage("The message digest algorithm should not be null");74 }75 @Test76 public void should_throw_error_if_expected_is_null() {77 Assertions.assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, null, digest, ((byte[]) (null)))).withMessage("The binary representation of digest to compare to should not be null");78 }79 @Test80 public void should_throw_error_wrapping_catched_IOException() throws IOException {81 // GIVEN82 IOException cause = new IOException();83 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);84 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);85 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(true);86 BDDMockito.given(nioFilesWrapper.newInputStream(actual)).willThrow(cause);87 // WHEN88 Throwable error = Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, digest, expected));89 // THEN90 Assertions.assertThat(error).isInstanceOf(UncheckedIOException.class).hasCause(cause);91 }92 @Test93 public void should_throw_error_wrapping_catched_NoSuchAlgorithmException() {94 // GIVEN95 String unknownDigestAlgorithm = "UnknownDigestAlgorithm";96 // WHEN97 Throwable error = Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, unknownDigestAlgorithm, expected));98 // THEN99 Assertions.assertThat(error).isInstanceOf(IllegalStateException.class).hasMessage("Unable to find digest implementation for: <UnknownDigestAlgorithm>");100 }101 @Test102 public void should_fail_if_actual_does_not_have_expected_digest() throws IOException {103 // GIVEN104 InputStream stream = getClass().getResourceAsStream("/red.png");105 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);106 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);107 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(true);108 BDDMockito.given(nioFilesWrapper.newInputStream(actual)).willReturn(stream);109 BDDMockito.given(digest.digest()).willReturn(new byte[]{ 0, 1 });110 // WHEN111 Assertions.catchThrowable(() -> paths.assertHasDigest(MockPathsBaseTest.INFO, actual, digest, expected));112 // THEN113 Mockito.verify(failures).failure(MockPathsBaseTest.INFO, ShouldHaveDigest.shouldHaveDigest(actual, new DigestDiff("0001", "", digest)));114 MockPathsBaseTest.failIfStreamIsOpen(stream);115 }116 @Test117 public void should_pass_if_actual_has_expected_digest() throws IOException {118 // GIVEN119 InputStream stream = getClass().getResourceAsStream("/red.png");120 BDDMockito.given(nioFilesWrapper.exists(actual)).willReturn(true);121 BDDMockito.given(nioFilesWrapper.isRegularFile(actual)).willReturn(true);122 BDDMockito.given(nioFilesWrapper.isReadable(actual)).willReturn(true);123 BDDMockito.given(nioFilesWrapper.newInputStream(actual)).willReturn(stream);124 BDDMockito.given(digest.digest()).willReturn(expected);125 // WHEN126 paths.assertHasDigest(MockPathsBaseTest.INFO, actual, digest, expected);127 // THEN128 MockPathsBaseTest.failIfStreamIsOpen(stream);129 }130}...

Full Screen

Full Screen

assertHasDigest

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.internal.paths;2import static org.assertj.core.api.Assertions.assertThat;3import static org.assertj.core.api.Assertions.catchThrowable;4import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest;5import static org.assertj.core.test.TestData.someInfo;6import static org.assertj.core.util.FailureMessages.actualIsNull;7import static org.assertj.core.util.Sets.newLinkedHashSet;8import static org.assertj.core.util.Sets.newTreeSet;9import java.io.File;10import java.io.IOException;11import java.nio.file.Path;12import java.nio.file.Paths;13import java.security.MessageDigest;14import java.security.NoSuchAlgorithmException;15import java.util.Set;16import org.assertj.core.api.AssertionInfo;17import org.assertj.core.internal.PathsBaseTest;18import org.junit.jupiter.api.DisplayName;19import org.junit.jupiter.api.Test;20@DisplayName("Paths assertHasDigest")21class Paths_assertHasDigest_Test extends PathsBaseTest {22 void should_fail_if_actual_is_null() {23 Path actual = null;24 String algorithm = "MD5";25 String expected = "some digest";26 Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected));27 assertThat(thrown).isInstanceOf(AssertionError.class);28 verifyFailureThrownWhenActualIsNull();29 }30 void should_fail_if_actual_does_not_exist() {31 Path actual = notExistingPath;32 String algorithm = "MD5";33 String expected = "some digest";34 Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected));35 assertThat(thrown).isInstanceOf(AssertionError.class);36 verifyFailureThrownWhenActualDoesNotExist();37 }38 void should_fail_if_actual_is_not_a_file() {39 Path actual = existingDirectory;40 String algorithm = "MD5";41 String expected = "some digest";42 Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected));43 assertThat(thrown).isInstanceOf(AssertionError.class);

Full Screen

Full Screen

assertHasDigest

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.AssertionInfo;2import org.assertj.core.api.PathAssert;3import org.assertj.core.api.PathAssertBaseTest;4import org.assertj.core.internal.Paths;5import org.junit.jupiter.api.BeforeEach;6import org.junit.jupiter.api.Test;7import java.nio.file.Path;8import static org.mockito.Mockito.verify;9public class PathAssert_assertHasDigest_Test extends PathAssertBaseTest {10 private Paths paths;11 public void setUp() {12 super.setUp();13 paths = mock(Paths.class);14 assertions.paths = paths;15 }16 public void should_verify_that_actual_has_digest() {17 String digest = "digest";18 assertions.assertHasDigest(digest);19 verify(paths).assertHasDigest(getInfo(assertions), getActual(assertions), digest);20 }21}22public class PathAssert extends PathAssertBase<PathAssert, Path> {23 Paths paths = Paths.instance();24 public PathAssert(Path actual) {25 super(actual, PathAssert.class);26 }27 public PathAssert assertHasDigest(String digest) {28 paths.assertHasDigest(info, actual, digest);29 return myself;30 }31}32 extends AbstractAssert<SELF, ACTUAL> {33 protected PathAssertBase(ACTUAL actual, Class<?> selfType) {34 super(actual, selfType);35 }36 public SELF isRegularFile() {37 paths.assertIsRegularFile(info, actual);38 return myself;39 }40 public SELF isDirectory() {41 paths.assertIsDirectory(info, actual);42 return myself;43 }44 public SELF hasFileName(String expected) {45 paths.assertHasFileName(info, actual, expected);46 return myself;47 }48 public SELF exists() {49 paths.assertExists(info, actual);50 return myself;51 }52 public SELF doesNotExist() {53 paths.assertDoesNotExist(info, actual);54 return myself;55 }56 public SELF hasParent(Path expected) {57 paths.assertHasParent(info, actual, expected);58 return myself;59 }60 public SELF hasParent(String expected) {

Full Screen

Full Screen

assertHasDigest

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import static org.assertj.core.api.Assertions.assertThat;3public class AssertHasDigest {4 public void test() {5 assertThat(new java.io.File("1.java")).hasDigest("MD5", "5f6b5e6b5e6b5e6b5e6b5e6b5e6b5e6b");6 }7}8 at org.junit.Assert.assertEquals(Assert.java:115)9 at org.junit.Assert.assertEquals(Assert.java:144)10 at org.assertj.core.internal.Digests.assertHasDigest(Digests.java:91)11 at org.assertj.core.internal.Digests.assertHasDigest(Digests.java:82)12 at org.assertj.core.api.AbstractPathAssert.hasDigest(AbstractPathAssert.java:330)13 at AssertHasDigest.test(AssertHasDigest.java:8)

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful