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