/**
 * Copyright (c) 2016, German Neuroinformatics Node (G-Node)
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted under the terms of the BSD License. See
 * LICENSE file in the root of the Project.
 */

package org.g_node.micro.commons;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Unit tests for the {@link AppUtils} class.
 *
 * @author Michael Sonntag (sonntag@bio.lmu.de)
 */
public final class AppUtilsTest {

    /**
     * Method checks that the {@link AppUtils} getHashSHA method returns
     * the proper hex hash for a List of String entries.
     */
    @Test
    public void testGetHashSHA() {
        final String checkHexSHA = "e5c055cdf43af5be8972d5a94c8d0182296de89b";

        final ArrayList<String> testHashLower = new ArrayList<>(Arrays.asList("hash", "me"));
        assertThat(checkHexSHA.equals(AppUtils.getHashSHA(testHashLower))).isTrue();

        final ArrayList<String> testHashMixed = new ArrayList<>(Arrays.asList("Hash", "Me"));
        assertThat(checkHexSHA.equals(AppUtils.getHashSHA(testHashMixed))).isTrue();

        final List<String> testHashSingleEntry = Collections.singletonList("Hash me");
        assertThat(checkHexSHA.equals(AppUtils.getHashSHA(testHashSingleEntry))).isTrue();

        final List<String> testDiff = Collections.singletonList("hashme");
        assertThat(checkHexSHA.equals(AppUtils.getHashSHA(testDiff))).isFalse();
    }

    /**
     * Method checks via regular expression that the method returns a valid timestamp.
     */
    @Test
    public void testGetTimeStamp() {
        final String testFormat = "dd.MM.yyyy HH:mm";
        final String regEx = String.join("",
                "([0][1-9]|[1-2][0-9]|[3][0-1]).([0][1-9]|[1][0-2]).(20\\d\\d) ",
                "([0-1][0-9]|[2][0-3]):[0-5][0-9]");

        final String getFormattedTimeStamp = AppUtils.getTimeStamp(testFormat);
        assertThat(getFormattedTimeStamp).matches(regEx);
    }

}

@@ -430,25 +430,59 @@
 ort 
-org.junit.Tes
+static org.assertj.core.api.Assertions.assertTha
 t;%0A
-%0A
 impo
@@ -523,25 +523,52 @@
 ertions.
-assertTha
+catchThrowable;%0Aimport org.junit.Tes
 t;%0A%0A/**%0A
@@ -1683,38 +1683,36 @@
 %0A    /**%0A     * 
-Method
+Test
  checks via regu
@@ -1769,16 +1769,116 @@
 estamp.%0A
+     * Further checks that a proper exception is thrown if a Non-DateTimeFormatter pattern is used.%0A
      */%0A
@@ -1921,16 +1921,33 @@
 eStamp()
+ throws Exception
  %7B%0A     
@@ -2313,16 +2313,343 @@
 (regEx);
+%0A%0A        final String testInvalidFormat = %22something definitely not dateTime%22;%0A        Throwable thrown = catchThrowable(() -%3E AppUtils.getTimeStamp(testInvalidFormat));%0A        assertThat(thrown)%0A                .isInstanceOf(IllegalArgumentException.class)%0A                .hasMessageContaining(%22Unknown pattern letter: o%22);
 %0A    %7D%0A%0A

Update AppUtils getTimeStamp test