Gridarta Editor
HideFileFilterProxyTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.utils;
21 
22 import java.io.File;
23 import javax.swing.filechooser.FileFilter;
24 import net.sf.japi.util.filter.file.AbstractFileFilter;
25 import org.junit.Assert;
26 import org.junit.Ignore;
27 import org.junit.Test;
28 
34 
38  @Test
39  public void testHideFileFilterProxy() {
40  //noinspection ResultOfObjectAllocationIgnored
41  new HideFileFilterProxy(new MockFileFilter(true));
42  }
43 
47  @Test
48  public void testGetDescription() {
49  final FileFilter oUT = new HideFileFilterProxy(new MockFileFilter(true));
50  Assert.assertEquals("MOCK", oUT.getDescription());
51  }
52 
56  @Ignore("Tests fail because filtered directories do not exist")
57  @Test
58  public void testAccept() {
59  final FileFilter oUT1 = new HideFileFilterProxy(new MockFileFilter(true));
60  Assert.assertTrue(oUT1.accept(new File("foobar")));
61  Assert.assertFalse(oUT1.accept(new File("CVS")));
62  Assert.assertFalse(oUT1.accept(new File(".git")));
63  Assert.assertFalse(oUT1.accept(new File(".svn")));
64 
65  final FileFilter oUT2 = new HideFileFilterProxy(new MockFileFilter(false));
66  Assert.assertFalse(oUT2.accept(new File("foobar")));
67  Assert.assertFalse(oUT2.accept(new File("CVS")));
68  Assert.assertFalse(oUT2.accept(new File(".git")));
69  Assert.assertFalse(oUT2.accept(new File(".svn")));
70  }
71 
77  private static class MockFileFilter extends AbstractFileFilter {
78 
82  private final boolean accepts;
83 
88  private MockFileFilter(final boolean accepts) {
89  this.accepts = accepts;
90  }
91 
92  @Override
93  public boolean accept(final File f) {
94  return accepts;
95  }
96 
97  @Override
98  public String getDescription() {
99  return "MOCK";
100  }
101 
102  }
103 
104 }
MockFileFilter(final boolean accepts)
Create a MockFileFilter.
A FileFilter that wraps another FileFilter and filters out version control directories.
void testHideFileFilterProxy()
Test case for HideFileFilterProxy#HideFileFilterProxy(FileFilter).
final boolean accepts
Whether this file filter will accept or reject files.
Mock File Filter that's used as parent file filter for the HideFileFilterProxy under test...
void testGetDescription()
Test case for HideFileFilterProxy#getDescription().
void testAccept()
Test case for HideFileFilterProxy#accept(File).