Skip to content

Commit

Permalink
Issue #1: Added unit tests for ImageFileFilter.
Browse files Browse the repository at this point in the history
  • Loading branch information
FridaTveit committed Dec 19, 2016
1 parent 8f12182 commit 044a66d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.3.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
64 changes: 64 additions & 0 deletions src/test/java/net/sf/javaanpr/gui/tools/ImageFileFilterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2013 JavaANPR contributors
* Copyright 2006 Ondrej Martinsky
* Licensed under the Educational Community 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.osedu.org/licenses/ECL-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 net.sf.javaanpr.gui.tools;

import org.junit.Test;

import java.io.File;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;

public class ImageFileFilterTest {
@Test
public void testAcceptsJpgFileName() {
assertTrue(ImageFileFilter.accept("some name.jpg"));
}

@Test
public void testAcceptsBmpFileName() {
assertTrue(ImageFileFilter.accept("some name.bmp"));
}

@Test
public void testAcceptsGifFileName() {
assertTrue(ImageFileFilter.accept("some name.gif"));
}

@Test
public void testAcceptsPngFileName() {
assertTrue(ImageFileFilter.accept("some name.png"));
}

@Test
public void testDoesNotAcceptFileNameWithoutExtension() {
assertFalse(ImageFileFilter.accept("some name"));
}

@Test
public void testDoesNotAcceptFileNameWithIncorrectExtension() {
assertFalse(ImageFileFilter.accept("some name.txt"));
}

@Test
public void testAcceptsDirectory() {
File mockedFile = mock(File.class);
when(mockedFile.isDirectory()).thenReturn(true);
assertTrue(new ImageFileFilter().accept(mockedFile));
}
}

0 comments on commit 044a66d

Please sign in to comment.