diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Box.java b/lesson00/src/com/hackbulgaria/qa/week2/Box.java new file mode 100644 index 0000000..26a933d --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Box.java @@ -0,0 +1,17 @@ +package com.hackbulgaria.qa.week2; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +public class Box { + private T data; + + public Box(T data) { this.data = data; } + public T getData() { return data; } + + public static void main(String[] args) { + Box a = new Box<>(1); + } +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Entity.java b/lesson00/src/com/hackbulgaria/qa/week2/Entity.java new file mode 100644 index 0000000..e88c358 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Entity.java @@ -0,0 +1,18 @@ +package com.hackbulgaria.qa.week2; + +public abstract class Entity { + private String id; + + protected String getId() { return id; } + + public abstract String getIdentifier(); + + public Entity(String id) { + this.id = id; + } + + @Override + public String toString() { + return getIdentifier(); + } +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Ivo.java b/lesson00/src/com/hackbulgaria/qa/week2/Ivo.java new file mode 100644 index 0000000..f5fac87 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Ivo.java @@ -0,0 +1,9 @@ +package com.hackbulgaria.qa.week2; + +public abstract class Ivo extends Panda { + @Override + public void eat() { + // TODO Auto-generated method stub + + } +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Magche.java b/lesson00/src/com/hackbulgaria/qa/week2/Magche.java new file mode 100644 index 0000000..0e7f226 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Magche.java @@ -0,0 +1,5 @@ +package com.hackbulgaria.qa.week2; + +public class Magche extends Ivo { + +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Main.java b/lesson00/src/com/hackbulgaria/qa/week2/Main.java new file mode 100644 index 0000000..7eb3402 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Main.java @@ -0,0 +1,31 @@ +package com.hackbulgaria.qa.week2; + +import java.util.ArrayList; +import java.util.Collections; + +public class Main { + public static void printArray(Object[] arr) { + StringBuilder b = new StringBuilder(); + b.append("["); + for (int i = 0; i < arr.length; i++) { + b.append(arr[i].toString()); + + if(i != arr.length - 1) { + b.append(", "); + } + } + + b.append("]"); + System.out.println(b.toString()); + } + + public static void main(String[] args) { + Student ivo = new Student("8"); + + ArrayList everything = new ArrayList<>(); + everything.add(new Student("1")); + everything.add(new Teacher("2")); + everything.add(ivo); + System.out.println(everything); + } +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Panda.java b/lesson00/src/com/hackbulgaria/qa/week2/Panda.java new file mode 100644 index 0000000..0b1bc21 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Panda.java @@ -0,0 +1,9 @@ +package com.hackbulgaria.qa.week2; + + +public abstract class Panda { + + public Panda() {} + public abstract void eat(); + +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Person.java b/lesson00/src/com/hackbulgaria/qa/week2/Person.java new file mode 100644 index 0000000..1b39ab3 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Person.java @@ -0,0 +1,61 @@ +package com.hackbulgaria.qa.week2; + +public class Person implements Comparable { + private String name; + private int age; + + public Person(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + public void setAge(int age) { + this.age = age; + } + + public String toString() { + StringBuilder b = new StringBuilder(); + + b.append("("); + b.append(name); + b.append(", "); + b.append(age); + b.append(")"); + + return b.toString(); + } + + @Override + public int compareTo(Person o) { + if(this.age == o.age) { + return 0; + } + + if(this.age < o.age) { + return -1; + } + + return 1; + } +} + + + + + + + + + + diff --git a/lesson00/src/com/hackbulgaria/qa/week2/PersonComparator.java b/lesson00/src/com/hackbulgaria/qa/week2/PersonComparator.java new file mode 100644 index 0000000..1c9747a --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/PersonComparator.java @@ -0,0 +1,16 @@ +package com.hackbulgaria.qa.week2; + +import java.util.Comparator; + +public class PersonComparator implements Comparator{ + + @Override + public int compare(Person o1, Person o2) { + if(o1.getAge() == o2.getAge()) { + return o1.getName().compareTo(o2.getName()); + } + + return o1.compareTo(o2); + } + +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/PythonRunner.java b/lesson00/src/com/hackbulgaria/qa/week2/PythonRunner.java new file mode 100644 index 0000000..bfa4cd2 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/PythonRunner.java @@ -0,0 +1,18 @@ +package com.hackbulgaria.qa.week2; + +public class PythonRunner extends Runner { + public PythonRunner(String code, String test) { + super(code, test); + } + + public void lint() {} + public void compile() {} + + public void execute() { +// Пусни python програмата в OS–а +// Заедно с тестовете и кода +// Гледай за някакви неща / while true / fork-loops и т.н +// Вземи резултата + result = "OK"; + } +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/RealPythonRunner.java b/lesson00/src/com/hackbulgaria/qa/week2/RealPythonRunner.java new file mode 100644 index 0000000..d56dab4 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/RealPythonRunner.java @@ -0,0 +1,12 @@ +package com.hackbulgaria.qa.week2; + +public class RealPythonRunner extends PythonRunner { + public RealPythonRunner(String code, String test) { + super(code, test); + } + @Override + public void execute() { + super.execute(); + result = "NOT OK"; + } +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Runner.java b/lesson00/src/com/hackbulgaria/qa/week2/Runner.java new file mode 100644 index 0000000..eb25fc2 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Runner.java @@ -0,0 +1,24 @@ +package com.hackbulgaria.qa.week2; + +public abstract class Runner { + protected String result; + protected String code; + protected String test; + + public Runner(String code, String test) { + this.code = code; + this.test = test; + } + + public String run() { + lint(); + compile(); + execute(); + + return result; + } + + public abstract void lint(); + public abstract void compile(); + public abstract void execute(); +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/SomeClass.java b/lesson00/src/com/hackbulgaria/qa/week2/SomeClass.java new file mode 100644 index 0000000..417d5f7 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/SomeClass.java @@ -0,0 +1,32 @@ +package com.hackbulgaria.qa.week2; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +public class SomeClass { + + public static void main(String[] args) { + Path path = Paths.get("/home/radorado/code/Loki/R.md"); + + try { + List lines = Files.readAllLines(path); + System.out.println(lines); + } catch (NoSuchFileException fnfe) { + System.out.println("File not found: " + fnfe.getMessage()); + System.out + .println("Please ensure that you have created the file, before running again."); + fnfe.printStackTrace(); + + } catch (IOException e) { + System.out.println(e.toString()); + System.out.println("Here"); + } catch(final Exception e) { + throw e; + } + } +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Student.java b/lesson00/src/com/hackbulgaria/qa/week2/Student.java new file mode 100644 index 0000000..e99672e --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Student.java @@ -0,0 +1,12 @@ +package com.hackbulgaria.qa.week2; + +public class Student extends Entity { + public Student(String identifier) { + super(identifier); + } + + @Override + public String getIdentifier() { + return "Student::" + getId(); + } +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/Teacher.java b/lesson00/src/com/hackbulgaria/qa/week2/Teacher.java new file mode 100644 index 0000000..babc281 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/Teacher.java @@ -0,0 +1,14 @@ +package com.hackbulgaria.qa.week2; + +public class Teacher extends Entity { + + public Teacher(String identifier) { + super(identifier); + } + + @Override + public String getIdentifier() { + return "Teacher::" + getId(); + } + +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/summary/A.java b/lesson00/src/com/hackbulgaria/qa/week2/summary/A.java new file mode 100644 index 0000000..a71d5f6 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/summary/A.java @@ -0,0 +1,5 @@ +package com.hackbulgaria.qa.week2.summary; + +public class A extends B implements C, D { + +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/summary/B.java b/lesson00/src/com/hackbulgaria/qa/week2/summary/B.java new file mode 100644 index 0000000..d4f1fcf --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/summary/B.java @@ -0,0 +1,5 @@ +package com.hackbulgaria.qa.week2.summary; + +public class B { + +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/summary/C.java b/lesson00/src/com/hackbulgaria/qa/week2/summary/C.java new file mode 100644 index 0000000..da3cbf1 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/summary/C.java @@ -0,0 +1,5 @@ +package com.hackbulgaria.qa.week2.summary; + +public interface C { + +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/summary/D.java b/lesson00/src/com/hackbulgaria/qa/week2/summary/D.java new file mode 100644 index 0000000..93e2d20 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/summary/D.java @@ -0,0 +1,5 @@ +package com.hackbulgaria.qa.week2.summary; + +public interface D { + +} diff --git a/lesson00/src/com/hackbulgaria/qa/week2/summary/E.java b/lesson00/src/com/hackbulgaria/qa/week2/summary/E.java new file mode 100644 index 0000000..4f7f4c8 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/qa/week2/summary/E.java @@ -0,0 +1,5 @@ +package com.hackbulgaria.qa.week2.summary; + +public class E extends A { + +} diff --git a/lesson00/src/com/hackbulgaria/week2/tdd/BankAccount.java b/lesson00/src/com/hackbulgaria/week2/tdd/BankAccount.java new file mode 100644 index 0000000..22a0870 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/week2/tdd/BankAccount.java @@ -0,0 +1,12 @@ +package com.hackbulgaria.week2.tdd; + +import java.util.Currency; + +import javax.transaction.InvalidTransactionException; + +public interface BankAccount { + public Currency getCurrency(); + public Integer getBalance(); + public void deposit(Integer amount); + public void withdraw(Integer amount) throws NotEnoughMoney; +} diff --git a/lesson00/src/com/hackbulgaria/week2/tdd/BankAccountImpl.java b/lesson00/src/com/hackbulgaria/week2/tdd/BankAccountImpl.java new file mode 100644 index 0000000..98554f1 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/week2/tdd/BankAccountImpl.java @@ -0,0 +1,41 @@ +package com.hackbulgaria.week2.tdd; + +import java.util.Currency; + +public class BankAccountImpl implements BankAccount { + + private int currentBalance; + + public BankAccountImpl() { + this(0); + } + + public BankAccountImpl(int initialAmount) { + this.currentBalance = initialAmount; + } + + @Override + public Currency getCurrency() { + return Currency.getInstance("BGN"); + } + + @Override + public Integer getBalance() { + return currentBalance; + } + + @Override + public void deposit(Integer amount) { + currentBalance += amount; + } + + @Override + public void withdraw(Integer amount) throws NotEnoughMoney { + if(currentBalance - amount < 0) { + throw new NotEnoughMoney(); + } + + currentBalance -= amount; + } + +} diff --git a/lesson00/src/com/hackbulgaria/week2/tdd/BulgarianBankAccountTests.java b/lesson00/src/com/hackbulgaria/week2/tdd/BulgarianBankAccountTests.java new file mode 100644 index 0000000..5a7743d --- /dev/null +++ b/lesson00/src/com/hackbulgaria/week2/tdd/BulgarianBankAccountTests.java @@ -0,0 +1,106 @@ +package com.hackbulgaria.week2.tdd; + +import static org.junit.Assert.*; + +import java.util.Currency; + +import org.junit.Before; +import org.junit.Test; + +public class BulgarianBankAccountTests { + + private BankAccount zeroAccount; + private BankAccount hundredAccount; + + @Before + public void setUp() { + BankAccount zeroAccount = new BankAccountImpl(); + this.zeroAccount = zeroAccount; + + BankAccount hundredAccount = new BankAccountImpl(100); + this.hundredAccount = hundredAccount; + } + + @Test + public void testWhenCreatingNewAccountBalanceShouldBeZero() { + assertEquals(new Integer(0), zeroAccount.getBalance()); + } + + @Test + public void testWhenCreatingNewAccountWithInitialBalanceThatBalanceCheckHolds() { + assertEquals(new Integer(100), hundredAccount.getBalance()); + } + + @Test + public void testThatInBulgarianBankAccountCurrencyIsBgn() { + // factory pattern + Currency bgn = Currency.getInstance("BGN"); + + assertEquals(bgn, zeroAccount.getCurrency()); + } + + @Test + public void testThatIfWeDepositInNewAccountBalanceShouldBeTheDepositedAmount() { + zeroAccount.deposit(100); + + assertEquals(new Integer(100), zeroAccount.getBalance()); + } + + @Test + public void testThatIfWeDepositInBankAccountWithInitialBalanceTheBalanceShouldBeSummed() { + + hundredAccount.deposit(100); + + assertEquals(new Integer(200), hundredAccount.getBalance()); + } + + @Test + public void testWithdrawingFromBankAccountWithEnoughInitialBalance() { + try { + hundredAccount.withdraw(20); + } catch (NotEnoughMoney e) { + fail("Should not be here - exception thrown when it's not needed."); + } + + assertEquals(new Integer(80), hundredAccount.getBalance()); + } + + @Test + public void testWhenWeEmptyTheBankAccountBalanceShouldBeZero() { + try { + hundredAccount.withdraw(100); + } catch (NotEnoughMoney e) { + fail("Should not be here - exception thrown when it's not needed."); + } + + assertEquals(new Integer(0), hundredAccount.getBalance()); + } + + @Test + public void testWithdrawingMoreMoneyThanActualBalanceShouldThrowExpcetion() { + boolean inCatch = false; + try { + hundredAccount.withdraw(200); + fail("Should not be here - exception should have been raised."); + } catch (NotEnoughMoney e) { + inCatch = true; + } finally { + assertEquals(true, inCatch); + assertEquals(new Integer(100), hundredAccount.getBalance()); + } + } + + @Test + public void testWithdrawingNegativeAmountOfMoneyShouldThrowInvalidOperation() { + boolean inCatch = false; + try { + hundredAccount.withdraw(200); + fail("Should not be here - exception should have been raised."); + } catch (NotEnoughMoney e) { + inCatch = true; + } finally { + assertEquals(true, inCatch); + assertEquals(new Integer(100), hundredAccount.getBalance()); + } + } +} diff --git a/lesson00/src/com/hackbulgaria/week2/tdd/Main.java b/lesson00/src/com/hackbulgaria/week2/tdd/Main.java new file mode 100644 index 0000000..bfbd138 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/week2/tdd/Main.java @@ -0,0 +1,8 @@ +package com.hackbulgaria.week2.tdd; + +import java.util.Currency; + +public class Main { +public static void main(String[] args) { +} +} diff --git a/lesson00/src/com/hackbulgaria/week2/tdd/NotEnoughMoney.java b/lesson00/src/com/hackbulgaria/week2/tdd/NotEnoughMoney.java new file mode 100644 index 0000000..5a76052 --- /dev/null +++ b/lesson00/src/com/hackbulgaria/week2/tdd/NotEnoughMoney.java @@ -0,0 +1,5 @@ +package com.hackbulgaria.week2.tdd; + +public class NotEnoughMoney extends Exception { + +}