JAVA-27645 Check article code matches github (#15323)
This commit is contained in:
parent
6508331a74
commit
76a2939e7d
@ -11,55 +11,55 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
public class InstanceOfUnitTest {
|
||||
|
||||
@Test
|
||||
void giveWhenInstanceIsCorrect_thenReturnTrue() {
|
||||
void givenWhenInstanceIsCorrect_thenReturnTrue() {
|
||||
Ring ring = new Ring();
|
||||
assertTrue(ring instanceof Round);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenObjectIsInstanceOfType_thenReturnTrue() {
|
||||
void givenWhenObjectIsInstanceOfType_thenReturnTrue() {
|
||||
Circle circle = new Circle();
|
||||
assertTrue(circle instanceof Circle);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void giveWhenInstanceIsOfSubtype_thenReturnTrue() {
|
||||
void givenWhenInstanceIsOfSubtype_thenReturnTrue() {
|
||||
Circle circle = new Circle();
|
||||
assertTrue(circle instanceof Round);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenTypeIsInterface_thenReturnTrue() {
|
||||
void givenWhenTypeIsInterface_thenReturnTrue() {
|
||||
Circle circle = new Circle();
|
||||
assertTrue(circle instanceof Shape);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenTypeIsOfObjectType_thenReturnTrue() {
|
||||
void givenWhenTypeIsOfObjectType_thenReturnTrue() {
|
||||
Thread thread = new Thread();
|
||||
assertTrue(thread instanceof Object);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenInstanceValueIsNull_thenReturnFalse() {
|
||||
void givenWhenInstanceValueIsNull_thenReturnFalse() {
|
||||
Circle circle = null;
|
||||
assertFalse(circle instanceof Round);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenComparingClassInDiffHierarchy_thenCompilationError() {
|
||||
void givenWhenComparingClassInDiffHierarchy_thenCompilationError() {
|
||||
//assertFalse( circle instanceof Triangle);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenStream_whenCastWithoutInstanceOfChk_thenGetException() {
|
||||
void givenWhenStream_whenCastWithoutInstanceOfChk_thenGetException() {
|
||||
Stream<Round> roundStream = Stream.of(new Ring(), new Ring(), new Circle());
|
||||
assertThrows(ClassCastException.class, () -> roundStream.map(it -> (Ring) it).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenStream_whenCastAfterInstanceOfChk_thenGetExpectedResult() {
|
||||
void givenWhenStream_whenCastAfterInstanceOfChk_thenGetExpectedResult() {
|
||||
Stream<Round> roundStream = Stream.of(new Ring(), new Ring(), new Circle());
|
||||
List<Ring> ringList = roundStream.filter(it -> it instanceof Ring).map(it -> (Ring) it).collect(Collectors.toList());
|
||||
assertEquals(2, ringList.size());
|
||||
|
@ -14,52 +14,52 @@ import java.util.List;
|
||||
public class Application {
|
||||
|
||||
// CSV Reader Examples
|
||||
public static List<String[]> readLineByLineSyncExample() throws Exception {
|
||||
public static List<String[]> readLineByLineExample() throws Exception {
|
||||
Path path = Helpers.twoColumnCsvPath();
|
||||
return CsvReaderExamples.readLineByLine(path);
|
||||
}
|
||||
|
||||
public static List<String[]> readAllLinesSyncExample() throws Exception {
|
||||
public static List<String[]> readAllLinesExample() throws Exception {
|
||||
Path path = Helpers.twoColumnCsvPath();
|
||||
return CsvReaderExamples.readAllLines(path);
|
||||
}
|
||||
|
||||
// CSV Writer Examples
|
||||
public static String writeLineByLineSyncExample() throws Exception {
|
||||
public static String writeLineByLineExample() throws Exception {
|
||||
Path path = Helpers.fileOutOnePath();
|
||||
return CsvWriterExamples.writeLineByLine(Helpers.fourColumnCsvString(), path);
|
||||
}
|
||||
|
||||
public static String writeAllLinesSyncExample() throws Exception {
|
||||
public static String writeAllLinesExample() throws Exception {
|
||||
Path path = Helpers.fileOutAllPath();
|
||||
return CsvWriterExamples.writeAllLines(Helpers.fourColumnCsvString(), path);
|
||||
}
|
||||
|
||||
// Bean Examples
|
||||
public static List<CsvBean> simpleSyncPositionBeanExample() throws Exception {
|
||||
public static List<CsvBean> simplePositionBeanExample() throws Exception {
|
||||
Path path = Helpers.twoColumnCsvPath();
|
||||
return BeanExamples.beanBuilderExample(path, SimplePositionBean.class);
|
||||
}
|
||||
|
||||
public static List<CsvBean> namedSyncColumnBeanExample() throws Exception {
|
||||
public static List<CsvBean> namedColumnBeanExample() throws Exception {
|
||||
Path path = Helpers.namedColumnCsvPath();
|
||||
return BeanExamples.beanBuilderExample(path, NamedColumnBean.class);
|
||||
}
|
||||
|
||||
public static String writeSyncCsvFromBeanExample() throws Exception {
|
||||
public static String writeCsvFromBeanExample() throws Exception {
|
||||
Path path = Helpers.fileOutBeanPath();
|
||||
return BeanExamples.writeCsvFromBean(path);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
simpleSyncPositionBeanExample();
|
||||
namedSyncColumnBeanExample();
|
||||
writeSyncCsvFromBeanExample();
|
||||
readLineByLineSyncExample();
|
||||
readAllLinesSyncExample();
|
||||
writeLineByLineSyncExample();
|
||||
writeAllLinesSyncExample();
|
||||
simplePositionBeanExample();
|
||||
namedColumnBeanExample();
|
||||
writeCsvFromBeanExample();
|
||||
readLineByLineExample();
|
||||
readAllLinesExample();
|
||||
writeLineByLineExample();
|
||||
writeAllLinesExample();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error during csv processing", e);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class OpenCsvIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenSampleData_whenReadUsingPosition_thenContentsRead() throws Exception {
|
||||
List<CsvBean> values = Application.simpleSyncPositionBeanExample();
|
||||
List<CsvBean> values = Application.simplePositionBeanExample();
|
||||
|
||||
assertThat(values)
|
||||
.extracting(Object::toString)
|
||||
@ -28,7 +28,7 @@ public class OpenCsvIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenSampleData_whenReadUsingNamedColumn_thenContentsRead() throws Exception {
|
||||
List<CsvBean> values = Application.namedSyncColumnBeanExample();
|
||||
List<CsvBean> values = Application.namedColumnBeanExample();
|
||||
|
||||
assertThat(values)
|
||||
.extracting(Object::toString)
|
||||
@ -41,7 +41,7 @@ public class OpenCsvIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenSampleData_whenReadLineByLine_thenContentsRead() throws Exception {
|
||||
List<String[]> lineByLineContents = Application.readLineByLineSyncExample();
|
||||
List<String[]> lineByLineContents = Application.readLineByLineExample();
|
||||
|
||||
assertThat(lineByLineContents)
|
||||
.containsExactly(
|
||||
@ -56,7 +56,7 @@ public class OpenCsvIntegrationTest {
|
||||
@Test
|
||||
public void givenSampleData_whenReadAllLines_thenContentsRead() throws Exception {
|
||||
|
||||
List<String[]> contents = Application.readAllLinesSyncExample();
|
||||
List<String[]> contents = Application.readAllLinesExample();
|
||||
|
||||
assertThat(contents)
|
||||
.containsExactly(
|
||||
@ -70,7 +70,7 @@ public class OpenCsvIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenSampleData_whenWriteCsvUsingBean_thenContentsWritten() throws Exception {
|
||||
String contents = Application.writeSyncCsvFromBeanExample();
|
||||
String contents = Application.writeCsvFromBeanExample();
|
||||
|
||||
assertThat(contents.split(NEW_LINE))
|
||||
.containsExactly(
|
||||
@ -82,7 +82,7 @@ public class OpenCsvIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenSampleData_whenWriteCsvLineByLine_thenContentsWritten() throws Exception {
|
||||
String contents = Application.writeLineByLineSyncExample();
|
||||
String contents = Application.writeLineByLineExample();
|
||||
|
||||
assertThat(contents.split(NEW_LINE))
|
||||
.containsExactly(
|
||||
@ -94,7 +94,7 @@ public class OpenCsvIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenSampleData_whenWriteCsvAllLines_thenContentsWritten() throws Exception {
|
||||
String contents = Application.writeAllLinesSyncExample();
|
||||
String contents = Application.writeAllLinesExample();
|
||||
|
||||
assertThat(contents.split(NEW_LINE))
|
||||
.containsExactly(
|
||||
|
Loading…
x
Reference in New Issue
Block a user