samples/cloneproblem/test/org/apidesign/cloneproblem/IntervalTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 21:30:10 +0100
changeset 409 40cabcdcd2be
permissions -rw-r--r--
Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
     1 /*
     2  * To change this template, choose Tools | Templates
     3  * and open the template in the editor.
     4  */
     5 
     6 package org.apidesign.cloneproblem;
     7 
     8 import java.util.Date;
     9 import junit.framework.TestCase;
    10 
    11 /** The test as would be written by the (not paranoiac) API author.
    12  *
    13  * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    14  */
    15 public class IntervalTest extends TestCase {
    16     
    17     public IntervalTest(String testName) {
    18         super(testName);
    19     }
    20 
    21     // BEGIN: interval.test
    22     public void testOneSecondInterval() {
    23         Date now = new Date();
    24         Date later = new Date(now.getTime() + 1000);
    25         
    26         Interval interval = new Interval(now, later);
    27         assertEquals("1s", 1000, interval.getLength());
    28     }
    29     // END: interval.test
    30 
    31     public void testLaterCantBeSooner() {
    32         Date now = new Date();
    33         Date later = new Date(now.getTime() - 1000);
    34 
    35         try {
    36             Interval interval = new Interval(now, later);
    37             fail("Shall throw IllegalArgumentException");
    38         } catch (IllegalArgumentException ex) {
    39             // OK
    40         }
    41     }
    42 
    43     public void testDoesNotThrowNPEOnSecondArg() {
    44         Date now = new Date();
    45         try {
    46             Interval interval = new Interval(now, null);
    47             fail("Shall throw IllegalArgumentException");
    48         } catch (IllegalArgumentException ex) {
    49             // OK
    50         }
    51     }
    52     
    53     public void testDoesNotThrowNPEOnFirstArg() {
    54         Date now = new Date();
    55         try {
    56             Interval interval = new Interval(null, now);
    57             fail("Shall throw IllegalArgumentException");
    58         } catch (IllegalArgumentException ex) {
    59             // OK
    60         }
    61     }
    62     
    63 }