/*
 * Copyright 2019 Michael Sean Gilligan
 *
 * 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.bitcoinj.utils;

import org.bitcoinj.core.Utils;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * Basic test of AppDataDirectory
 */
public class AppDataDirectoryTest {
    private static final String HOMEDIR = System.getProperty("user.home");
    private static final String WINAPPDATA = System.getenv("APPDATA");

    @Test
    public void worksOnCurrentPlatform() {
        final String appName = "bitcoinj";
        String path = AppDataDirectory.get(appName).toString();
        if (Utils.isWindows()) {
            assertEquals("Path wrong on Mac", winPath(appName), path);
        } else if (Utils.isMac()) {
            assertEquals("Path wrong on Mac",  macPath(appName), path);
        } else if (Utils.isLinux()) {
            assertEquals("Path wrong on Linux",  unixPath(appName), path);
        } else {
            assertEquals("Path wrong on unknown/default",  unixPath(appName), path);
        }
    }

    @Test
    public void worksOnCurrentPlatformForBitcoinCore() {
        final String appName = "Bitcoin";
        String path = AppDataDirectory.get(appName).toString();
        if (Utils.isWindows()) {
            assertEquals("Path wrong on Mac", winPath(appName), path);
        } else if (Utils.isMac()) {
            assertEquals("Path wrong on Mac",  macPath(appName), path);
        } else if (Utils.isLinux()) {
            assertEquals("Path wrong on Linux",  unixPath(appName), path);
        } else {
            assertEquals("Path wrong on unknown/default",  unixPath(appName), path);
        }
    }

    private static String winPath(String appName) {
        return WINAPPDATA + "\\." + appName.toLowerCase();
    }

    private static String macPath(String appName) {
        return HOMEDIR + "/Library/Application Support/" + appName;
    }

    private static String unixPath(String appName) {
        return HOMEDIR + "/." + appName.toLowerCase();
    }
}

@@ -36,16 +36,47 @@
 illigan%0A
+ * Copyright 2019 Tim Strasser%0A
  *%0A * Li
@@ -2198,32 +2198,596 @@
        %7D%0A    %7D%0A%0A
+    @Test(expected = RuntimeException.class)%0A    public void throwsIOExceptionIfPathNotFound() %7B%0A        // The null character is non printable and an ASCII control character%0A        // Forbidden on all OSs%0A        if (Utils.isWindows()) %7B%0A            AppDataDirectory.get(%22/%22);%0A        %7D%0A        if (Utils.isMac()) %7B%0A            // The only illegal character for folder names in OSX is the colon%0A            AppDataDirectory.get(%22:%22);%0A        %7D%0A        if (Utils.isLinux()) %7B%0A            // NUL character%0A            AppDataDirectory.get(%22%5C0%22);%0A        %7D%0A    %7D%0A%0A%0A
     private stat

Implement a test for case of invalid directory name