1 package com.puppycrawl.tools.checkstyle.filters; 2 3 import java.util.regex.PatternSyntaxException ; 4 5 import com.puppycrawl.tools.checkstyle.api.AuditEvent; 6 import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; 7 8 import junit.framework.TestCase; 9 10 11 public class SuppressElementTest extends TestCase 12 { 13 private SuppressElement filter; 14 15 public void setUp() 16 throws PatternSyntaxException 17 { 18 filter = new SuppressElement("Test"); 19 filter.setChecks("Test"); 20 } 21 22 public void testDecideDefault() 23 { 24 final AuditEvent ev = new AuditEvent(this, "Test.java"); 25 assertTrue(ev.getFileName(), filter.accept(ev)); 26 } 27 28 public void testDecideLocalizedMessage() 29 { 30 LocalizedMessage message = 31 new LocalizedMessage(0, 0, "", "", null, null, this.getClass()); 32 final AuditEvent ev = new AuditEvent(this, "ATest.java", message); 33 assertFalse("Names match", filter.accept(ev)); 35 } 36 37 public void testDecideByLine() 38 { 39 LocalizedMessage message = 40 new LocalizedMessage(10, 10, "", "", null, null, this.getClass()); 41 final AuditEvent ev = new AuditEvent(this, "ATest.java", message); 42 filter.setLines("1-10"); 44 assertFalse("In range 1-10", filter.accept(ev)); 45 filter.setLines("1-9, 11"); 46 assertTrue("Not in 1-9, 11", filter.accept(ev)); 47 } 48 49 public void testDecideByColumn() 50 { 51 LocalizedMessage message = 52 new LocalizedMessage(10, 10, "", "", null, null, this.getClass()); 53 final AuditEvent ev = new AuditEvent(this, "ATest.java", message); 54 filter.setColumns("1-10"); 56 assertFalse("In range 1-10", filter.accept(ev)); 57 filter.setColumns("1-9, 11"); 58 assertTrue("Not in 1-9, 1)", filter.accept(ev)); 59 } 60 61 public void testEquals() throws PatternSyntaxException 62 { 63 final SuppressElement filter2 = new SuppressElement("Test"); 64 filter2.setChecks("Test"); 65 assertEquals("filter, filter2", filter, filter2); 66 final SuppressElement filter3 = new SuppressElement("Test"); 67 filter3.setChecks("Test3"); 68 assertFalse("filter, filter3", filter.equals(filter3)); 69 filter.setColumns("1-10"); 70 assertFalse("filter, filter2", filter.equals(filter2)); 71 filter2.setColumns("1-10"); 72 assertEquals("filter, filter2", filter, filter2); 73 filter.setColumns(null); 74 assertFalse("filter, filter2", filter.equals(filter2)); 75 filter2.setColumns(null); 76 filter.setLines("3,4"); 77 assertFalse("filter, filter2", filter.equals(filter2)); 78 filter2.setLines("3,4"); 79 assertEquals("filter, filter2", filter, filter2); 80 filter.setColumns("1-10"); 81 assertFalse("filter, filter2", filter.equals(filter2)); 82 filter2.setColumns("1-10"); 83 assertEquals("filter, filter2", filter, filter2); 84 } 85 } 86 | Popular Tags |