Home | History | Annotate | Download | only in check
      1 /*******************************************************************************
      2  * Copyright (c) 2009, 2015 Mountainminds GmbH & Co. KG and Contributors
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *    Marc R. Hoffmann - initial API and implementation
     10  *
     11  *******************************************************************************/
     12 package org.jacoco.report.check;
     13 
     14 import static org.junit.Assert.assertEquals;
     15 import static org.junit.Assert.assertFalse;
     16 import static org.junit.Assert.assertTrue;
     17 
     18 import java.util.ArrayList;
     19 import java.util.Arrays;
     20 import java.util.Collections;
     21 
     22 import org.jacoco.core.analysis.ICoverageNode.ElementType;
     23 import org.junit.Before;
     24 import org.junit.Test;
     25 
     26 /**
     27  * Unit tests for {@link Rule}.
     28  */
     29 public class RuleTest {
     30 
     31 	private Rule rule;
     32 
     33 	@Before
     34 	public void setup() {
     35 		rule = new Rule();
     36 	}
     37 
     38 	@Test
     39 	public void testDefaults() {
     40 		assertEquals(ElementType.BUNDLE, rule.getElement());
     41 		assertEquals(Collections.emptyList(), rule.getLimits());
     42 		assertEquals("*", rule.getIncludes());
     43 		assertEquals("", rule.getExcludes());
     44 	}
     45 
     46 	@Test
     47 	public void testSetElement() {
     48 		rule.setElement(ElementType.PACKAGE);
     49 		assertEquals(ElementType.PACKAGE, rule.getElement());
     50 	}
     51 
     52 	@Test
     53 	public void testSetLimits() {
     54 		Limit l1 = new Limit();
     55 		Limit l2 = new Limit();
     56 		Limit l3 = new Limit();
     57 		rule.setLimits(Arrays.asList(l1, l2, l3));
     58 		assertEquals(Arrays.asList(l1, l2, l3), rule.getLimits());
     59 	}
     60 
     61 	@Test
     62 	public void testCreateLimit() {
     63 		Limit l1 = new Limit();
     64 		Limit l2 = new Limit();
     65 		rule.setLimits(new ArrayList<Limit>(Arrays.asList(l1, l2)));
     66 		Limit l3 = rule.createLimit();
     67 		assertEquals(Arrays.asList(l1, l2, l3), rule.getLimits());
     68 	}
     69 
     70 	@Test
     71 	public void testSetIncludes() {
     72 		rule.setIncludes("Foo*");
     73 		assertEquals("Foo*", rule.getIncludes());
     74 		assertTrue(rule.matches("FooBar"));
     75 		assertFalse(rule.matches("Other"));
     76 	}
     77 
     78 	@Test
     79 	public void testSetExcludes() {
     80 		rule.setExcludes("Foo*");
     81 		assertEquals("Foo*", rule.getExcludes());
     82 		assertTrue(rule.matches("Other"));
     83 		assertFalse(rule.matches("FooBar"));
     84 	}
     85 
     86 }
     87