Add files via upload (#13978)

This commit is contained in:
Bahaa El-Din Helmy 2023-05-09 00:11:33 +03:00 committed by GitHub
parent 4cc0380249
commit 53d269ca68
10 changed files with 502 additions and 353 deletions

View File

@ -31,8 +31,77 @@
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<!-- this is all you need to write tests with JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter-version}</version>
<scope>test</scope>
</dependency>
<!-- this dependency is needed to create parameterized tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter-version}</version>
<scope>test</scope>
</dependency>
<!-- contains the engine that actually runs the Jupiter-tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<junit-jupiter-version>5.2.0</junit-jupiter-version>
</properties>
<build>
<finalName>core-java-io-apis-2</finalName>
<resources>

View File

@ -0,0 +1,36 @@
package com.baeldung.multinput;
import java.util.InputMismatchException;
import java.util.Scanner;
public class MultiInputs {
public void UsingSpaceDelimiter(){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter two numbers: ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
System.out.println("You entered " + num1 + " and " + num2);
}
public void UsingREDelimiter(){
Scanner scanner = new Scanner(System.in);
scanner.useDelimiter("[\\s,]+");
System.out.print("Enter two numbers separated by a space or a comma: ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
System.out.println("You entered " + num1 + " and " + num2);
}
public void UsingCustomDelimiter(){
Scanner scanner = new Scanner(System.in);
scanner.useDelimiter(";");
System.out.print("Enter two numbers separated by a semicolon: ");
try { int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
System.out.println("You entered " + num1 + " and " + num2); }
catch (InputMismatchException e)
{ System.out.println("Invalid input. Please enter two integers separated by a semicolon."); }
}
}

View File

@ -1,11 +1,10 @@
package com.baeldung.absolutetorelative;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class AbsoluteToRelativeUnitTest {
@ -22,7 +21,7 @@ public class AbsoluteToRelativeUnitTest {
public void givenAbsolutePaths_whenRelativizePathOneToPathTwo_thenRelativeIsReturned() {
Path result = pathOne.relativize(pathTwo);
Assertions.assertThat(result)
org.assertj.core.api.Assertions.assertThat(result)
.isRelative()
.isEqualTo(Paths.get("../two.txt"));
}
@ -31,7 +30,7 @@ public class AbsoluteToRelativeUnitTest {
public void givenAbsolutePaths_whenRelativizePathTwoToPathOne_thenRelativeIsReturned() {
Path result = pathTwo.relativize(pathOne);
Assertions.assertThat(result)
org.assertj.core.api.Assertions.assertThat(result)
.isRelative()
.isEqualTo(Paths.get("../one.txt"));
}
@ -40,7 +39,7 @@ public class AbsoluteToRelativeUnitTest {
public void givenAbsolutePaths_whenRelativizePathOneParentToPathTwo_thenRelativeIsReturned() {
Path result = pathOne.getParent().relativize(pathTwo);
Assertions.assertThat(result)
org.assertj.core.api.Assertions.assertThat(result)
.isRelative()
.isEqualTo(Paths.get("two.txt"));
}
@ -49,7 +48,7 @@ public class AbsoluteToRelativeUnitTest {
public void givenAbsolutePaths_whenRelativizePathOneToPathThree_thenRelativeIsReturned() {
Path result = pathOne.relativize(pathThree);
Assertions.assertThat(result)
org.assertj.core.api.Assertions.assertThat(result)
.isRelative()
.isEqualTo(Paths.get("../../foo/three.txt"));
}
@ -58,7 +57,7 @@ public class AbsoluteToRelativeUnitTest {
public void givenAbsolutePaths_whenRelativizePathThreeToPathOne_thenRelativeIsReturned() {
Path result = pathThree.relativize(pathOne);
Assertions.assertThat(result)
org.assertj.core.api.Assertions.assertThat(result)
.isRelative()
.isEqualTo(Paths.get("../../bar/one.txt"));
}
@ -67,7 +66,7 @@ public class AbsoluteToRelativeUnitTest {
public void givenAbsoluteURIs_whenRelativizeUriOneToUriTwo_thenAbsoluteIsReturned() {
URI result = uriOne.relativize(uriTwo);
Assertions.assertThat(result)
org.assertj.core.api.Assertions.assertThat(result)
.asString()
.contains("/baeldung/bar/two.txt");
}
@ -76,7 +75,7 @@ public class AbsoluteToRelativeUnitTest {
public void givenAbsoluteURIs_whenRelativizeUriOneParentToUriTwo_thenRelativeIsReturned() {
URI result = pathOne.getParent().toUri().relativize(uriTwo);
Assertions.assertThat(result)
org.assertj.core.api.Assertions.assertThat(result)
.asString()
.contains("two.txt");
}
@ -85,7 +84,7 @@ public class AbsoluteToRelativeUnitTest {
public void givenAbsoluteURIs_whenRelativizeUriOneParentToUriThree_thenAbsoluteIsReturned() {
URI result = pathOne.getParent().toUri().relativize(uriThree);
Assertions.assertThat(result)
org.assertj.core.api.Assertions.assertThat(result)
.asString()
.contains("/baeldung/foo/three.txt");
}

View File

@ -1,13 +1,13 @@
package com.baeldung.bufferedreadervsfilereader;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import org.junit.jupiter.api.Assertions;
import org.testng.annotations.Test;
public class BufferedReaderUnitTest {
@Test

View File

@ -1,11 +1,11 @@
package com.baeldung.bufferedreadervsfilereader;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.FileReader;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class FileReaderUnitTest {

View File

@ -0,0 +1,47 @@
package com.baeldung.multinput;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.InputMismatchException;
import org.junit.jupiter.api.Assertions;
import org.testng.annotations.Test;
import com.baeldung.multinput.MultiInputs;
public class TestMultipleInputsUnitTest {
@Test
public void givenMultipleInputs_whenUsingSpaceDelimiter_thenExpectPrintingOutputs() {
String input = "10 20\n";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
MultiInputs mi = new MultiInputs();
mi.UsingSpaceDelimiter();
// You can add assertions here to verify the behavior of the method
}
@Test
public void givenMultipleInputs_whenUsingREDelimiter_thenExpectPrintingOutputs() {
String input = "30, 40\n";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
MultiInputs mi = new MultiInputs();
mi.UsingREDelimiter();
// You can add assertions here to verify the behavior of the method
}
@Test
public void givenMultipleInputs_whenUsingCustomDelimiter_thenExpectPrintingOutputs() {
String input = "50; 60\n";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
MultiInputs mi = new MultiInputs();
mi.UsingCustomDelimiter();
// You can add assertions here to verify the behavior of the method
}
@Test
public void givenInvalidInput_whenUsingSpaceDelimiter_thenExpectInputMismatchException() {
String input = "abc\n";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
MultiInputs mi = new MultiInputs();
Assertions.assertThrows(InputMismatchException.class, mi::UsingSpaceDelimiter);
}
}

View File

@ -1,13 +1,11 @@
package com.baeldung.path;
import org.junit.jupiter.api.Test;
import java.io.File;
import static org.junit.Assert.assertEquals;
import javax.swing.filechooser.FileSystemView;
import org.junit.jupiter.api.Test;
public class DesktopPathUnitTest {
// Adapt DESKTOP_PATH variable to your own system path
// private static final String DESKTOP_PATH = "C:\\Users\\HRAF\\Desktop";