<file_sep>/**
 * Created by Hunter on 2015-03-08.
 */
public class CalculatorDouble implements CalculatorDoubleImp {
    @Override
    public double add(double a, double b) {
        return a+b;
    }
    @Override
    public double sub(double a, double b) {
        return a-b;
    }
    @Override
    public double multi(double a, double b) {
        return a*b;
    }
    @Override
    public double div(double a, double b) {
        return a/b;
    }
    @Override
    public boolean greater(double a, double b) {
        if(a>b) return true;
        else return false;
    }
}<file_sep>package com.example.mock.test;

import com.example.mock.app.Messenger;
import com.example.mock.messenger.DummyMsgService;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;


/**
 * Created by Hunter on 2015-04-15.
 */
public class DummyMsgServiceTest {
    private Messenger messenger;

    @Before
    public void Init() {
        messenger = new Messenger(new DummyMsgService());
    }
//PASSING TESTS
    @Test
    public void TestConnectionWithServerForCorrectAdress() {
        assertThat(messenger.TestConnection("www.wp.pl"), is(0));
    }

    @Test
    public void SendCommuniqueForCorrectMessageCorrectServer() {
        assertThat(messenger.SendMsg("Message for", "www.interia.pl"), is(anyOf(equalTo(1), equalTo(0))));
    }
//FAILURE TEST
    @Test
    public void TestConnectionWithServerForWrongAdress() {
        assertThat(messenger.TestConnection("www.wp.gov"), is(1));
    }

    @Test
    public void SendCommuniqueForWrongMessageCorrectServer() {
        assertThat(messenger.SendMsg("Ab", "www.interia.pl"), is(anyOf(equalTo(1), equalTo(0))));
    }

    @Test
    public void SendCommuniqueForCorrectMessageWrongServer() {
        assertThat(messenger.SendMsg("Message for", "www.interia.gov"), is(1));
    }

    @Test
    public void SendCommuniqueForWrongMessageWrongServer() {
        assertThat(messenger.SendMsg("Av", "www.interia.gov"), is(1));
    }
}
<file_sep>/**
 * Created by Hunter on 2015-03-18.
 */
package com.game.code;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by Hunter on 2015-03-10.
 */
public class Psikus implements IPsikus {

    @Override
    public Integer cyfrokrad(Integer liczba) {
        //Split of Integer to string
        String number = String.valueOf(liczba);
        //List<Integer> digits = new ArrayList<Integer>(); easier way
        String[] digits = number.split("(?<=.)");
        //return null if only 1 element
        if (digits.length <= 1) {
            return null;
        }

        Random random = new Random();

        int randomize = random.nextInt(digits.length);
        //loop to delete an element(Array list would be easier ArrayList got .remove method)

        //adding array to new integer
        int i;
        int num = 0;
        for (i = 0; i < digits.length; i++) {
            if(i !=randomize)
            num = 10 * num + Integer.valueOf(digits[i]);
        }
        return num;
    }

    @Override
    public Integer hultajchochla(Integer liczba) throws NieudanyPsikusException {
        //Split of Integer to string
        String number = String.valueOf(liczba);
        //List<Integer> digits = new ArrayList<Integer>(); easier way
        String[] digits = number.split("(?<=.)");

        Random random = new Random();
        int randomize = random.nextInt(digits.length);
        int randomize2 = random.nextInt(digits.length);

        String pom, pom2;
        try {
            if (digits.length <= 1) {
                throw new NieudanyPsikusException("Wrong Length (it should be above 1)");
            }
            //switch
            pom = digits[randomize];
            pom2 = digits[randomize2];
            digits[randomize] = pom2;
            digits[randomize2] = pom;

        } catch (NieudanyPsikusException e) {
            System.out.println(e.getMessage());
        }
        //adding array to new integer
        int i;
        int num = 0;
        for (i = 0; i < digits.length; i++) {
            num = 10 * num + Integer.parseInt(digits[i]);
        }
        return num;
    }

    @Override
    public Integer nieksztaltek(Integer liczba) {
        //Split of Integer to string
        String number = String.valueOf(liczba);
        //List<Integer> digits = new ArrayList<Integer>(); easier way
        String[] digits = number.split("(?<=.)");

        int i;
        List<Integer> three = new ArrayList<Integer>();
        List<Integer> six = new ArrayList<Integer>();
        List<Integer> seven = new ArrayList<Integer>();
        for (i = 0; i < digits.length; i++) {
            if (digits[i].equals("3")) {
                three.add(i);
            }
            if (digits[i].equals("6")) {
                six.add(i);
            }
            if (digits[i].equals("7")) {
                seven.add(i);
            }
        }
        //if empty return argument
        if (three.size() == 0 && six.size() == 0 && seven.size() == 0) {
            return liczba;
        }

        int randomize;
        Random random = new Random();
        if (three.size() != 0) {
            randomize = random.nextInt(three.size());
            int val = three.get(randomize);
            System.out.print(val);
            digits[val] = "8";
        }
        if (six.size() != 0) {
            randomize = random.nextInt(six.size());
            int val = three.get(randomize);
            System.out.print(val);
            digits[val] = "9";
        }
        if (seven.size() != 0) {
            randomize = random.nextInt(seven.size());
            int val = three.get(randomize);
            System.out.print(val);
            digits[val] = "1";
        }
        //adding array to new integer
        int num = 0;
        for (i = 0; i < digits.length; i++) {
            num = 10 * num + Integer.parseInt(digits[i]);
        }

        return num;
    }
}<file_sep>/**
 * Created by Hunter on 2015-03-08.
 */

import org.junit.*;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
 * Created by student on 25.02.15.
 */

public class CalculatorTest {
    private Calculator calculatorImp;
    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Before
    public void setUp() {
        calculatorImp = new Calculator();
    }

    @Test
    public void AddTest() {
        Assert.assertEquals(20, calculatorImp.add(14, 6));
    }

    @Test
    public void SubTest() {
        Assert.assertEquals(19, calculatorImp.sub(20, 1));
    }

    @Test
    public void multiTest() {
        Assert.assertEquals(40, calculatorImp.multi(8, 5));
    }

    @Test
    public void divTest() {
        Assert.assertEquals(12, calculatorImp.div(36, 3));
    }

    @Test
    public void greaterTest() {
        Assert.assertTrue(calculatorImp.greater(20, 12));
    }

    @Test
    public void DivideArithmeticException_Excepted() {
        thrown.expect(ArithmeticException.class);
        calculatorImp.div(14, 0);
    }

    //to samo co wyzej
    @Test(expected = ArithmeticException.class)
    public void DivExp() throws ArithmeticException {
        calculatorImp.div(14, 0);
    }
}
<file_sep>/**
 * Created by Hunter on 2015-04-15.
 */
public class Messenger {
    private IMessageService messageService;

    public Messenger(IMessageService msgService) {
        this.messageService = msgService;
    }

    public Messenger() {

    }
    public int TestConnection(String address) {
        //FAILURE
        if (messageService.checkConnection(address) != ConnectionStatus.SUCCESS)
            return 1;
        //SUCESS
        return 0;
    }

    public int SendMsg(String msg, String address) {
        try {
            SendingStatus ss = messageService.send(address, msg);
            //SEND ERROR
            if (TestConnection(address) != 0 || ss!= SendingStatus.SENT)
                return 1;
        } catch (MalformedRecipientException e) {
            e.printStackTrace();
            return 1;
        }
        //SENT
        return 0;
    }


}<file_sep>/**
 * Created by Hunter on 2015-04-08.
 */
package com.example.mock.messenger;
public enum ConnectionStatus {
    SUCCESS, FAILURE
}
<file_sep>/**
 * Created by Hunter on 2015-03-08.
 */
public class LiczbaRzymska {
    private int liczba;

    public LiczbaRzymska(int liczba){

        this.liczba = liczba;
    }
    public static String ToRom(int arabska){
        String roman = "";
        if(arabska < 1 || arabska > 3999){
            return "Insert Integer between 1 and 9999";
        }
        for(;arabska>=1000;arabska=arabska-1000) {
            roman = roman + "M";
        }
        for(;arabska>=900;arabska=arabska-900) {
            roman = roman + "CM";
        }
        for(;arabska>=500;arabska=arabska-500) {
            roman = roman + "D";
        }
        for(;arabska>=400;arabska=arabska-400) {
            roman = roman + "CD";
        }
        for(;arabska>=100;arabska=arabska-100) {
            roman = roman + "C";
        }
        for(;arabska>=90;arabska=arabska-90) {
            roman = roman + "XC";
        }
        for(;arabska>=50;arabska=arabska-50) {
            roman = roman + "L";
        }
        for(;arabska>=40;arabska=arabska-40) {
            roman = roman + "XL";
        }
        for(;arabska>=10;arabska=arabska-10) {
            roman = roman + "X";
        }
        for(;arabska>=9;arabska=arabska-9) {
            roman = roman + "IX";
        }
        for(;arabska>=5;arabska=arabska-5) {
            roman = roman + "V";
        }
        for(;arabska>=4;arabska=arabska-4) {
            roman = roman + "IV";
        }
        for(;arabska>=1;arabska=arabska-1) {
            roman = roman + "I";
        }

        return roman;
    }

    @Override
    public String toString() {
        return ToRom(liczba);
    }

    }

<file_sep>package com.example.maven.game;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
 * Created by Hunter on 2015-03-10.
 */
public class Psikus implements Ipsikus {

    @Override
    public Integer cyfrokrad(Integer liczba) {
        //Split of Integer to string
        String number = String.valueOf(liczba);
        List<Integer> digits = new ArrayList<Integer>();
        for(int i=0;i<number.length();i++){
            digits.add(number.charAt(i)-48);
        }
        if (digits.size() <=1 ){
            return null;
        }

        Random rand = new Random();
        int random = rand.nextInt(digits.size());
        digits.remove(random);

        int[] array = new int[digits.size()];
        for(int i=0;i < array.length ;i++){
            array[i] = digits.get(i);
        }
        int res=0;
        for(int i=0;i < array.length ;i++) {
            res = 10 * res + array[i];
        }
        return res;
    }

    @Override
    public Integer hultajchochla(Integer liczba) throws NieudanyPsikusException {
        String number = String.valueOf(liczba);
        List<Integer> digits = new ArrayList<Integer>();
        for(int i=0;i<number.length();i++){
            digits.add(number.charAt(i)-48);
        }

        Random random = new Random();
        int randomize = random.nextInt(digits.size());
        int randomize2 = random.nextInt(digits.size());

        int pom, pom2;
        try {
            if (digits.size() <= 1) {
                throw new NieudanyPsikusException("Wrong Length (it should be above 1)");
            }
            //switch
            pom = digits.get(randomize);
            pom2 = digits.get(randomize2);
            digits.set(randomize,pom2);
            digits.set(randomize2,pom);

        } catch (NieudanyPsikusException e) {
            System.out.println(e.getMessage());
        }
        //adding array to new integer
        int[] array = new int[digits.size()];
        for(int j=0;j < array.length ;j++){
            array[j] = digits.get(j);
        }
        int res=0;
        for(int j=0;j < array.length ;j++) {
            res = 10 * res + array[j];
        }
        return res;

    }

    @Override
    public Integer nieksztaltek(Integer liczba) {
        //Split of Integer to string
        String number = String.valueOf(liczba);
        List<Integer> digits = new ArrayList<Integer>();
        for(int i=0;i<number.length();i++){
            digits.add(number.charAt(i)-48);
        }

        int i;
        List<Integer> three = new ArrayList<Integer>();
        List<Integer> six = new ArrayList<Integer>();
        List<Integer> seven = new ArrayList<Integer>();
        for (i = 0; i < digits.size(); i++) {
            if (digits.get(i) == 3) {
                three.add(i);
            }
            if (digits.get(i) == 6) {
                six.add(i);
            }
            if (digits.get(i) == 7) {
                seven.add(i);
            }
        }
        //if empty return argument
        if (three.size() == 0 && six.size() == 0 && seven.size() == 0) {
            return liczba;
        }

        int randomize;
        Random random = new Random();
        if (three.size() != 0) {
            randomize = random.nextInt(three.size());
            digits.set(randomize,8);
        }
        if (six.size() != 0) {
            randomize = random.nextInt(six.size());
            digits.set(randomize,9);
        }
        if (seven.size() != 0) {
            randomize = random.nextInt(seven.size());
            digits.set(randomize,1);
        }
        //adding array to new integer
        int[] array = new int[digits.size()];
        for(int j=0;j < array.length ;j++){
            array[j] = digits.get(j);
        }
        int res=0;
        for(int j=0;j < array.length ;j++) {
            res = 10 * res + array[j];
        }
        return res;


    }
}
<file_sep>/**
 * Created by Hunter on 2015-03-18.
 */
package com.game.test;

import com.game.code.NieudanyPsikusException;
import com.game.code.Psikus;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;

public class PsikusTest {

    private Psikus psikus = new Psikus();

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    //cyfrokrad Tests
    @Test
    public void cyfrokradNotNullReturn() {
        Assert.assertNotNull(psikus.cyfrokrad(123).intValue());
    }

    @Test
    public void cyfrokradReturnNull() {
        Assert.assertNull(psikus.cyfrokrad(5));
    }

    @Test
    public void cyfrokradRemoveofOneNumber() {
        Assert.assertEquals(2, psikus.cyfrokrad(169).toString().length());
    }

    @Test
    public void cyfrokradLengthOfThree() {
        Assert.assertEquals(3, psikus.cyfrokrad(1694).toString().length());
    }

    //chujtajchochla Test
//   @Test
//    public void hultajchochlaException() throws NieudanyPsikusException {
//        thrown.expect(NieudanyPsikusException.class);
//        psikus.hultajchochla(1);
//    }

    @Test
    public void hultajchochlaDiffNumber() throws NieudanyPsikusException {
        Assert.assertNotSame(13246, psikus.hultajchochla(12346).toString());
    }

    //Nieksztaltek Tests:
    @Test
    public void nieksztaltekDiffrentResult() {
        Assert.assertThat(psikus.nieksztaltek(367).intValue(), is(anyOf(equalTo(867), equalTo(361), equalTo(397))));
    }

    @Test
    public void nieksztaltekSameNumberNothingToSwap() {
        Assert.assertEquals(124, psikus.nieksztaltek(124).intValue());
    }

    @Test
    public void nieksztaltekDiffrentNumberSwap() {
        Assert.assertNotEquals(136, psikus.nieksztaltek(136).intValue());
    }

    @Test
    public void nieksztaltekOnlySwap() {
        Assert.assertNotSame(376, psikus.nieksztaltek(376).intValue());
    }


}<file_sep>/**
 * Created by Hunter on 2015-03-08.
 */
public interface CalculatorDoubleImp {
    double add(double a, double b);
    double sub(double a, double b);
    double multi(double a, double b);
    double div(double a, double b);
    boolean greater(double a, double b);
}

<file_sep>package com.game.code;

/**
 * Created by Hunter on 2015-03-18.
 */
public interface IPsikus {
    Integer cyfrokrad(Integer liczba);
    Integer hultajchochla(Integer liczba) throws NieudanyPsikusException;
    Integer nieksztaltek(Integer liczba);
}
<file_sep>package com.game.code;

/**
 * Created by Hunter on 2015-03-18.
 */
public class NieudanyPsikusException extends Exception{
        private static final long serialVersionUID = -4197380075619961717L;
        //Parameterless Constructor
        //Constructor that accepts a message
        public NieudanyPsikusException(String message)
        {
            super(message);
        }
    }
<file_sep>package com.example.mock.messenger;

/**
 * Created by Hunter on 2015-04-08.
 */
public interface IMessageService {
    ConnectionStatus checkConnection(String server);

    SendingStatus send(String server, String contents) throws MalformedRecipientException;
}
<file_sep>package com.example.mock.messenger;

/**
 * Created by Hunter on 2015-04-08.
 */
public enum SendingStatus {
    SENT, SENDING_ERROR
}
<file_sep>/**
 * Created by Hunter on 2015-03-08.
 */
    public class Calculator implements CalculatorImp {
        @Override
        public int add(int a, int b) {
            return a+b;
        }
        @Override
        public int sub(int a, int b) {
            return a-b;
        }
        @Override
        public int multi(int a, int b) {
            return a*b;
        }
        @Override
        public int div(int a, int b) {
            return a/b;
        }
        @Override
        public boolean greater(int a, int b) {
            if(a>b) return true;
            else return false;
        }
    }
<file_sep>/**
 * Created by Hunter on 2015-03-10.
 */
    public interface PsikusImp {
        Integer cyfrokrad(Integer liczba);
        Integer hultajchochla(Integer liczba) throws NieudanyPsikusException;
        Integer nieksztaltek(Integer liczba);
    }
<file_sep>package com.example.mock.messenger;

import java.util.Random;

/**
 * Created by Hunter on 2015-04-08.
 */
public class DummyMsgService implements IMessageService {

    @Override
    public ConnectionStatus checkConnection(String server) {
        if(server.matches("www.[A-Za-z]{2,}.pl$")){
            return ConnectionStatus.SUCCESS;
        }
        return ConnectionStatus.FAILURE;
    }

    @Override
    public SendingStatus send(String server, String contents) throws MalformedRecipientException {
        if (server.length() < 4 || contents.length() < 2) {
            throw new MalformedRecipientException();
        }
        if(checkConnection(server) == ConnectionStatus.FAILURE) {
            return SendingStatus.SENDING_ERROR;
        }

        Random random = new Random();
        boolean x = random.nextBoolean();
        if(x){
            return  SendingStatus.SENT;
        }
            return SendingStatus.SENDING_ERROR;

    }
}
<file_sep>
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;

/**
 * Created by Hunter on 2015-04-22.
 */
public class TelemanTests {

    private static WebDriver driver;
    WebElement element;

    @BeforeClass
    public static void driverSetup() {
        // ChromeDrirver, FireforxDriver, ...
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\Hunter\\Downloads\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }
    @Test
    public void homePage(){
        driver.get("http://www.teleman.pl");
        assertEquals("Program TV",driver.getTitle());
    }

    @Test
    public void register() throws InterruptedException {

        driver.get("http://www.teleman.pl/");
        driver.findElement(By.cssSelector("a[href*='/account']")).click();

        driver.findElement(By.cssSelector("a[href*='/accounts/signup']")).click();

        driver.findElement(By.id("id_username")).sendKeys("test");
        driver.findElement(By.id("id_email")).sendKeys("<EMAIL>");
        driver.findElement(By.id("id_password")).sendKeys("<PASSWORD>");
        driver.findElement(By.xpath(".//*[@id='signupForm']/div[2]/input")).click();
        assertEquals("Użytkownik z taką nazwą jest już zarejestrowany.", driver.findElement(By.className("errorlist")).getText());
    }

    @Test
    public void login(){
        driver.get("http://www.teleman.pl/");
        driver.findElement(By.cssSelector("a[href*='/account']")).click();
        driver.findElement(By.id("id_username")).sendKeys("kekeke");
        driver.findElement(By.id("id_password")).sendKeys("<PASSWORD>");
        driver.findElement(By.xpath(".//*[@id='signupForm']/div[2]/input")).click();
        assertEquals("Nieprawidłowa nazwa użytkownika, email lub hasło. Pamietaj, że wielkość liter w haśle jest ważna.",driver.findElement(By.className("errorlist")).getText());
    }

    @Test
    public void search() throws IOException {
        driver.get("http://www.teleman.pl/");
        driver.findElement(By.xpath("//*[@id=\"search-form\"]/input[1]")).sendKeys("Liga Mistrzow");
        driver.findElement(By.xpath("//*[@id=\"search-form\"]/input[1]")).submit();
        driver.findElement(By.cssSelector("a[href*='/tv/Pilka-Nozna-Liga-Mistrzow-1305579")).click();
        assertEquals("rewanżowy mecz ćwierćfinałowy: Real Madryt - Atletico Madryt",driver.findElement(By.id("showMainInfo")).getText());
        assertEquals("CANAL+ Sport", driver.findElement(By.cssSelector("a[href*='/program-tv/stacje/CanalPlus-Sport#prog9974185")).getText());
        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, new File("c:\\Users\\Hunter\\Desktop\\screenshot.png"));
    }
    @Test
    public void loginAndCheck(){
        driver.get("http://www.morele.net/");
        driver.findElement(By.className("profile")).click();
        driver.findElement(By.name("email")).sendKeys("<EMAIL>");
        driver.findElement(By.name("password")).sendKeys("<PASSWORD>");
        driver.findElement(By.name("submitLogin")).click();
        driver.findElement(By.className("profile")).click();
        assertEquals("Patryk", driver.findElement(By.id("firstname")).getAttribute("value"));
        assertEquals("Adamaszek", driver.findElement(By.id("lastname")).getAttribute("value"));
        assertEquals("691766007", driver.findElement(By.id("phone")).getAttribute("value"));
        driver.findElement(By.className("logout")).click();
    }

    @Test
    public void addToCart(){
        driver.get("http://www.morele.net/");
        driver.findElement(By.className("profile")).click();
        driver.findElement(By.name("email")).sendKeys("<EMAIL>");
        driver.findElement(By.name("password")).sendKeys("<PASSWORD>");
        driver.findElement(By.name("submitLogin")).click();
        driver.findElement(By.className("department")).click();
        driver.findElement(By.cssSelector("a[href*='/komputer-morele-harcot-asus-gaming-kit-690856/")).click();

        driver.findElement(By.xpath(".//*[@id='right']/div/div[2]/p[4]/a/img")).click();

        driver.findElement(By.cssSelector("a[href*='/koszyk")).click();
        assertEquals("Komputer Morele Harcot Asus Gaming Kit", driver.findElement(By.xpath(".//*[@id='overflow']/form[2]/table/tbody/tr[1]/td[3]/a")).getText());
        driver.findElement(By.className("delete")).click();
        driver.findElement(By.className("logout")).click();
    }


    /*@AfterClass
    public static void cleanp() {
        driver.quit();
    }*/
}
