package creditcard_eventsourcing.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.math.BigDecimal;
import java.util.UUID;

import org.junit.Before;
import org.junit.Test;
import org.requirementsascode.exception.UnhandledException;

public class CreditCardTest {

    @Before
    public void setUp() throws Exception {
    }
    
    @Test
    public void assigningLimitOnceWorksCorrectly() {
	CreditCard card = new CreditCard(UUID.randomUUID());
	card.assignLimit(BigDecimal.TEN);
	assertEquals(BigDecimal.TEN, card.availableLimit());
    }

    @Test
    public void assigningLimitTwiceThrowsException() {
	CreditCard card = new CreditCard(UUID.randomUUID());
	card.assignLimit(BigDecimal.TEN);

	boolean illegalStateExceptionThrown = false;
	try {
	    card.assignLimit(BigDecimal.TEN);
	} catch (UnhandledException e) {
	    illegalStateExceptionThrown = e.getCause() instanceof IllegalStateException;
	}
	assertTrue(illegalStateExceptionThrown);
    }
}

@@ -381,13 +381,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -799,16 +799,16 @@
 %0A%09try %7B%0A
-
 %09    car
@@ -1005,10 +1005,717 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void withdrawingOnceWorksCorrectly() %7B%0A%09CreditCard card = new CreditCard(UUID.randomUUID());%0A%09card.assignLimit(BigDecimal.TEN);%0A%09card.withdraw(BigDecimal.ONE);%0A%09assertEquals(new BigDecimal(9), card.availableLimit());%0A    %7D%0A%0A    @Test%0A    public void withdrawingTooOftenThrowsException() %7B%0A%09CreditCard card = new CreditCard(UUID.randomUUID());%0A%09card.assignLimit(new BigDecimal(100));%0A%0A%09boolean illegalStateExceptionThrown = false;%0A%09try %7B%0A%09    for (int i = 1; i %3C= 90; i++) %7B%0A%09%09card.withdraw(BigDecimal.ONE);%0A%09    %7D%0A%09%7D catch (UnhandledException e) %7B%0A%09    illegalStateExceptionThrown = e.getCause() instanceof IllegalStateException;%0A%09%7D%0A%09assertTrue(illegalStateExceptionThrown);%0A    %7D%0A
 %7D%0A

Add test for withdraw