Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,21 @@
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<!-- End for New dependency -->

<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-lambda</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<!-- End for New dependency -->

</dependencies>

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/testFileA.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
proba
1 change: 1 addition & 0 deletions src/main/resources/testFileB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
proba
66 changes: 66 additions & 0 deletions src/test/java/com/example/gui_basic/CopyFilesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import com.example.gui_basic.CopyFiles;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class CopyFilesTest {

CopyFiles CopyFiles = null;

@BeforeEach
void setUp() {
CopyFiles = new CopyFiles();
}

@TempDir
Path tempDir;

@Test
@DisplayName("copyContent teszt Temp diractory-ban létrehozott fájllal")
void copyContent_tempDir() throws Exception {
// Create a temporary file. This is guaranteed to be deleted after the test finishes.
final Path tempFileA = Files.createFile(tempDir.resolve("tempFileA.txt"));
final Path tempFileB = Files.createFile(tempDir.resolve("tempFileB.txt"));

// Egyik fájlba a tesztszöveteg írjuk, ezt másoljuk majd át a másikba
Files.writeString(tempFileA, "Hello World");

// Meghívjuk a CopyFiles metódust
CopyFiles.copyContent(new File(tempFileA.toString()), new File(tempFileB.toString()));

// Visszaolvassuk a másik (CopyFiles metódussal másolt) fájl tartalmát
final String s = Files.readString(tempFileB);

// Ellenőrizzük, hogy egyezik-e az első fájlba írt tartalommal
assertThat("Hello World", is(s));
}

@Test
@DisplayName("copyContent teszt saját fájllal")
void copyContent_fixFile() throws Exception {
// 2 tesztfájl, testFileA.txt tartalma: "proba"
File testFileA = new File("C:\\Users\\Zsófi\\IdeaProjects\\GUI_basic\\src\\main\\resources\\testFileA.txt");
File testFileB = new File("C:\\Users\\Zsófi\\IdeaProjects\\GUI_basic\\src\\main\\resources\\testFileB.txt");

// testFileB.txt tartalmát töröljük
Files.writeString(testFileB.toPath(), "");

// Meghívjuk a CopyFiles metódust
CopyFiles.copyContent(testFileA, testFileB);

// Visszaolvassuk testFileB.txt tartalmát
final String s = Files.readString(Paths.get("C:\\Users\\Zsófi\\IdeaProjects\\GUI_basic\\src\\main\\resources\\testFileB.txt"));

// Ellenőrizzük, hogy egyezik-e az első fájlba írt tartalommal
assertThat("proba", is(s));
}
}