Advertisement
kenzierocks

test for SO answer 23971816/436524

May 31st, 2014
2,937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import static org.junit.Assert.*;
  2.  
  3. import java.util.Calendar;
  4.  
  5. import org.junit.Before;
  6. import org.junit.Test;
  7.  
  8. public class Tester {
  9.  
  10.     private static Calendar cacheCalendar;
  11.  
  12.     public static int getFirstMonday(int year, int month) {
  13.         cacheCalendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  14.         cacheCalendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1);
  15.         cacheCalendar.set(Calendar.MONTH, month);
  16.         cacheCalendar.set(Calendar.YEAR, year);
  17.         return cacheCalendar.get(Calendar.DATE);
  18.     }
  19.  
  20.     @Before
  21.     public void setUp() throws Exception {
  22.         cacheCalendar = Calendar.getInstance();
  23.         System.err.println("Using calendar " + cacheCalendar);
  24.     }
  25.  
  26.     @Test
  27.     public void test() {
  28.         assertEquals(6, getFirstMonday(2014, Calendar.JANUARY));
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement