* commited initial code for hexagonal architecture

* Deleting to check in again

* Deleing to check in again

* Push first code for Hexagonal Architecture

* final code with UT for JSON to Java conversion

* removed hexagonal-architecture code from last commit

* BEL-5071 updated README

* BAEL-5071: Undo README changes and added a nested object in the JSON example.

* BAEL-5071: fixed whitespace/indentation in JsonToJavaClassConversion.java

* BAEL-5151: Added code for getting the first of a String

* BAEL-5151: Renamed Unit Test

* BAEL-5151: Moved the files from core-java-string-operations to core-java-string-operations-3

* BAEL-5151: Replaced tabs with white spaces.

Co-authored-by: Vaibhav Jain <vaibhav.ashokjain@vodafone.com>
This commit is contained in:
vaibhav007jain 2021-11-08 18:05:17 +05:30 committed by GitHub
parent d1cf3c02c1
commit 3ab032d095
2 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package com.baeldung.firstword;
public class FirstWordGetter {
public static void main(String[] args) {
String input = "Roberto \"I wish you a bug-free day\"";
System.out.println("Using split: " + getFirstWordUsingSplit(input));
System.out.println("Using subString: " + getFirstWordUsingSubString(input));
}
public static String getFirstWordUsingSubString(String input) {
int index = input.contains(" ") ? input.indexOf(" ") : 0;
return input.substring(0, index);
}
public static String getFirstWordUsingSplit(String input) {
String[] tokens = input.split(" ", 2);
return tokens[0];
}
}

View File

@ -0,0 +1,30 @@
package com.baeldung.firstword;
import static com.baeldung.firstword.FirstWordGetter.getFirstWordUsingSplit;
import static com.baeldung.firstword.FirstWordGetter.getFirstWordUsingSubString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class FirstWordGetterUnitTest {
@Test
public void givenString_whenSplit_thenFirstWordIsReturned() {
assertEquals("Roberto", getFirstWordUsingSplit("Roberto \"I wish you a bug-free day\""));
}
@Test
public void givenStringWithNoSpace_whenSplit_thenFirstWordIsReturned() {
assertEquals("StringWithNoSpace", getFirstWordUsingSplit("StringWithNoSpace"));
}
@Test
public void givenString_whenPassedToSubstring_thenFirstWordIsReturned() {
assertEquals("Roberto", getFirstWordUsingSubString("Roberto \"I wish you a bug-free day\""));
}
@Test
public void givenStringWithNoSpace_whenPassedToSubstring_thenFirstWordIsReturned() {
assertEquals("", getFirstWordUsingSubString("StringWithNoSpace"));
}
}