some code samples, various examples of simple modeling ideas and some minor algorithms.

AccountTest.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class AccountTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class AccountTest
  12. {
  13. Account test = new Account();
  14. @Test
  15. public void transferTest(){
  16. //Given:
  17. test.deposit(1000);
  18. //Then:
  19. boolean expected = true;
  20. boolean actual = test.transfer(test, 999);
  21. //Assert:
  22. assertEquals(expected, actual);
  23. }
  24. @Test
  25. public void balanceTest(){
  26. //Given:
  27. test.deposit(1000);
  28. //Then:
  29. int expected = 1000;
  30. int actual = test.balance();
  31. //Assert:
  32. assertEquals(expected, actual);
  33. }
  34. @Test
  35. public void depositTest(){
  36. //Given:
  37. Account test = new Account(100);
  38. test.deposit(100);
  39. //Then:
  40. int expected = 200;
  41. int actual = test.balance();
  42. //Assert
  43. assertEquals(expected,actual);
  44. }
  45. @Test
  46. public void openTest() {
  47. //Given
  48. Account test = new Account(100);
  49. //Then:
  50. Account answer = test.open(90);
  51. //Assert
  52. assertTrue(answer.balance() == 90);
  53. }
  54. @Test
  55. public void withdrawTest(){
  56. test.deposit(1000);
  57. try{test.withdraw(800);}
  58. catch(AccountException ae){};
  59. int expected = 200;
  60. int actual = test.balance();
  61. assertEquals(expected,actual);
  62. }
  63. }