From a0fa8d9fb7aca060c4f525d3e92cba6d53242a95 Mon Sep 17 00:00:00 2001 From: Maurice Laveaux Date: Thu, 15 May 2014 20:52:47 +0200 Subject: Added some basic test cases for BrandChecker. --- test/analysis/BrandCheckerTest.java | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 test/analysis/BrandCheckerTest.java (limited to 'test') diff --git a/test/analysis/BrandCheckerTest.java b/test/analysis/BrandCheckerTest.java new file mode 100644 index 0000000..06818ac --- /dev/null +++ b/test/analysis/BrandCheckerTest.java @@ -0,0 +1,86 @@ +package analysis; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author maurice + */ +public class BrandCheckerTest { + + public BrandCheckerTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Initialize the instance. + */ + private BrandChecker brandChecker; + + private void checkEquals(final List expected, final List results) { + for (String brand : expected) { + if (!results.contains(brand)) { + fail("expected brand " + brand + " was not in results " + results.toString()); + } + } + + for (String result : results) { + if (!expected.contains(result)) { + fail("unexpected brand " + result + " was not in the expected " + expected.toString()); + } + } + } + + public void doTest(final String input, final String[] expectedArray) { + brandChecker = new BrandChecker("brandrules.txt"); + + ArrayList expected = new ArrayList(); + + expected.addAll(Arrays.asList(expectedArray)); + + List results = brandChecker.getBrands(input); + + checkEquals(expected, results); + } + + @Test + public void testGetBrands() { + doTest("10 essential apps you need to install on your new Samsung Galaxy S5", new String[]{"galaxy s5"}); + } + + @Test + public void testMultiple() { + doTest("QBD - Black in Ear Earphones. 3.5mm Jack Plug for Apple iPod, " + + "IPhone 4, 4S, 5, 5S, 5C, Ipad Air, Ipad Mini", + new String[]{"iphone 4", "iphone 4s", "iphone 5S", "iphone 5c"}); + } + + @Test + public void testBullshit() { + doTest("This applepie is delicious", new String[]{}); + } + +} -- cgit v1.2.1