소스 검색

FileConventer

user 1 년 전
부모
커밋
0aa9b3cc04

+ 1 - 0
8/dir/file1.txt

@@ -0,0 +1 @@
+asd

+ 3 - 0
8/dir/file2.txt

@@ -0,0 +1,3 @@
+qwe
+zxc
+

+ 70 - 0
8/pom.xml

@@ -0,0 +1,70 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<modelVersion>4.0.0</modelVersion>
+<groupId>pl.dmcs</groupId>
+<artifactId>app8</artifactId>
+<version>1.0</version>
+<packaging>jar</packaging>
+<properties>
+<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+<maven.compiler.source>11</maven.compiler.source>
+<maven.compiler.target>11</maven.compiler.target>
+</properties>
+<!--  useful for documentation generation  -->
+<name>My sample project</name>
+<description>This is my sample project.</description>
+<url>https://weeia.p.lodz.pl</url>
+<dependencies>
+<dependency>
+<groupId>org.junit.jupiter</groupId>
+<artifactId>junit-jupiter-engine</artifactId>
+<version>5.10.2</version>
+<scope>test</scope>
+</dependency>
+</dependencies>
+<build>
+<pluginManagement>
+<!--  lock down plugins versions to avoid using Maven defaults  -->
+<plugins>
+<!--  clean lifecycle  -->
+<plugin>
+<artifactId>maven-clean-plugin</artifactId>
+<version>3.3.2</version>
+</plugin>
+<!--  default lifecycle  -->
+<plugin>
+<artifactId>maven-resources-plugin</artifactId>
+<version>3.3.1</version>
+</plugin>
+<plugin>
+<artifactId>maven-compiler-plugin</artifactId>
+<version>3.12.1</version>
+</plugin>
+<plugin>
+<artifactId>maven-surefire-plugin</artifactId>
+<version>3.2.5</version>
+</plugin>
+<plugin>
+<artifactId>maven-jar-plugin</artifactId>
+<version>3.3.0</version>
+</plugin>
+<plugin>
+<artifactId>maven-install-plugin</artifactId>
+<version>3.1.1</version>
+</plugin>
+<plugin>
+<artifactId>maven-deploy-plugin</artifactId>
+<version>3.1.1</version>
+</plugin>
+<!--  site lifecycle  -->
+<plugin>
+<artifactId>maven-site-plugin</artifactId>
+<version>4.0.0-M13</version>
+</plugin>
+<plugin>
+<artifactId>maven-project-info-reports-plugin</artifactId>
+<version>3.5.0</version>
+</plugin>
+</plugins>
+</pluginManagement>
+</build>
+</project>

+ 19 - 0
8/src/main/java/pl/weeia/FileConverter.java

@@ -0,0 +1,19 @@
+package pl.weeia;
+
+import java.io.*;
+import java.nio.file.*;
+import java.util.stream.*;
+
+public class FileConverter {
+    public void convertFileToUpperCase(String filePath) throws IOException {
+        Path path = Paths.get(filePath);
+        if (!Files.exists(path)) {
+            throw new FileNotFoundException("Plik nie istnieje: " + filePath);
+        }
+
+        String content = Files.readString(path);
+        String upperCaseContent = content.toUpperCase();
+        Files.writeString(path, upperCaseContent);
+    }
+}
+

+ 9 - 0
8/src/main/java/pl/weeia/Main.java

@@ -0,0 +1,9 @@
+package pl.weeia;
+import java.io.IOException;
+import java.util.Scanner;
+
+public class Main {
+    public static void main(String[] args) {
+
+  }
+}

+ 36 - 0
8/src/test/java/FileConverterTest.java

@@ -0,0 +1,36 @@
+import org.junit.jupiter.api.*;
+import pl.weeia.FileConverter;
+
+import java.io.*;
+import java.nio.file.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class FileConverterTest {
+    private final FileConverter fileConverter = new FileConverter();
+    private Path tempFile;
+
+    @BeforeEach
+    public void setUp() throws IOException {
+        tempFile = Files.createTempFile("testFile", ".txt");
+        Files.writeString(tempFile, "Test123\nabcXYZ");
+    }
+
+    @AfterEach
+    public void tearDown() throws IOException {
+        Files.deleteIfExists(tempFile);
+    }
+
+    @Test
+    public void testConvertFileToUpperCase() throws IOException {
+        fileConverter.convertFileToUpperCase(tempFile.toString());
+        String content = Files.readString(tempFile);
+        assertEquals("TEST123\nABCXYZ", content);
+    }
+
+    @Test
+    public void testConvertFileWithNonExistentPath() {
+        assertThrows(FileNotFoundException.class, () ->
+                fileConverter.convertFileToUpperCase("non_existent_file.txt"));
+    }
+}
+

BIN
8/target/app8-1.0.jar


BIN
8/target/classes/pl/weeia/FileConverter.class


BIN
8/target/classes/pl/weeia/Main.class


+ 3 - 0
8/target/maven-archiver/pom.properties

@@ -0,0 +1,3 @@
+artifactId=app8
+groupId=pl.dmcs
+version=1.0

+ 2 - 0
8/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

@@ -0,0 +1,2 @@
+pl/weeia/FileConverter.class
+pl/weeia/Main.class

+ 2 - 0
8/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

@@ -0,0 +1,2 @@
+/home/user/testy/tasks/8/src/main/java/pl/weeia/FileConverter.java
+/home/user/testy/tasks/8/src/main/java/pl/weeia/Main.java

+ 1 - 0
8/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst

@@ -0,0 +1 @@
+FileConverterTest.class

+ 1 - 0
8/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst

@@ -0,0 +1 @@
+/home/user/testy/tasks/8/src/test/java/FileConverterTest.java

+ 4 - 0
8/target/surefire-reports/DirConverterTest.txt

@@ -0,0 +1,4 @@
+-------------------------------------------------------------------------------
+Test set: DirConverterTest
+-------------------------------------------------------------------------------
+Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.087 s -- in DirConverterTest

+ 4 - 0
8/target/surefire-reports/FileConverterTest.txt

@@ -0,0 +1,4 @@
+-------------------------------------------------------------------------------
+Test set: FileConverterTest
+-------------------------------------------------------------------------------
+Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.073 s -- in FileConverterTest

+ 57 - 0
8/target/surefire-reports/TEST-DirConverterTest.xml

@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="DirConverterTest" time="0.087" tests="2" errors="0" skipped="0" failures="0">
+  <properties>
+    <property name="java.specification.version" value="17"/>
+    <property name="sun.jnu.encoding" value="UTF-8"/>
+    <property name="java.class.path" value="/home/user/testy/tasks/8/target/test-classes:/home/user/testy/tasks/8/target/classes:/home/user/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.2/junit-jupiter-engine-5.10.2.jar:/home/user/.m2/repository/org/junit/platform/junit-platform-engine/1.10.2/junit-platform-engine-1.10.2.jar:/home/user/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/home/user/.m2/repository/org/junit/platform/junit-platform-commons/1.10.2/junit-platform-commons-1.10.2.jar:/home/user/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.2/junit-jupiter-api-5.10.2.jar:/home/user/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:"/>
+    <property name="java.vm.vendor" value="Debian"/>
+    <property name="sun.arch.data.model" value="64"/>
+    <property name="java.vendor.url" value="https://tracker.debian.org/openjdk-17"/>
+    <property name="os.name" value="Linux"/>
+    <property name="java.vm.specification.version" value="17"/>
+    <property name="sun.java.launcher" value="SUN_STANDARD"/>
+    <property name="user.country" value="US"/>
+    <property name="sun.boot.library.path" value="/usr/lib/jvm/java-17-openjdk-amd64/lib"/>
+    <property name="sun.java.command" value="/home/user/testy/tasks/8/target/surefire/surefirebooter-20250126210018379_3.jar /home/user/testy/tasks/8/target/surefire 2025-01-26T21-00-18_286-jvmRun1 surefire-20250126210018379_1tmp surefire_0-20250126210018379_2tmp"/>
+    <property name="jdk.debug" value="release"/>
+    <property name="surefire.test.class.path" value="/home/user/testy/tasks/8/target/test-classes:/home/user/testy/tasks/8/target/classes:/home/user/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.2/junit-jupiter-engine-5.10.2.jar:/home/user/.m2/repository/org/junit/platform/junit-platform-engine/1.10.2/junit-platform-engine-1.10.2.jar:/home/user/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/home/user/.m2/repository/org/junit/platform/junit-platform-commons/1.10.2/junit-platform-commons-1.10.2.jar:/home/user/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.2/junit-jupiter-api-5.10.2.jar:/home/user/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:"/>
+    <property name="sun.cpu.endian" value="little"/>
+    <property name="user.home" value="/home/user"/>
+    <property name="user.language" value="en"/>
+    <property name="java.specification.vendor" value="Oracle Corporation"/>
+    <property name="java.version.date" value="2024-10-15"/>
+    <property name="java.home" value="/usr/lib/jvm/java-17-openjdk-amd64"/>
+    <property name="file.separator" value="/"/>
+    <property name="basedir" value="/home/user/testy/tasks/8"/>
+    <property name="java.vm.compressedOopsMode" value="32-bit"/>
+    <property name="line.separator" value="&#10;"/>
+    <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
+    <property name="java.specification.name" value="Java Platform API Specification"/>
+    <property name="surefire.real.class.path" value="/home/user/testy/tasks/8/target/surefire/surefirebooter-20250126210018379_3.jar"/>
+    <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
+    <property name="java.runtime.version" value="17.0.13+11-Debian-2deb12u1"/>
+    <property name="user.name" value="user"/>
+    <property name="path.separator" value=":"/>
+    <property name="os.version" value="6.1.0-28-amd64"/>
+    <property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
+    <property name="file.encoding" value="UTF-8"/>
+    <property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
+    <property name="localRepository" value="/home/user/.m2/repository"/>
+    <property name="java.vendor.url.bug" value="https://bugs.debian.org/openjdk-17"/>
+    <property name="java.io.tmpdir" value="/tmp"/>
+    <property name="java.version" value="17.0.13"/>
+    <property name="user.dir" value="/home/user/testy/tasks/8"/>
+    <property name="os.arch" value="amd64"/>
+    <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
+    <property name="native.encoding" value="UTF-8"/>
+    <property name="java.library.path" value="/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib"/>
+    <property name="java.vm.info" value="mixed mode, sharing"/>
+    <property name="java.vendor" value="Debian"/>
+    <property name="java.vm.version" value="17.0.13+11-Debian-2deb12u1"/>
+    <property name="java.specification.maintenance.version" value="1"/>
+    <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
+    <property name="java.class.version" value="61.0"/>
+  </properties>
+  <testcase name="testConvertFilesInNonExistentDirectory" classname="DirConverterTest" time="0.053"/>
+  <testcase name="testConvertFilesInDirectoryToUpperCase" classname="DirConverterTest" time="0.006"/>
+</testsuite>

+ 57 - 0
8/target/surefire-reports/TEST-FileConverterTest.xml

@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="FileConverterTest" time="0.073" tests="2" errors="0" skipped="0" failures="0">
+  <properties>
+    <property name="java.specification.version" value="17"/>
+    <property name="sun.jnu.encoding" value="UTF-8"/>
+    <property name="java.class.path" value="/home/user/testy/tasks/8/target/test-classes:/home/user/testy/tasks/8/target/classes:/home/user/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.2/junit-jupiter-engine-5.10.2.jar:/home/user/.m2/repository/org/junit/platform/junit-platform-engine/1.10.2/junit-platform-engine-1.10.2.jar:/home/user/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/home/user/.m2/repository/org/junit/platform/junit-platform-commons/1.10.2/junit-platform-commons-1.10.2.jar:/home/user/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.2/junit-jupiter-api-5.10.2.jar:/home/user/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:"/>
+    <property name="java.vm.vendor" value="Debian"/>
+    <property name="sun.arch.data.model" value="64"/>
+    <property name="java.vendor.url" value="https://tracker.debian.org/openjdk-17"/>
+    <property name="os.name" value="Linux"/>
+    <property name="java.vm.specification.version" value="17"/>
+    <property name="sun.java.launcher" value="SUN_STANDARD"/>
+    <property name="user.country" value="US"/>
+    <property name="sun.boot.library.path" value="/usr/lib/jvm/java-17-openjdk-amd64/lib"/>
+    <property name="sun.java.command" value="/home/user/testy/tasks/8/target/surefire/surefirebooter-20250126210156962_3.jar /home/user/testy/tasks/8/target/surefire 2025-01-26T21-01-56_872-jvmRun1 surefire-20250126210156962_1tmp surefire_0-20250126210156962_2tmp"/>
+    <property name="jdk.debug" value="release"/>
+    <property name="surefire.test.class.path" value="/home/user/testy/tasks/8/target/test-classes:/home/user/testy/tasks/8/target/classes:/home/user/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.2/junit-jupiter-engine-5.10.2.jar:/home/user/.m2/repository/org/junit/platform/junit-platform-engine/1.10.2/junit-platform-engine-1.10.2.jar:/home/user/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/home/user/.m2/repository/org/junit/platform/junit-platform-commons/1.10.2/junit-platform-commons-1.10.2.jar:/home/user/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.2/junit-jupiter-api-5.10.2.jar:/home/user/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:"/>
+    <property name="sun.cpu.endian" value="little"/>
+    <property name="user.home" value="/home/user"/>
+    <property name="user.language" value="en"/>
+    <property name="java.specification.vendor" value="Oracle Corporation"/>
+    <property name="java.version.date" value="2024-10-15"/>
+    <property name="java.home" value="/usr/lib/jvm/java-17-openjdk-amd64"/>
+    <property name="file.separator" value="/"/>
+    <property name="basedir" value="/home/user/testy/tasks/8"/>
+    <property name="java.vm.compressedOopsMode" value="32-bit"/>
+    <property name="line.separator" value="&#10;"/>
+    <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
+    <property name="java.specification.name" value="Java Platform API Specification"/>
+    <property name="surefire.real.class.path" value="/home/user/testy/tasks/8/target/surefire/surefirebooter-20250126210156962_3.jar"/>
+    <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
+    <property name="java.runtime.version" value="17.0.13+11-Debian-2deb12u1"/>
+    <property name="user.name" value="user"/>
+    <property name="path.separator" value=":"/>
+    <property name="os.version" value="6.1.0-28-amd64"/>
+    <property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
+    <property name="file.encoding" value="UTF-8"/>
+    <property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
+    <property name="localRepository" value="/home/user/.m2/repository"/>
+    <property name="java.vendor.url.bug" value="https://bugs.debian.org/openjdk-17"/>
+    <property name="java.io.tmpdir" value="/tmp"/>
+    <property name="java.version" value="17.0.13"/>
+    <property name="user.dir" value="/home/user/testy/tasks/8"/>
+    <property name="os.arch" value="amd64"/>
+    <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
+    <property name="native.encoding" value="UTF-8"/>
+    <property name="java.library.path" value="/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib"/>
+    <property name="java.vm.info" value="mixed mode, sharing"/>
+    <property name="java.vendor" value="Debian"/>
+    <property name="java.vm.version" value="17.0.13+11-Debian-2deb12u1"/>
+    <property name="java.specification.maintenance.version" value="1"/>
+    <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
+    <property name="java.class.version" value="61.0"/>
+  </properties>
+  <testcase name="testConvertFileToUpperCase" classname="FileConverterTest" time="0.046"/>
+  <testcase name="testConvertFileWithNonExistentPath" classname="FileConverterTest" time="0.004"/>
+</testsuite>

BIN
8/target/test-classes/FileConverterTest.class