package pl.java.scalatech;

import static org.fest.assertions.Assertions.assertThat;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;

import lombok.extern.slf4j.Slf4j;

import org.junit.BeforeClass;
import org.junit.Test;

import com.google.common.base.Charsets;

@Slf4j
public class URLTest {

    private static File file;
    private URI fileLocation;

    @BeforeClass
    public static void init() {
        file = new File("src/test/resources/strings.txt");
    }

    @Test
    public void shouldFilelocationExists() {
        log.info("{}", fileLocation);
    }

    @Test
    public void shouldURLConnect() throws IOException {
        URL url = new URL("http://przewidywalna-java.blogspot.com/");
        StringBuilder fileContent;
        try (InputStream in = url.openStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in, Charsets.UTF_8));) {
            fileContent = new StringBuilder();
            String line = bufferedReader.readLine();
            while (line != null) {
                fileContent.append(line);
                line = bufferedReader.readLine();
            }
        }
        assertThat(fileContent.toString().contains("przewidywalna-java.blogspot.com/search/label")).isTrue();
    }
}

@@ -326,109 +326,509 @@
 fore
-Class;%0Aimport org.junit.Test;%0A%0Aimport com.google.common.base.Charsets;%0A%0A@Slf4j%0Apublic class URLTest %7B
+;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.TemporaryFolder;%0A%0Aimport com.google.common.base.Charsets;%0A%0A@Slf4j%0Apublic class URLTest %7B%0A%0A    @Rule%0A    public TemporaryFolder testFolder = new TemporaryFolder();%0A    private File fileTemp;%0A%0A    @Before%0A    public void initStep() throws IOException %7B%0A        testFolder.newFolder(%22test_%22);%0A        fileTemp = testFolder.newFile(%22t.txt%22);%0A        log.info(%22file :  %7B%7D%22, file.getAbsolutePath());%0A%0A    %7D
 %0A%0A  

test @Rule TemporaryFolder