19d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/*
29d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Copyright 2008 the original author or authors.
39d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
49d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Licensed under the Apache License, Version 2.0 (the "License");
59d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * you may not use this file except in compliance with the License.
69d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * You may obtain a copy of the License at
79d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
89d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *      http://www.apache.org/licenses/LICENSE-2.0
99d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Unless required by applicable law or agreed to in writing, software
119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * distributed under the License is distributed on an "AS IS" BASIS,
129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * See the License for the specific language governing permissions and
149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * limitations under the License.
159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */
169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpackage org.mockftpserver.fake.filesystem
179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.lang.reflect.Constructor
199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.test.AbstractGroovyTest
219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/**
239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Abstract test superclass for subclasses of AbstractFileSystemEntry
249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @version $Revision: $ - $Date: $
269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @author Chris Mair
289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */
299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpublic abstract class AbstractFileSystemEntryTest extends AbstractGroovyTest {
309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    protected static final PATH = "c:/test/dir"
329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the no-argument constructor
359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    void testConstructor_NoArgs() {
379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        AbstractFileSystemEntry entry = (AbstractFileSystemEntry) getImplementationClass().newInstance()
389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertNull("path", entry.getPath())
399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        entry.setPath(PATH)
409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assert entry.getPath() == PATH
419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assert isDirectory() == entry.isDirectory()
429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the constructor that takes a single String parameter
469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    void testConstructor_Path() {
489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        Constructor constructor = getImplementationClass().getConstructor([String.class] as Class[])
499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        AbstractFileSystemEntry entry = (AbstractFileSystemEntry) constructor.newInstance([PATH] as Object[])
509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        LOG.info(entry)
519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("path", PATH, entry.getPath())
529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        entry.setPath("")
539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assert entry.getPath() == ""
549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assert isDirectory() == entry.isDirectory()
559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return the subclass of AbstractFileSystemEntry to be tested
599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    protected abstract Class getImplementationClass()
619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return true if the class being tested represents a directory entry
649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    protected abstract boolean isDirectory()
669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair}
68