• Post Reply Bookmark Topic Watch Topic
  • New Topic

please correct me if my test case is wrong  RSS feed

 
rag mag
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package com.yieldstar.mpfui.property.test;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;

public class DemoTest extends TestCase {

Integer year = null;
String associateId = null;

@Before
public void setUp(){
year = 1980;
associateId="ASDF234XASD";
}


@Test
public void testIsYearValid() {

final DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
final Calendar c = Calendar.getInstance();
c.setTime(new Date());
Integer currentYear = c.get(Calendar.YEAR);
assertNotNull("Year should not be null", year); //
assertEquals("Year should not be lessthan 1990 or greater than current year",false, (year < 1990 || year > currentYear));

}

@Test
public void testAssociateID() {

assertNotNull(associateId);
if (associateId.length() > 11 || associateId.length() < 11) {
assertTrue("AssociateID cannot be lessthan 11 or greater than 11 digits",false);
} else if (!isAlphaNumeric(associateId)) {
assertTrue("AssociateID should be alphanumeric", false);
}
}

public boolean isAlphaNumeric(String s) {
String pattern = "^[a-zA-Z0-9]+$";
if (s.matches(pattern)) {
return true;
}
return false;
}

}
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Kindly don't edit a post to remove the question. I have restored it. If you had a problem and have sorted it please tell us how you solved it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!