From 044a66db174ac6b1eb2c0f625371ba95543b2385 Mon Sep 17 00:00:00 2001 From: Frida Tveit Date: Mon, 19 Dec 2016 15:33:31 +0000 Subject: [PATCH] Issue #1: Added unit tests for ImageFileFilter. --- pom.xml | 6 ++ .../gui/tools/ImageFileFilterTest.java | 64 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/test/java/net/sf/javaanpr/gui/tools/ImageFileFilterTest.java diff --git a/pom.xml b/pom.xml index 92d3c45..71b1749 100644 --- a/pom.xml +++ b/pom.xml @@ -300,6 +300,12 @@ 4.12 test + + org.mockito + mockito-core + 2.3.7 + test + ch.qos.logback logback-classic diff --git a/src/test/java/net/sf/javaanpr/gui/tools/ImageFileFilterTest.java b/src/test/java/net/sf/javaanpr/gui/tools/ImageFileFilterTest.java new file mode 100644 index 0000000..0ed92eb --- /dev/null +++ b/src/test/java/net/sf/javaanpr/gui/tools/ImageFileFilterTest.java @@ -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)); + } +}