Merge branch 'master' of github.com:eugenp/tutorials

This commit is contained in:
Nick
2019-12-08 10:33:08 +00:00
7101 changed files with 78776 additions and 194853 deletions
@@ -1,26 +0,0 @@
package com.baeldung.string.equalsIgnoreCase;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class StringEqualsIgnoreCaseUnitTest {
private String string1 = "equals ignore case";
private String string2 = "EQUALS IGNORE CASE";
@Test
public void givenEqualStringsWithDifferentCase_whenUsingEqualsIgnoreCase_ThenTheyAreEqual() {
assertThat(string1.equalsIgnoreCase(string2)).isTrue();
}
@Test
public void givenEqualStringsWithDifferentCase_whenUsingApacheCommonsEqualsIgnoreCase_ThenTheyAreEqual() {
assertThat(StringUtils.equalsIgnoreCase(string1, string2)).isTrue();
}
@Test
public void givenAStringAndNullValue_whenUsingApacheCommonsEqualsIgnoreCase_ThenTheyAreNotEqual() {
assertThat(StringUtils.equalsIgnoreCase(string1, null)).isFalse();
}
}
@@ -1,56 +0,0 @@
package com.baeldung.string.todouble;
import static org.junit.Assert.assertEquals;
import java.text.DecimalFormat;
import java.text.ParseException;
import org.junit.Test;
public class StringToDoubleConversionUnitTest {
@Test
public void givenValidString_WhenParseDouble_ThenResultIsPrimitiveDouble() {
assertEquals(1.23, Double.parseDouble("1.23"), 0.000001);
}
@Test(expected = NullPointerException.class)
public void givenNullString_WhenParseDouble_ThenNullPointerExceptionIsThrown() {
Double.parseDouble(null);
}
@Test(expected = NumberFormatException.class)
public void givenInalidString_WhenParseDouble_ThenNumberFormatExceptionIsThrown() {
Double.parseDouble("&");
}
@Test
public void givenValidString_WhenValueOf_ThenResultIsPrimitiveDouble() {
assertEquals(1.23, Double.valueOf("1.23"), 0.000001);
}
@Test(expected = NullPointerException.class)
public void givenNullString_WhenValueOf_ThenNullPointerExceptionIsThrown() {
Double.valueOf(null);
}
@Test(expected = NumberFormatException.class)
public void givenInalidString_WhenValueOf_ThenNumberFormatExceptionIsThrown() {
Double.valueOf("&");
}
@Test
public void givenValidString_WhenDecimalFormat_ThenResultIsValidDouble() throws ParseException {
assertEquals(1.23, new DecimalFormat("#").parse("1.23").doubleValue(), 0.000001);
}
@Test(expected = NullPointerException.class)
public void givenNullString_WhenDecimalFormat_ThenNullPointerExceptionIsThrown() throws ParseException {
new DecimalFormat("#").parse(null);
}
@Test(expected = ParseException.class)
public void givenInvalidString_WhenDecimalFormat_ThenParseExceptionIsThrown() throws ParseException {
new DecimalFormat("#").parse("&");
}
}
@@ -1,35 +0,0 @@
package com.baeldung.string.wordcount;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.util.StringTokenizer;
public class WordCountUnitTest {
private String string1 = "This is a test sentence with eight words";
private String string2 = "This#is%a test sentence with eight words";
@Test
public void givenStringWith8Words_whenUsingRegexCount_ThenResultEqual8() {
assertEquals(8, WordCounter.countWordsUsingRegex(string2));
assertEquals(9, WordCounter.countWordsUsingRegex("no&one#should%ever-write-like,this;but:well"));
assertEquals(7, WordCounter.countWordsUsingRegex("the farmer's wife--she was from Albuquerque"));
}
@Test
public void givenStringWith8Words_whenUsingManualMethod_ThenWordCountEqual8() {
assertEquals(8, WordCounter.countWordsManually(string1));
assertEquals(9, WordCounter.countWordsManually("no&one#should%ever-write-like,this but well"));
assertEquals(7, WordCounter.countWordsManually("the farmer's wife--she was from Albuquerque"));
}
@Test
public void givenAStringWith8Words_whenUsingTokenizer_ThenWordCountEqual8() {
assertEquals(8, WordCounter.countWordsUsingTokenizer(string1));
assertEquals(3, new StringTokenizer("three blind mice").countTokens());
assertEquals(4, new StringTokenizer("see\thow\tthey\trun").countTokens());
assertEquals(7, new StringTokenizer("the farmer's wife--she was from Albuquerque", " -").countTokens());
assertEquals(10, new StringTokenizer("did,you,ever,see,such,a,sight,in,your,life", ",").countTokens());
}
}