/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.commons.io;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/**
 * This class ensure the correctness of {@link FileUtils#copyDirectoryToDirectory(File, File)}.
 * TODO: currently does not cover happy cases
 *
 * @see FileUtils#copyDirectoryToDirectory(File, File)
 */
public class FileUtilsCopyDirectoryToDirectoryTestCase {

    @TempDir
    public File temporaryFolder;

    @Test
    public void copyDirectoryToDirectoryThrowsIllegalExceptionWithCorrectMessageWhenSrcDirIsNotDirectory() throws IOException {
        final File srcDir = File.createTempFile("notadireotry", null, temporaryFolder);
        final File destDir = new File(temporaryFolder, "destinationDirectory");
        destDir.mkdirs();
        final String expectedMessage = String.format("Source '%s' is not a directory", srcDir);
        assertExceptionTypeAndMessage(srcDir, destDir, IllegalArgumentException.class, expectedMessage);
    }

    @Test
    public void copyDirectoryToDirectoryThrowsIllegalArgumentExceptionWithCorrectMessageWhenDstDirIsNotDirectory() throws IOException {
        final File srcDir = new File(temporaryFolder, "sourceDirectory");
        srcDir.mkdir();
        final File destDir = new File(temporaryFolder, "notadirectory");
        destDir.createNewFile();
        String expectedMessage = String.format("Destination '%s' is not a directory", destDir);
        assertExceptionTypeAndMessage(srcDir, destDir, IllegalArgumentException.class, expectedMessage);
    }

    @Test
    public void copyDirectoryToDirectoryThrowsNullPointerExceptionWithCorrectMessageWhenSrcDirIsNull() throws IOException {
        final File srcDir = null;
        final File destinationDirectory = new File(temporaryFolder, "destinationDirectory");
        destinationDirectory.mkdir();
        assertExceptionTypeAndMessage(srcDir, destinationDirectory, NullPointerException.class,  "sourceDir");
    }

    @Test
    public void copyDirectoryToDirectoryThrowsNullPointerExceptionWithCorrectMessageWhenDstDirIsNull() throws IOException {
        final File srcDir = new File(temporaryFolder, "sourceDirectory");
        srcDir.mkdir();
        final File destDir =  null;
        assertExceptionTypeAndMessage(srcDir, destDir, NullPointerException.class, "destinationDir");
    }

    private static void assertExceptionTypeAndMessage(final File srcDir, final File destDir, final Class expectedExceptionType, final String expectedMessage) {
        try {
            FileUtils.copyDirectoryToDirectory(srcDir, destDir);
        } catch (final Exception e) {
            final String msg = e.getMessage();
            assertEquals(expectedExceptionType, e.getClass());
            assertEquals(expectedMessage, msg);
            return;
        }
        fail();
    }
}

@@ -827,32 +827,39 @@
 ons.io;%0A%0Aimport 
+static 
 org.junit.jupite
@@ -864,20 +864,39 @@
 ter.api.
-Test
+Assertions.assertEquals
 ;%0Aimport
@@ -896,16 +896,23 @@
 %0Aimport 
+static 
 org.juni
@@ -929,18 +929,23 @@
 api.
-io.TempDir
+Assertions.fail
 ;%0A%0Ai
@@ -992,39 +992,32 @@
 eption;%0A%0Aimport 
-static 
 org.junit.jupite
@@ -1022,39 +1022,20 @@
 ter.api.
-Assertions.assertEquals
+Test
 ;%0Aimport
@@ -1027,39 +1027,32 @@
 pi.Test;%0Aimport 
-static 
 org.junit.jupite
@@ -1057,31 +1057,26 @@
 ter.api.
-Assertions.fail
+io.TempDir
 ;%0A%0A/**%0A 
@@ -1169,19 +1169,16 @@
  File)%7D.
-%0A *
  TODO: c
@@ -1194,16 +1194,19 @@
 does not
+%0A *
  cover h
@@ -1491,32 +1491,40 @@
 IsNotDirectory()
+%0A       
  throws IOExcept
@@ -2055,16 +2055,24 @@
 ectory()
+%0A       
  throws 
@@ -2609,35 +2609,16 @@
 IsNull()
- throws IOException
  %7B%0A     
@@ -2872,17 +2872,16 @@
 n.class,
- 
  %22source
@@ -3006,35 +3006,16 @@
 IsNull()
- throws IOException
  %7B%0A     
@@ -3135,17 +3135,16 @@
 estDir =
- 
  null;%0A 
@@ -3339,24 +3339,32 @@
 ile destDir,
+%0A       
  final Class
@@ -3363,16 +3363,37 @@
 al Class
+%3C? extends Exception%3E
  expecte

Clean ups.