Merge pull request #5676 from rozagerardo/geroza/BAEL-10301_fix-unit-tests-in-core-java-module

[BAEL-10301] core-java | fix unit tests
This commit is contained in:
Loredana Crusoveanu 2018-11-13 23:50:25 +02:00 committed by GitHub
commit b5907e06e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 9 deletions

View File

@ -2,6 +2,9 @@ package com.baeldung.abstractclasses;
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
import com.baeldung.abstractclasses.filereaders.LowercaseFileReader;
import java.net.URL;
import java.nio.file.Paths;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@ -10,7 +13,9 @@ public class LowercaseFileReaderUnitTest {
@Test
public void givenLowercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception {
String filePath = getClass().getClassLoader().getResource("files/test.txt").getPath().substring(1);
// We'll transform the resource URL path to URI to load the file correctly in Windows
URL url = getClass().getClassLoader().getResource("files/test.txt");
String filePath = Paths.get(url.toURI()).toString();
BaseFileReader lowercaseFileReader = new LowercaseFileReader(filePath);
assertThat(lowercaseFileReader.readFile()).isInstanceOf(List.class);

View File

@ -1,16 +1,23 @@
package com.baeldung.abstractclasses;
import static org.assertj.core.api.Assertions.assertThat;
import java.net.URL;
import java.nio.file.Paths;
import java.util.List;
import org.junit.Test;
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
import com.baeldung.abstractclasses.filereaders.StandardFileReader;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class StandardFileReaderUnitTest {
@Test
public void givenStandardFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception {
String filePath = getClass().getClassLoader().getResource("files/test.txt").getPath().substring(1);
// We'll transform the resource URL path to URI to load the file correctly in Windows
URL url = getClass().getClassLoader().getResource("files/test.txt");
String filePath = Paths.get(url.toURI()).toString();
BaseFileReader standardFileReader = new StandardFileReader(filePath);
assertThat(standardFileReader.readFile()).isInstanceOf(List.class);

View File

@ -2,6 +2,9 @@ package com.baeldung.abstractclasses;
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
import com.baeldung.abstractclasses.filereaders.UppercaseFileReader;
import java.net.URL;
import java.nio.file.Paths;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@ -10,7 +13,9 @@ public class UppercaseFileReaderUnitTest {
@Test
public void givenUppercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception {
String filePath = getClass().getClassLoader().getResource("files/test.txt").getPath().substring(1);
// We'll transform the resource URL path to URI to load the file correctly in Windows
URL url = getClass().getClassLoader().getResource("files/test.txt");
String filePath = Paths.get(url.toURI()).toString();
BaseFileReader uppercaseFileReader = new UppercaseFileReader(filePath);
assertThat(uppercaseFileReader.readFile()).isInstanceOf(List.class);

View File

@ -25,7 +25,7 @@ public class SimpleDateFormatUnitTest {
@Test
public void givenSpecificDate_whenFormattedUsingDateFormat_thenCheckFormatCorrect() throws Exception {
DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT);
DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
assertEquals("5/24/77", formatter.format(new Date(233345223232L)));
}