Merge branch 'masterupstream' into tutorials/jerseyFiltersInterceptors

This commit is contained in:
Marcos Lopez Gonzalez 2018-02-26 22:47:43 +01:00
commit 5cbfd34be3
5 changed files with 212 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package com.baeldung.system;
import org.apache.commons.lang3.SystemUtils;
public class DetectOS {
public String getOperatingSystem() {
String os = System.getProperty("os.name");
System.out.println("Using System Property: " + os);
return os;
}
public String getOperatingSystemSystemUtils() {
String os = SystemUtils.OS_NAME;
System.out.println("Using SystemUtils: " + os);
return os;
}
}

View File

@ -0,0 +1,25 @@
package com.baeldung.system;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class WhenDetectingOSTest {
private DetectOS os = new DetectOS();
@Test
public void whenUsingSystemProperty_shouldReturnOS() {
String expected = "Windows 10";
String actual = os.getOperatingSystem();
Assert.assertEquals(expected, actual);
}
@Test
public void whenUsingSystemUtils_shouldReturnOS() {
String expected = "Windows 10";
String actual = os.getOperatingSystemSystemUtils();
Assert.assertEquals(expected, actual);
}
}

View File

@ -43,6 +43,14 @@
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,64 @@
package org.baeldung.hamcrest;
import static org.hamcrest.core.StringContains.containsString;
import static org.hamcrest.io.FileMatchers.aFileNamed;
import static org.hamcrest.io.FileMatchers.aFileWithAbsolutePath;
import static org.hamcrest.io.FileMatchers.aFileWithCanonicalPath;
import static org.hamcrest.io.FileMatchers.aFileWithSize;
import static org.hamcrest.io.FileMatchers.aReadableFile;
import static org.hamcrest.io.FileMatchers.aWritableFile;
import static org.hamcrest.io.FileMatchers.anExistingDirectory;
import static org.hamcrest.io.FileMatchers.anExistingFile;
import static org.hamcrest.io.FileMatchers.anExistingFileOrDirectory;
import static org.hamcrest.number.OrderingComparison.greaterThan;
import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
import static org.junit.Assert.assertThat;
import java.io.File;
import org.junit.Test;
public class HamcrestFileUnitTest {
@Test
public final void whenVerifyingFileName_thenCorrect() {
File file = new File("src/test/resources/test1.in");
assertThat(file, aFileNamed(equalToIgnoringCase("test1.in")));
}
@Test
public final void whenVerifyingFileOrDirExist_thenCorrect() {
File file = new File("src/test/resources/test1.in");
File dir = new File("src/test/resources");
assertThat(file, anExistingFile());
assertThat(dir, anExistingDirectory());
assertThat(file, anExistingFileOrDirectory());
assertThat(dir, anExistingFileOrDirectory());
}
@Test
public final void whenVerifyingFileIsReadableAndWritable_thenCorrect() {
File file = new File("src/test/resources/test1.in");
assertThat(file, aReadableFile());
assertThat(file, aWritableFile());
}
@Test
public final void whenVerifyingFileSize_thenCorrect() {
File file = new File("src/test/resources/test1.in");
assertThat(file, aFileWithSize(11));
assertThat(file, aFileWithSize(greaterThan(1L)));;
}
@Test
public final void whenVerifyingFilePath_thenCorrect() {
File file = new File("src/test/resources/test1.in");
assertThat(file, aFileWithCanonicalPath(containsString("src/test/resources")));
assertThat(file, aFileWithAbsolutePath(containsString("src/test/resources")));
}
}

View File

@ -0,0 +1,97 @@
package org.baeldung.hamcrest;
import static org.hamcrest.core.StringContains.containsString;
import static org.hamcrest.core.StringContains.containsStringIgnoringCase;
import static org.hamcrest.core.StringEndsWith.endsWith;
import static org.hamcrest.core.StringEndsWith.endsWithIgnoringCase;
import static org.hamcrest.core.StringStartsWith.startsWith;
import static org.hamcrest.core.StringStartsWith.startsWithIgnoringCase;
import static org.hamcrest.text.IsBlankString.blankOrNullString;
import static org.hamcrest.text.IsBlankString.blankString;
import static org.hamcrest.text.IsEmptyString.emptyOrNullString;
import static org.hamcrest.text.IsEmptyString.emptyString;
import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
import static org.hamcrest.text.IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace;
import static org.hamcrest.text.MatchesPattern.matchesPattern;
import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder;
import static org.junit.Assert.assertThat;
import org.junit.Test;
public class HamcrestTextUnitTest {
@Test
public final void whenTwoStringsAreEqual_thenCorrect() {
String first = "hello";
String second = "Hello";
assertThat(first, equalToIgnoringCase(second));
}
@Test
public final void whenTwoStringsAreEqualWithWhiteSpace_thenCorrect() {
String first = "hello";
String second = " Hello ";
assertThat(first, equalToIgnoringWhiteSpace(second));
}
@Test
public final void whenStringIsBlank_thenCorrect() {
String first = " ";
String second = null;
assertThat(first, blankString());
assertThat(first, blankOrNullString());
assertThat(second, blankOrNullString());
}
@Test
public final void whenStringIsEmpty_thenCorrect() {
String first = "";
String second = null;
assertThat(first, emptyString());
assertThat(first, emptyOrNullString());
assertThat(second, emptyOrNullString());
}
@Test
public final void whenStringMatchPattern_thenCorrect() {
String first = "hello";
assertThat(first, matchesPattern("[a-z]+"));
}
@Test
public final void whenVerifyStringContains_thenCorrect() {
String first = "hello";
assertThat(first, containsString("lo"));
assertThat(first, containsStringIgnoringCase("EL"));
}
@Test
public final void whenVerifyStringContainsInOrder_thenCorrect() {
String first = "hello";
assertThat(first, stringContainsInOrder("e","l","o"));
}
@Test
public final void whenVerifyStringStartsWith_thenCorrect() {
String first = "hello";
assertThat(first, startsWith("he"));
assertThat(first, startsWithIgnoringCase("HEL"));
}
@Test
public final void whenVerifyStringEndsWith_thenCorrect() {
String first = "hello";
assertThat(first, endsWith("lo"));
assertThat(first, endsWithIgnoringCase("LO"));
}
}