package com.zj.c01;
public class MathTool {
public static int gcd(int num1, int num2) {
int r = 0;
while (num2 != 0) {
r = num1 % num2;
num1 = num2;
num2 = r;
}
return num1;
}
}
package com.zj.c01;
import junit.framework.TestCase;
public class MathToolTest extends TestCase {
public MathToolTest(String name) {
super(name);
}
public void testGcd() {
assertEquals(5, MathTool.gcd(10, 5));
}
}
@Test
public void testBizException()
{
try{
Password.validate( "123" );
fail( "No exception thrown." );
}catch ( Exception ex ) {
assertTrue( ex instanceof BizException );
assertTrue( ex.getMessage().contains( "error" ) );
}
}
@Test( expected = BizException.class )
public void testBizException()
{
Password.validate( null );
}
new BizException(“Password must contains at least 6 letters.”) new BizException(“Password length less than 15 letters”)
@Rule
public ExpectedException expectedEx = ExpectedException.none();
@Test
public void testBizException() throws InvalidPasswordException
{
expectedEx.expect( BizException.class );
expectedEx.expectMessage( "required" );
Password.validate( "" );
}
java.lang.AssertionError: No exception thrown. at org.junit.Assert.fail(Assert.java:91) at cc.unmi.PasswordTest.passwordLengthLessThan6LettersThrowsException(PasswordTest.java:20)
java.lang.AssertionError: at org.junit.Assert.fail(Assert.java:91) at org.junit.Assert.assertTrue(Assert.java:43) at org.junit.Assert.assertTrue(Assert.java:54) at cc.unmi.PasswordTest.passwordLengthLessThan6LettersThrowsException(PasswordTest.java:22)
java.lang.AssertionError: Expected exception: cc.test.BizException at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:32) at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:110)
java.lang.AssertionError: Expected: (exception with message a string containing “YES. required” and an instance of java.lang.NullPointerException) got: at org.junit.Assert.assertThat(Assert.java:778) at org.junit.Assert.assertThat(Assert.java:736) at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:114)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有