001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2007, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba.npe;
021:
022: import junit.framework.Assert;
023: import junit.framework.TestCase;
024: import edu.umd.cs.findbugs.ba.DataflowAnalysisException;
025:
026: /**
027: * Test cases for ReturnPathType class.
028: *
029: * @author David Hovemeyer
030: */
031: public class ReturnPathTypeTest extends TestCase {
032: ReturnPathType top;
033: ReturnPathType normal;
034: ReturnPathType abnormal;
035:
036: /* (non-Javadoc)
037: * @see junit.framework.TestCase#setUp()
038: */
039: @Override
040: protected void setUp() throws Exception {
041: top = new ReturnPathType();
042: normal = new ReturnPathType();
043: normal.setCanReturnNormally(true);
044: abnormal = new ReturnPathType();
045: abnormal.setCanReturnNormally(false);
046: }
047:
048: public void testTop() throws Exception {
049: Assert.assertFalse(top.isValid());
050: Assert.assertTrue(top.isTop());
051: try {
052: top.canReturnNormally();// should throw exception
053: Assert.assertTrue(false);
054: } catch (DataflowAnalysisException e) {
055: // Good
056: }
057: }
058:
059: public void testCanReturnNormally() throws Exception {
060: Assert.assertTrue(normal.isValid());
061: Assert.assertTrue(normal.canReturnNormally());
062: }
063:
064: public void testCannotReturnNormally() throws Exception {
065: Assert.assertTrue(abnormal.isValid());
066: Assert.assertFalse(abnormal.canReturnNormally());
067: }
068:
069: public void testMergeWithTop() throws Exception {
070: normal.mergeWith(top);
071: Assert.assertTrue(normal.canReturnNormally());
072: abnormal.mergeWith(top);
073: Assert.assertFalse(abnormal.canReturnNormally());
074: }
075:
076: public void testTopMergeWithNormalReturn() throws Exception {
077: top.mergeWith(normal);
078: Assert.assertTrue(top.canReturnNormally());
079: }
080:
081: public void testTopMergeWithAbnormalReturn() throws Exception {
082: top.mergeWith(abnormal);
083: Assert.assertFalse(top.canReturnNormally());
084: }
085:
086: public void testNormalMergeWIthAbnormal() throws Exception {
087: normal.mergeWith(abnormal);
088: Assert.assertTrue(normal.canReturnNormally());
089: }
090:
091: public void testAbnormalMergeWithNormal() throws Exception {
092: abnormal.mergeWith(normal);
093: Assert.assertTrue(abnormal.canReturnNormally());
094: }
095:
096: public void testNormalMergeWithNormal() throws Exception {
097: ReturnPathType otherNormal = new ReturnPathType();
098: otherNormal.setCanReturnNormally(true);
099:
100: normal.mergeWith(otherNormal);
101: Assert.assertTrue(normal.canReturnNormally());
102: }
103:
104: public void testAbnormalMergeWithAbnormal() throws Exception {
105: ReturnPathType otherAbnormal = new ReturnPathType();
106: otherAbnormal.setCanReturnNormally(false);
107:
108: abnormal.mergeWith(otherAbnormal);
109: Assert.assertFalse(abnormal.canReturnNormally());
110: }
111: }
|