001/* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2010 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020package net.sf.gridarta.utils; 021 022import java.io.File; 023import javax.swing.filechooser.FileFilter; 024import net.sf.japi.util.filter.file.AbstractFileFilter; 025import org.junit.Assert; 026import org.junit.Test; 027 028/** 029 * Test for {@link HideFileFilterProxy}. 030 * @author <a href="mailto:cher@riedquat.de">Christian Hujer</a> 031 */ 032public class HideFileFilterProxyTest { 033 034 /** 035 * Test case for {@link HideFileFilterProxy#HideFileFilterProxy(FileFilter)}. 036 */ 037 @Test 038 public void testHideFileFilterProxy() { 039 //noinspection ResultOfObjectAllocationIgnored 040 new HideFileFilterProxy(new MockFileFilter(true)); 041 } 042 043 /** 044 * Test case for {@link HideFileFilterProxy#getDescription()}. 045 */ 046 @Test 047 public void testGetDescription() { 048 final FileFilter oUT = new HideFileFilterProxy(new MockFileFilter(true)); 049 Assert.assertEquals("MOCK", oUT.getDescription()); 050 } 051 052 /** 053 * Test case for {@link HideFileFilterProxy#accept(File)}. 054 */ 055 @Test 056 public void testAccept() { 057 final FileFilter oUT1 = new HideFileFilterProxy(new MockFileFilter(true)); 058 Assert.assertTrue(oUT1.accept(new File("foobar"))); 059 //Assert.assertFalse(oUT1.accept(new File("CVS"))); 060 Assert.assertFalse(oUT1.accept(new File(".svn"))); 061 062 final FileFilter oUT2 = new HideFileFilterProxy(new MockFileFilter(false)); 063 Assert.assertFalse(oUT2.accept(new File("foobar"))); 064 //Assert.assertFalse(oUT2.accept(new File("CVS"))); 065 Assert.assertFalse(oUT2.accept(new File(".svn"))); 066 } 067 068 /** 069 * Mock File Filter that's used as parent file filter for the 070 * HideFileFilterProxy under test. 071 * @author <a href="mailto:cher@riedquat.de">Christian Hujer</a> 072 */ 073 private static class MockFileFilter extends AbstractFileFilter { 074 075 /** 076 * Whether this file filter will accept or reject files. 077 */ 078 private final boolean accepts; 079 080 /** 081 * Create a MockFileFilter. 082 * @param accepts whether this file filter will accept or reject files 083 */ 084 private MockFileFilter(final boolean accepts) { 085 this.accepts = accepts; 086 } 087 088 @Override 089 public boolean accept(final File f) { 090 return accepts; 091 } 092 093 @Override 094 public String getDescription() { 095 return "MOCK"; 096 } 097 098 } 099 100}