/*
 * 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.netbeans.modules.java.project.ui;

import org.netbeans.modules.java.project.ui.JavaTargetChooserPanel;
import java.io.File;
import org.netbeans.junit.NbTestCase;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;

/**
 *
 * @author Jiri Rechtacek
 */
public class JavaTargetChooserPanelTest extends NbTestCase {
    FileObject root = null;

    public JavaTargetChooserPanelTest (String testName) {
        super (testName);
    }

    protected void setUp () throws Exception {
        super.setUp ();
        clearWorkDir ();
    }

    // tests #51135: checked existence of multiple dotted package name
    public void testCanUseFileName () throws Exception {
        File rootFile = getWorkDir ();
        assertNotNull ("WorkDir exists.", rootFile);
        root = FileUtil.toFileObject (rootFile);
        if (!root.canWrite ()) {
            fail ("Cannot create test folder.");
        }

        root = root.createFolder ("testCanUseFileName");

        assertNotNull (root + " exists.", FileUtil.toFile (root));
        assertTrue ("Package aaa.bbb.ccc can be created.", JavaTargetChooserPanel.canUseFileName (root, "", "aaa.bbb.ccc", "") == null);

        assertNotNull ("Package aaa.bbb.ccc was created.", root.createFolder ("aaa").createFolder ("bbb").createFolder ("ccc"));
        assertTrue ("Package aaa cannot be created.", JavaTargetChooserPanel.canUseFileName (root, "", "aaa", "") != null);
        assertTrue ("Package aaa.bbb cannot be created.", JavaTargetChooserPanel.canUseFileName (root, "", "aaa.bbb", "") != null);
        assertTrue ("Package aaa.bbb.ccc cannot be created.", JavaTargetChooserPanel.canUseFileName (root, "", "aaa.bbb.ccc", "") != null);
        assertTrue ("Package ddd can be created.", JavaTargetChooserPanel.canUseFileName (root, "", "ddd", "") == null);
    }
    
}
