// Path: src/main/java/org/simplify4u/plugins/ValidationChecksum.java
// static final class Builder {
// 
//     private static final String FILENAME_CHECKSUM_PRIOR_VALIDATION = "pgpverify-prior-validation-checksum";
// 
//     private static final Logger LOG = LoggerFactory.getLogger(Builder.class);
// 
//     private File file;
// 
//     private boolean disabled;
// 
//     private Iterable<Artifact> artifacts;
// 
//     Builder() {
//     }
// 
//     /**
//      * Destination for checksum file.
//      *
//      * @param directory the target directory
//      */
//     Builder destination(File directory) {
//         this.file = new File(directory, FILENAME_CHECKSUM_PRIOR_VALIDATION);
//         return this;
//     }
// 
//     /**
//      * Set whether checksum calculation is disabled.
//      *
//      * @param disabled true if checksum is disabled, false otherwise.
//      */
//     Builder disabled(boolean disabled) {
//         this.disabled = disabled;
//         return this;
//     }
// 
//     /**
//      * Perform checksum calculation on artifacts.
//      *
//      * @param artifacts the artifacts as deterministically ordered collection
//      */
//     Builder artifacts(Iterable<Artifact> artifacts) {
//         this.artifacts = requireNonNull(artifacts);
//         return this;
//     }
// 
//     /**
//      * Build ValidationChecksum instance.
//      *
//      * @return Returns the validation checksum instance.
//      */
//     ValidationChecksum build() {
//         if (this.artifacts == null) {
//             throw new IllegalStateException("artifacts need to be provided");
//         }
//         return new ValidationChecksum(this.file, this.disabled ? new byte[0] : calculateChecksum());
//     }
// 
//     private byte[] calculateChecksum() {
//         final SHA256Digest digest = new SHA256Digest();
//         final byte[] result = new byte[digest.getDigestSize()];
//         for (final Artifact artifact : this.artifacts) {
//             final byte[] id = artifact.getId().getBytes(UTF_8);
//             digest.update(id, 0, id.length);
//             digest.update((byte) '\0');
//         }
//         digest.doFinal(result, 0);
//         if (LOG.isDebugEnabled()) {
//             LOG.debug("Checksum of resolved artifacts: {}", ByteUtils.toHexString(result, "0x", ""));
//         }
//         return result;
//     }
// }


import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import org.apache.maven.artifact.Artifact;
import org.simplify4u.plugins.ValidationChecksum.Builder;
import org.testng.annotations.AfterMethod;
/*
 * Copyright 2020 Danny van Heumen
 *
 * 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 org.simplify4u.plugins;




public class ValidationChecksumTest {

    private File checksumdirectory = null;

    @BeforeMethod
    public void setUp() throws IOException {
        this.checksumdirectory = Files.createTempDirectory("ValidationChecksumTest").toFile();
    }

    @AfterMethod
    public void tearDown() throws IOException {
        Files.walk(checksumdirectory.toPath())
                .sorted(Comparator.reverseOrder())
                .map(Path::toFile)
                .forEach(File::delete);
    }

    @Test
    public void testValidationChecksumBuilderNullFile() {
// Path: src/main/java/org/simplify4u/plugins/ValidationChecksum.java
// static final class Builder {
// 
//     private static final String FILENAME_CHECKSUM_PRIOR_VALIDATION = "pgpverify-prior-validation-checksum";
// 
//     private static final Logger LOG = LoggerFactory.getLogger(Builder.class);
// 
//     private File file;
// 
//     private boolean disabled;
// 
//     private Iterable<Artifact> artifacts;
// 
//     Builder() {
//     }
// 
//     /**
//      * Destination for checksum file.
//      *
//      * @param directory the target directory
//      */
//     Builder destination(File directory) {
//         this.file = new File(directory, FILENAME_CHECKSUM_PRIOR_VALIDATION);
//         return this;
//     }
// 
//     /**
//      * Set whether checksum calculation is disabled.
//      *
//      * @param disabled true if checksum is disabled, false otherwise.
//      */
//     Builder disabled(boolean disabled) {
//         this.disabled = disabled;
//         return this;
//     }
// 
//     /**
//      * Perform checksum calculation on artifacts.
//      *
//      * @param artifacts the artifacts as deterministically ordered collection
//      */
//     Builder artifacts(Iterable<Artifact> artifacts) {
//         this.artifacts = requireNonNull(artifacts);
//         return this;
//     }
// 
//     /**
//      * Build ValidationChecksum instance.
//      *
//      * @return Returns the validation checksum instance.
//      */
//     ValidationChecksum build() {
//         if (this.artifacts == null) {
//             throw new IllegalStateException("artifacts need to be provided");
//         }
//         return new ValidationChecksum(this.file, this.disabled ? new byte[0] : calculateChecksum());
//     }
// 
//     private byte[] calculateChecksum() {
//         final SHA256Digest digest = new SHA256Digest();
//         final byte[] result = new byte[digest.getDigestSize()];
//         for (final Artifact artifact : this.artifacts) {
//             final byte[] id = artifact.getId().getBytes(UTF_8);
//             digest.update(id, 0, id.length);
//             digest.update((byte) '\0');
//         }
//         digest.doFinal(result, 0);
//         if (LOG.isDebugEnabled()) {
//             LOG.debug("Checksum of resolved artifacts: {}", ByteUtils.toHexString(result, "0x", ""));
//         }
//         return result;
//     }
// }


// Path: src/test/java/org/simplify4u/plugins/ValidationChecksumTest.java
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import org.apache.maven.artifact.Artifact;
import org.simplify4u.plugins.ValidationChecksum.Builder;
import org.testng.annotations.AfterMethod;

/*
 * Copyright 2020 Danny van Heumen
 *
 * 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 org.simplify4u.plugins;




public class ValidationChecksumTest {

    private File checksumdirectory = null;

    @BeforeMethod
    public void setUp() throws IOException {
        this.checksumdirectory = Files.createTempDirectory("ValidationChecksumTest").toFile();
    }

    @AfterMethod
    public void tearDown() throws IOException {
        Files.walk(checksumdirectory.toPath())
                .sorted(Comparator.reverseOrder())
                .map(Path::toFile)
                .forEach(File::delete);
    }

    @Test
    public void testValidationChecksumBuilderNullFile() {
        new ValidationChecksum.Builder().destination(null).artifacts(emptyList()).build();