asserttests.java

来自「spring,z几 塞积极 决撒 积极上经济歼击机就 将计就计经济年毫毫毫毫毫毫」· Java 代码 · 共 54 行

JAVA
54
字号
/*
 * Copyright 2004-2005 the original author or authors.
 */

package org.springframework.util;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

/**
 * Tests for the Assert class.
 *
 * @author Keith Donald
 * @author Erwin Vervaet
 */
public class AssertTests extends TestCase {

	public void testInstanceOf() {
		Set set = new HashSet();
		Assert.isInstanceOf(HashSet.class, set);
		try {
			Assert.isInstanceOf(HashMap.class, set);
			fail("Should have failed - a hash map is not a set");
		}
		catch (IllegalArgumentException ex) {
			// ok
		}
	}

	public void testIsNull() {
		Assert.isNull(null, "Bla");
		try {
			Assert.isNull(new Object(), "Bla");
			fail("Should have failed - object is not null");
		}
		catch (IllegalArgumentException e) {
			assertEquals("Bla", e.getMessage());
		}

		Assert.isNull(null);
		try {
			Assert.isNull(new Object());
			fail("Should have failed - object is not null");
		}
		catch (IllegalArgumentException ex) {
			// ok
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?