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", "iphone 5"}); } @Test public void testBullshit() { doTest("This applepie is delicious", new String[]{}); } @Test public void multipleBrands() { doTest("This tweet contains both iphone 4s,galaxy s5 and iphone", new String[]{"iphone 4s", "galaxy s5"}); } }