Update and merge
This commit is contained in:
commit
bc6d707976
@ -11,7 +11,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
/**
|
/**
|
||||||
* Tests which show issues with JGit that we reported upstream.
|
* Tests which show issues with JGit that we reported upstream.
|
||||||
*/
|
*/
|
||||||
public class JGitBugTest {
|
public class JGitBugIntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
public void testRevWalkDisposeClosesReader() throws IOException {
|
public void testRevWalkDisposeClosesReader() throws IOException {
|
||||||
try (Repository repo = Helper.openJGitRepository()) {
|
try (Repository repo = Helper.openJGitRepository()) {
|
@ -2,7 +2,7 @@ package com.baeldung.jgit.porcelain;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class PorcelainTest {
|
public class PorcelainUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void runSamples() throws Exception {
|
public void runSamples() throws Exception {
|
||||||
// simply call all the samples to see any severe problems with the samples
|
// simply call all the samples to see any severe problems with the samples
|
@ -9,7 +9,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import twitter4j.TwitterException;
|
import twitter4j.TwitterException;
|
||||||
|
|
||||||
public class ApplicationTest {
|
public class ApplicationIntegrationTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In order run this jUnit test you need to configure your API details in the twitter4j.properties
|
* In order run this jUnit test you need to configure your API details in the twitter4j.properties
|
@ -5,7 +5,7 @@ import org.junit.Test;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class PrimeCheckerTest {
|
public class PrimeCheckerUnitTest {
|
||||||
|
|
||||||
private final BigIntegerPrimeChecker primeChecker = new BigIntegerPrimeChecker();
|
private final BigIntegerPrimeChecker primeChecker = new BigIntegerPrimeChecker();
|
||||||
|
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -13,11 +12,6 @@
|
|||||||
|
|
||||||
<artifactId>annotation-user</artifactId>
|
<artifactId>annotation-user</artifactId>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -26,31 +20,6 @@
|
|||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
|
|
||||||
<plugins>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
</plugins>
|
|
||||||
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -4,7 +4,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class PersonBuilderTest {
|
public class PersonBuilderUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenBuildPersonWithBuilder_thenObjectHasPropertyValues() {
|
public void whenBuildPersonWithBuilder_thenObjectHasPropertyValues() {
|
@ -17,7 +17,7 @@ import static org.junit.Assert.*;
|
|||||||
|
|
||||||
import com.baeldung.model.User;
|
import com.baeldung.model.User;
|
||||||
|
|
||||||
public class ValidationTest {
|
public class ValidationIntegrationTest {
|
||||||
private static ValidatorFactory validatorFactory;
|
private static ValidatorFactory validatorFactory;
|
||||||
private static Validator validator;
|
private static Validator validator;
|
||||||
|
|
@ -26,7 +26,7 @@ import org.apache.cxf.aegis.AegisReader;
|
|||||||
import org.apache.cxf.aegis.AegisWriter;
|
import org.apache.cxf.aegis.AegisWriter;
|
||||||
import org.apache.cxf.aegis.type.AegisType;
|
import org.apache.cxf.aegis.type.AegisType;
|
||||||
|
|
||||||
public class BaeldungTest {
|
public class BaeldungIntegrationTest {
|
||||||
private AegisContext context;
|
private AegisContext context;
|
||||||
private String fileName = "baeldung.xml";
|
private String fileName = "baeldung.xml";
|
||||||
|
|
@ -14,38 +14,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- test scoped -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-core</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>${mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- new dependencies -->
|
<!-- new dependencies -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.xmlgraphics</groupId>
|
<groupId>org.apache.xmlgraphics</groupId>
|
||||||
<artifactId>fop</artifactId>
|
<artifactId>fop</artifactId>
|
||||||
@ -154,11 +123,6 @@
|
|||||||
<avalon-framework.version>4.3</avalon-framework.version>
|
<avalon-framework.version>4.3</avalon-framework.version>
|
||||||
<dbdoclet.version>8.0.2</dbdoclet.version>
|
<dbdoclet.version>8.0.2</dbdoclet.version>
|
||||||
<jtidy.version>r938</jtidy.version>
|
<jtidy.version>r938</jtidy.version>
|
||||||
|
|
||||||
<!-- testing -->
|
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
|
||||||
<mockito.version>1.10.19</mockito.version>
|
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -21,7 +21,7 @@ import org.junit.Test;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
|
||||||
public class JExcelTest {
|
public class JExcelIntegrationTest {
|
||||||
|
|
||||||
private JExcelHelper jExcelHelper;
|
private JExcelHelper jExcelHelper;
|
||||||
private static String FILE_NAME = "temp.xls";
|
private static String FILE_NAME = "temp.xls";
|
@ -18,7 +18,7 @@ import org.junit.Test;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
|
||||||
public class ExcelTest {
|
public class ExcelIntegrationTest {
|
||||||
|
|
||||||
private ExcelPOIHelper excelPOIHelper;
|
private ExcelPOIHelper excelPOIHelper;
|
||||||
private static String FILE_NAME = "temp.xlsx";
|
private static String FILE_NAME = "temp.xlsx";
|
@ -14,12 +14,12 @@ import org.apache.poi.xwpf.usermodel.XWPFRun;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class WordTest {
|
public class WordIntegrationTest {
|
||||||
static WordDocument wordDocument;
|
static WordDocument wordDocument;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void generateMSWordFile() throws Exception {
|
public static void generateMSWordFile() throws Exception {
|
||||||
WordTest.wordDocument = new WordDocument();
|
WordIntegrationTest.wordDocument = new WordDocument();
|
||||||
wordDocument.handleSimpleDoc();
|
wordDocument.handleSimpleDoc();
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,9 @@
|
|||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>generate-sources</phase>
|
<phase>generate-sources</phase>
|
||||||
<goals><goal>add-source</goal></goals>
|
<goals>
|
||||||
|
<goal>add-source</goal>
|
||||||
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sources>
|
<sources>
|
||||||
<source>generated</source>
|
<source>generated</source>
|
||||||
|
@ -6,7 +6,7 @@ import org.junit.Assert;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CrossPlatformServiceTest {
|
public class CrossPlatformServiceIntegrationTest {
|
||||||
|
|
||||||
private CrossPlatformServiceServer server = new CrossPlatformServiceServer();
|
private CrossPlatformServiceServer server = new CrossPlatformServiceServer();
|
||||||
|
|
@ -35,11 +35,6 @@
|
|||||||
<artifactId>velocity-tools</artifactId>
|
<artifactId>velocity-tools</artifactId>
|
||||||
<version>${velocity-tools-version}</version>
|
<version>${velocity-tools-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent-modules</artifactId>
|
<artifactId>parent-modules</artifactId>
|
||||||
|
@ -12,7 +12,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MessagesAggregateTest {
|
public class MessagesAggregateIntegrationTest {
|
||||||
|
|
||||||
private FixtureConfiguration<MessagesAggregate> fixture;
|
private FixtureConfiguration<MessagesAggregate> fixture;
|
||||||
|
|
@ -10,7 +10,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Java9OptionalsStreamTest {
|
public class Java9OptionalsStreamUnitTest {
|
||||||
|
|
||||||
private static List<Optional<String>> listOfOptionals = Arrays.asList(Optional.empty(), Optional.of("foo"), Optional.empty(), Optional.of("bar"));
|
private static List<Optional<String>> listOfOptionals = Arrays.asList(Optional.empty(), Optional.of("foo"), Optional.empty(), Optional.of("bar"));
|
||||||
|
|
@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class MultiResultionImageTest {
|
public class MultiResultionImageUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void baseMultiResImageTest() {
|
public void baseMultiResImageTest() {
|
@ -6,7 +6,7 @@ import java.util.stream.Stream;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class OptionalToStreamTest {
|
public class OptionalToStreamUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOptionalToStream() {
|
public void testOptionalToStream() {
|
@ -5,7 +5,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class SetExamplesTest {
|
public class SetExamplesUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmutableSet() {
|
public void testUnmutableSet() {
|
@ -9,7 +9,7 @@ import static org.junit.Assert.assertSame;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CompletableFutureTest {
|
public class CompletableFutureUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void testDelay () throws Exception {
|
public void testDelay () throws Exception {
|
||||||
Object input = new Object();
|
Object input = new Object();
|
@ -24,7 +24,7 @@ import javax.net.ssl.SSLParameters;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SimpleHttpRequestsTest {
|
public class SimpleHttpRequestsUnitTest {
|
||||||
|
|
||||||
private URI httpURI;
|
private URI httpURI;
|
||||||
|
|
@ -2,7 +2,7 @@ package com.baeldung.java9.language;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class DiamondTest {
|
public class DiamondUnitTest {
|
||||||
|
|
||||||
static class FooClass<X> {
|
static class FooClass<X> {
|
||||||
FooClass(X x) {
|
FooClass(X x) {
|
@ -3,7 +3,7 @@ package com.baeldung.java9.language;
|
|||||||
import com.baeldung.java9.language.PrivateInterface;
|
import com.baeldung.java9.language.PrivateInterface;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class PrivateInterfaceTest {
|
public class PrivateInterfaceUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
@ -3,7 +3,7 @@ package com.baeldung.java9.language;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TryWithResourcesTest {
|
public class TryWithResourcesUnitTest {
|
||||||
|
|
||||||
static int closeCount = 0;
|
static int closeCount = 0;
|
||||||
|
|
@ -9,7 +9,7 @@ import static org.junit.Assert.assertArrayEquals;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
public class ListFactoryMethodsTest {
|
public class ListFactoryMethodsUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenListCreated_thenSuccess() {
|
public void whenListCreated_thenSuccess() {
|
@ -8,7 +8,7 @@ import org.junit.Test;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
public class MapFactoryMethodsTest {
|
public class MapFactoryMethodsUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenMapCreated_thenSuccess() {
|
public void whenMapCreated_thenSuccess() {
|
@ -9,7 +9,7 @@ import static org.junit.Assert.assertArrayEquals;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
public class SetFactoryMethodsTest {
|
public class SetFactoryMethodsUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSetCreated_thenSuccess() {
|
public void whenSetCreated_thenSuccess() {
|
@ -8,7 +8,7 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class CollectorImprovementTest {
|
public class CollectorImprovementUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenList_whenSatifyPredicate_thenMapValueWithOccurences() {
|
public void givenList_whenSatifyPredicate_thenMapValueWithOccurences() {
|
||||||
List<Integer> numbers = List.of(1, 2, 3, 5, 5);
|
List<Integer> numbers = List.of(1, 2, 3, 5, 5);
|
@ -12,7 +12,7 @@ import java.util.stream.Stream;
|
|||||||
import static java.lang.Integer.*;
|
import static java.lang.Integer.*;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class StreamFeaturesTest {
|
public class StreamFeaturesUnitTest {
|
||||||
|
|
||||||
public static class TakeAndDropWhileTest {
|
public static class TakeAndDropWhileTest {
|
||||||
|
|
@ -16,7 +16,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
* Created by sanaulla on 2/23/2017.
|
* Created by sanaulla on 2/23/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ProcessAPIEnhancementsTest {
|
public class ProcessAPIEnhancementsUnitTest {
|
||||||
|
|
||||||
Logger log = LoggerFactory.getLogger(ProcessAPIEnhancementsTest.class);
|
Logger log = LoggerFactory.getLogger(ProcessAPIEnhancementsTest.class);
|
||||||
|
|
@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class ProcessApi {
|
public class ProcessApiUnitTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
@ -13,7 +13,7 @@ import org.junit.Rule;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.Stopwatch;
|
import org.junit.rules.Stopwatch;
|
||||||
|
|
||||||
public class BaeldungBatchSubscriberImplTest {
|
public class BaeldungBatchSubscriberImplIntegrationTest {
|
||||||
|
|
||||||
private static final int ITEM_SIZE = 10;
|
private static final int ITEM_SIZE = 10;
|
||||||
private SubmissionPublisher<String> publisher;
|
private SubmissionPublisher<String> publisher;
|
@ -13,7 +13,7 @@ import org.junit.Rule;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.Stopwatch;
|
import org.junit.rules.Stopwatch;
|
||||||
|
|
||||||
public class BaeldungSubscriberImplTest {
|
public class BaeldungSubscriberImplIntegrationTest {
|
||||||
|
|
||||||
private static final int ITEM_SIZE = 10;
|
private static final int ITEM_SIZE = 10;
|
||||||
private SubmissionPublisher<String> publisher;
|
private SubmissionPublisher<String> publisher;
|
@ -2,7 +2,7 @@ package com.baeldung.java9.stackwalker;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class StackWalkerDemoTest {
|
public class StackWalkerDemoUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void giveStalkWalker_whenWalkingTheStack_thenShowStackFrames() {
|
public void giveStalkWalker_whenWalkingTheStack_thenShowStackFrames() {
|
@ -101,3 +101,4 @@
|
|||||||
- [HashSet and TreeSet Comparison](http://www.baeldung.com/java-hashset-vs-treeset)
|
- [HashSet and TreeSet Comparison](http://www.baeldung.com/java-hashset-vs-treeset)
|
||||||
- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request)
|
- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request)
|
||||||
- [Call Methods at Runtime Using Java Reflection](http://www.baeldung.com/java-method-reflection)
|
- [Call Methods at Runtime Using Java Reflection](http://www.baeldung.com/java-method-reflection)
|
||||||
|
- [Guide to DelayQueue](http://www.baeldung.com/java-delay-queue)
|
||||||
|
@ -8,12 +8,6 @@
|
|||||||
|
|
||||||
<name>core-java</name>
|
<name>core-java</name>
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>parent-modules</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- utils -->
|
<!-- utils -->
|
||||||
@ -80,12 +74,29 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- logging -->
|
<!-- logging -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>${logback.version}</version>
|
||||||
|
<!-- <scope>runtime</scope> -->
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
<version>${org.slf4j.version}</version>
|
<version>${org.slf4j.version}</version>
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@ -93,13 +104,6 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- mysql -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
<version>${mysql.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -109,6 +113,13 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest-core</artifactId>
|
||||||
@ -153,28 +164,11 @@
|
|||||||
<artifactId>moneta</artifactId>
|
<artifactId>moneta</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.owasp.esapi</groupId>
|
|
||||||
<artifactId>esapi</artifactId>
|
|
||||||
<version>2.1.0.1</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.owasp.esapi</groupId>
|
<groupId>org.owasp.esapi</groupId>
|
||||||
<artifactId>esapi</artifactId>
|
<artifactId>esapi</artifactId>
|
||||||
<version>2.1.0.1</version>
|
<version>2.1.0.1</version>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -189,6 +183,30 @@
|
|||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
|
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||||
|
<exclude>**/*ManualTest.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
<testFailureIgnore>true</testFailureIgnore>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
@ -219,6 +237,7 @@
|
|||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
@ -242,6 +261,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
@ -262,6 +282,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.jolira</groupId>
|
<groupId>com.jolira</groupId>
|
||||||
<artifactId>onejar-maven-plugin</artifactId>
|
<artifactId>onejar-maven-plugin</artifactId>
|
||||||
@ -278,6 +299,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
@ -293,6 +315,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
</build>
|
</build>
|
||||||
@ -336,8 +359,9 @@
|
|||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
<jackson.version>2.8.5</jackson.version>
|
<jackson.version>2.8.5</jackson.version>
|
||||||
|
|
||||||
<!-- mysql -->
|
<!-- logging -->
|
||||||
<mysql.version>6.0.6</mysql.version>
|
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||||
|
<logback.version>1.1.7</logback.version>
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>21.0</guava.version>
|
<guava.version>21.0</guava.version>
|
||||||
@ -354,10 +378,15 @@
|
|||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||||
|
<junit.version>4.12</junit.version>
|
||||||
<mockito.version>1.10.19</mockito.version>
|
<mockito.version>1.10.19</mockito.version>
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
|
|
||||||
|
<!-- maven plugins -->
|
||||||
|
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||||
|
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.baeldung.concurrent.delayqueue;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Ints;
|
||||||
|
|
||||||
|
import java.util.concurrent.Delayed;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class DelayObject implements Delayed {
|
||||||
|
private String data;
|
||||||
|
private long startTime;
|
||||||
|
|
||||||
|
public DelayObject(String data, long delayInMilliseconds) {
|
||||||
|
this.data = data;
|
||||||
|
this.startTime = System.currentTimeMillis() + delayInMilliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getDelay(TimeUnit unit) {
|
||||||
|
long diff = startTime - System.currentTimeMillis();
|
||||||
|
return unit.convert(diff, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Delayed o) {
|
||||||
|
return Ints.saturatedCast(this.startTime - ((DelayObject) o).startTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{" +
|
||||||
|
"data='" + data + '\'' +
|
||||||
|
", startTime=" + startTime +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.baeldung.concurrent.delayqueue;
|
||||||
|
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
|
||||||
|
public class DelayQueueConsumer implements Runnable {
|
||||||
|
private BlockingQueue<DelayObject> queue;
|
||||||
|
private final Integer numberOfElementsToTake;
|
||||||
|
public final AtomicInteger numberOfConsumedElements = new AtomicInteger();
|
||||||
|
|
||||||
|
public DelayQueueConsumer(BlockingQueue<DelayObject> queue, Integer numberOfElementsToTake) {
|
||||||
|
this.queue = queue;
|
||||||
|
this.numberOfElementsToTake = numberOfElementsToTake;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (int i = 0; i < numberOfElementsToTake; i++) {
|
||||||
|
try {
|
||||||
|
DelayObject object = queue.take();
|
||||||
|
numberOfConsumedElements.incrementAndGet();
|
||||||
|
System.out.println("Consumer take: " + object);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.baeldung.concurrent.delayqueue;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
|
|
||||||
|
public class DelayQueueProducer implements Runnable {
|
||||||
|
private BlockingQueue<DelayObject> queue;
|
||||||
|
private final Integer numberOfElementsToProduce;
|
||||||
|
private final Integer delayOfEachProducedMessageMilliseconds;
|
||||||
|
|
||||||
|
public DelayQueueProducer(BlockingQueue<DelayObject> queue,
|
||||||
|
Integer numberOfElementsToProduce,
|
||||||
|
Integer delayOfEachProducedMessageMilliseconds) {
|
||||||
|
this.queue = queue;
|
||||||
|
this.numberOfElementsToProduce = numberOfElementsToProduce;
|
||||||
|
this.delayOfEachProducedMessageMilliseconds = delayOfEachProducedMessageMilliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (int i = 0; i < numberOfElementsToProduce; i++) {
|
||||||
|
DelayObject object
|
||||||
|
= new DelayObject(UUID.randomUUID().toString(), delayOfEachProducedMessageMilliseconds);
|
||||||
|
System.out.println("Put object = " + object);
|
||||||
|
try {
|
||||||
|
queue.put(object);
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.baeuldung.serialization;
|
||||||
|
|
||||||
|
public class Address {
|
||||||
|
|
||||||
|
private int houseNumber;
|
||||||
|
|
||||||
|
public int getHouseNumber() {
|
||||||
|
return houseNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHouseNumber(int houseNumber) {
|
||||||
|
this.houseNumber = houseNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package com.baeuldung.serialization;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Employee implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private transient Address address; // not an serializable object
|
||||||
|
private Person person;
|
||||||
|
|
||||||
|
public Address getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(Address address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person getPerson() {
|
||||||
|
return person;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPerson(Person person) {
|
||||||
|
this.person = person;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||||
|
oos.defaultWriteObject();
|
||||||
|
oos.writeObject(address.getHouseNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
|
||||||
|
ois.defaultReadObject();
|
||||||
|
Integer houseNumber = (Integer) ois.readObject();
|
||||||
|
Address a = new Address();
|
||||||
|
a.setHouseNumber(houseNumber);
|
||||||
|
this.setAddress(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.baeuldung.serialization;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Person implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private int age;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.baeldung.stackoverflowerror;
|
package com.baeldung.stackoverflowerror;
|
||||||
|
|
||||||
public class RecursionWithCorrectTerminationCondition {
|
public class RecursionWithCorrectTerminationCondition {
|
||||||
public static int calculateFactorial(final int number) {
|
public int calculateFactorial(final int number) {
|
||||||
return number <= 1 ? 1 : number * calculateFactorial(number - 1);
|
return number <= 1 ? 1 : number * calculateFactorial(number - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,10 @@ public class StringHelper {
|
|||||||
public static String removeLastCharRegexOptional(String s) {
|
public static String removeLastCharRegexOptional(String s) {
|
||||||
return Optional.ofNullable(s)
|
return Optional.ofNullable(s)
|
||||||
.map(str -> str.replaceAll(".$", ""))
|
.map(str -> str.replaceAll(".$", ""))
|
||||||
|
<<<<<<< HEAD
|
||||||
.orElse(s);
|
.orElse(s);
|
||||||
|
=======
|
||||||
|
.orElse(null);
|
||||||
|
>>>>>>> refs/remotes/eugenp/master
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
core-java/src/main/resources/datasource.properties
Normal file
6
core-java/src/main/resources/datasource.properties
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
dataSourceClassName=//TBD
|
||||||
|
dataSource.user=//TBD
|
||||||
|
dataSource.password=//TBD
|
||||||
|
dataSource.databaseName=//TBD
|
||||||
|
dataSource.portNumber=//TBD
|
||||||
|
dataSource.serverName=//TBD
|
@ -9,7 +9,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class ArrayCopyUtilTest {
|
public class ArrayCopyUtilUnitTest {
|
||||||
private static Employee[] employees;
|
private static Employee[] employees;
|
||||||
private static final int MAX = 2;
|
private static final int MAX = 2;
|
||||||
|
|
@ -11,7 +11,7 @@ import java.util.stream.IntStream;
|
|||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
|
||||||
public class LongAccumulatorTest {
|
public class LongAccumulatorUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenLongAccumulator_whenApplyActionOnItFromMultipleThrads_thenShouldProduceProperResult() throws InterruptedException {
|
public void givenLongAccumulator_whenApplyActionOnItFromMultipleThrads_thenShouldProduceProperResult() throws InterruptedException {
|
@ -11,7 +11,7 @@ import java.util.stream.IntStream;
|
|||||||
import static com.jayway.awaitility.Awaitility.await;
|
import static com.jayway.awaitility.Awaitility.await;
|
||||||
import static junit.framework.TestCase.assertEquals;
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
|
||||||
public class LongAdderTest {
|
public class LongAdderUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
|
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
|
||||||
//given
|
//given
|
@ -11,7 +11,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
|
||||||
public class CopyOnWriteArrayListTest {
|
public class CopyOnWriteArrayListUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCopyOnWriteList_whenIterateAndAddElementToUnderneathList_thenShouldNotChangeIterator() {
|
public void givenCopyOnWriteList_whenIterateAndAddElementToUnderneathList_thenShouldNotChangeIterator() {
|
@ -0,0 +1,78 @@
|
|||||||
|
package com.baeldung.concurrent.delayqueue;
|
||||||
|
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class DelayQueueIntegrationTest {
|
||||||
|
@Test
|
||||||
|
public void givenDelayQueue_whenProduceElement_thenShouldConsumeAfterGivenDelay() throws InterruptedException {
|
||||||
|
//given
|
||||||
|
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||||
|
BlockingQueue<DelayObject> queue = new DelayQueue<>();
|
||||||
|
int numberOfElementsToProduce = 2;
|
||||||
|
int delayOfEachProducedMessageMilliseconds = 500;
|
||||||
|
DelayQueueConsumer consumer = new DelayQueueConsumer(queue, numberOfElementsToProduce);
|
||||||
|
DelayQueueProducer producer
|
||||||
|
= new DelayQueueProducer(queue, numberOfElementsToProduce, delayOfEachProducedMessageMilliseconds);
|
||||||
|
|
||||||
|
//when
|
||||||
|
executor.submit(producer);
|
||||||
|
executor.submit(consumer);
|
||||||
|
|
||||||
|
//then
|
||||||
|
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||||
|
executor.shutdown();
|
||||||
|
assertEquals(consumer.numberOfConsumedElements.get(), numberOfElementsToProduce);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDelayQueue_whenProduceElementWithHugeDelay_thenConsumerWasNotAbleToConsumeMessageInGivenTime() throws InterruptedException {
|
||||||
|
//given
|
||||||
|
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||||
|
BlockingQueue<DelayObject> queue = new DelayQueue<>();
|
||||||
|
int numberOfElementsToProduce = 1;
|
||||||
|
int delayOfEachProducedMessageMilliseconds = 10_000;
|
||||||
|
DelayQueueConsumer consumer = new DelayQueueConsumer(queue, numberOfElementsToProduce);
|
||||||
|
DelayQueueProducer producer
|
||||||
|
= new DelayQueueProducer(queue, numberOfElementsToProduce, delayOfEachProducedMessageMilliseconds);
|
||||||
|
|
||||||
|
//when
|
||||||
|
executor.submit(producer);
|
||||||
|
executor.submit(consumer);
|
||||||
|
|
||||||
|
//then
|
||||||
|
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||||
|
executor.shutdown();
|
||||||
|
assertEquals(consumer.numberOfConsumedElements.get(), 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDelayQueue_whenProduceElementWithNegativeDelay_thenConsumeMessageImmediately() throws InterruptedException {
|
||||||
|
//given
|
||||||
|
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||||
|
BlockingQueue<DelayObject> queue = new DelayQueue<>();
|
||||||
|
int numberOfElementsToProduce = 1;
|
||||||
|
int delayOfEachProducedMessageMilliseconds = -10_000;
|
||||||
|
DelayQueueConsumer consumer = new DelayQueueConsumer(queue, numberOfElementsToProduce);
|
||||||
|
DelayQueueProducer producer
|
||||||
|
= new DelayQueueProducer(queue, numberOfElementsToProduce, delayOfEachProducedMessageMilliseconds);
|
||||||
|
|
||||||
|
//when
|
||||||
|
executor.submit(producer);
|
||||||
|
executor.submit(consumer);
|
||||||
|
|
||||||
|
//then
|
||||||
|
executor.awaitTermination(1, TimeUnit.SECONDS);
|
||||||
|
executor.shutdown();
|
||||||
|
assertEquals(consumer.numberOfConsumedElements.get(), 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -66,9 +66,7 @@ public class SharedObjectWithLockManualTest {
|
|||||||
|
|
||||||
private void executeThreads(SharedObjectWithLock object, int threadCount, ExecutorService service) {
|
private void executeThreads(SharedObjectWithLock object, int threadCount, ExecutorService service) {
|
||||||
for (int i = 0; i < threadCount; i++) {
|
for (int i = 0; i < threadCount; i++) {
|
||||||
service.execute(() -> {
|
service.execute(object::perform);
|
||||||
object.perform();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import java.util.concurrent.Phaser;
|
|||||||
import static junit.framework.TestCase.assertEquals;
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class PhaserTest {
|
public class PhaserUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPhaser_whenCoordinateWorksBetweenThreads_thenShouldCoordinateBetweenMultiplePhases() {
|
public void givenPhaser_whenCoordinateWorksBetweenThreads_thenShouldCoordinateBetweenMultiplePhases() {
|
@ -9,7 +9,7 @@ import java.time.temporal.ChronoUnit;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class JavaDurationTest {
|
public class JavaDurationUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test2() {
|
public void test2() {
|
@ -9,9 +9,9 @@ import java.time.Period;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
public class JavaPeriodTest {
|
public class JavaPeriodUnitTest {
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(JavaPeriodTest.class);
|
private static final Logger LOG = Logger.getLogger(JavaPeriodUnitTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenTestPeriod_thenOk() {
|
public void whenTestPeriod_thenOk() {
|
@ -9,18 +9,18 @@ import java.util.Map;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class DynamicProxyTest {
|
public class DynamicProxyIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenDynamicProxy_thenPutWorks() {
|
public void givenDynamicProxy_thenPutWorks() {
|
||||||
Map proxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyTest.class.getClassLoader(), new Class[] { Map.class }, new DynamicInvocationHandler());
|
Map proxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyIntegrationTest.class.getClassLoader(), new Class[] { Map.class }, new DynamicInvocationHandler());
|
||||||
|
|
||||||
proxyInstance.put("hello", "world");
|
proxyInstance.put("hello", "world");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenInlineDynamicProxy_thenGetWorksOtherMethodsDoNot() {
|
public void givenInlineDynamicProxy_thenGetWorksOtherMethodsDoNot() {
|
||||||
Map proxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyTest.class.getClassLoader(), new Class[] { Map.class }, (proxy, method, methodArgs) -> {
|
Map proxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyIntegrationTest.class.getClassLoader(), new Class[] { Map.class }, (proxy, method, methodArgs) -> {
|
||||||
|
|
||||||
if (method.getName().equals("get")) {
|
if (method.getName().equals("get")) {
|
||||||
return 42;
|
return 42;
|
||||||
@ -43,12 +43,12 @@ public class DynamicProxyTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTimingDynamicProxy_thenMethodInvokationsProduceTiming() {
|
public void givenTimingDynamicProxy_thenMethodInvokationsProduceTiming() {
|
||||||
Map mapProxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyTest.class.getClassLoader(), new Class[] { Map.class }, new TimingDynamicInvocationHandler(new HashMap<>()));
|
Map mapProxyInstance = (Map) Proxy.newProxyInstance(DynamicProxyIntegrationTest.class.getClassLoader(), new Class[] { Map.class }, new TimingDynamicInvocationHandler(new HashMap<>()));
|
||||||
|
|
||||||
mapProxyInstance.put("hello", "world");
|
mapProxyInstance.put("hello", "world");
|
||||||
assertEquals("world", mapProxyInstance.get("hello"));
|
assertEquals("world", mapProxyInstance.get("hello"));
|
||||||
|
|
||||||
CharSequence csProxyInstance = (CharSequence) Proxy.newProxyInstance(DynamicProxyTest.class.getClassLoader(), new Class[] { CharSequence.class }, new TimingDynamicInvocationHandler("Hello World"));
|
CharSequence csProxyInstance = (CharSequence) Proxy.newProxyInstance(DynamicProxyIntegrationTest.class.getClassLoader(), new Class[] { CharSequence.class }, new TimingDynamicInvocationHandler("Hello World"));
|
||||||
|
|
||||||
assertEquals('l', csProxyInstance.charAt(2));
|
assertEquals('l', csProxyInstance.charAt(2));
|
||||||
assertEquals(11, csProxyInstance.length());
|
assertEquals(11, csProxyInstance.length());
|
@ -14,8 +14,7 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
public class FileOperationsManualTest {
|
||||||
public class FileOperationsUnitTest {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenFileName_whenUsingClassloader_thenFileData() throws IOException {
|
public void givenFileName_whenUsingClassloader_thenFileData() throws IOException {
|
||||||
@ -33,7 +32,7 @@ public class FileOperationsUnitTest {
|
|||||||
public void givenFileNameAsAbsolutePath_whenUsingClasspath_thenFileData() throws IOException {
|
public void givenFileNameAsAbsolutePath_whenUsingClasspath_thenFileData() throws IOException {
|
||||||
String expectedData = "Hello World from fileTest.txt!!!";
|
String expectedData = "Hello World from fileTest.txt!!!";
|
||||||
|
|
||||||
Class clazz = FileOperationsUnitTest.class;
|
Class clazz = FileOperationsManualTest.class;
|
||||||
InputStream inputStream = clazz.getResourceAsStream("/fileTest.txt");
|
InputStream inputStream = clazz.getResourceAsStream("/fileTest.txt");
|
||||||
String data = readFromInputStream(inputStream);
|
String data = readFromInputStream(inputStream);
|
||||||
|
|
@ -9,7 +9,7 @@ import static org.hamcrest.CoreMatchers.hasItems;
|
|||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class GenericsTest {
|
public class GenericsUnitTest {
|
||||||
|
|
||||||
// testing the generic method with Integer
|
// testing the generic method with Integer
|
||||||
@Test
|
@Test
|
@ -12,7 +12,7 @@ import org.unix4j.line.Line;
|
|||||||
import static org.unix4j.unix.Grep.*;
|
import static org.unix4j.unix.Grep.*;
|
||||||
import static org.unix4j.unix.cut.CutOption.*;
|
import static org.unix4j.unix.cut.CutOption.*;
|
||||||
|
|
||||||
public class GrepWithUnix4JTest {
|
public class GrepWithUnix4JIntegrationTest {
|
||||||
|
|
||||||
private File fileToGrep;
|
private File fileToGrep;
|
||||||
|
|
@ -9,7 +9,7 @@ import com.google.common.collect.EnumHashBiMap;
|
|||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.google.common.collect.ImmutableBiMap;
|
import com.google.common.collect.ImmutableBiMap;
|
||||||
|
|
||||||
public class GuavaBiMapTest {
|
public class GuavaBiMapUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenQueryByValue_returnsKey() {
|
public void whenQueryByValue_returnsKey() {
|
||||||
final BiMap<String, String> capitalCountryBiMap = HashBiMap.create();
|
final BiMap<String, String> capitalCountryBiMap = HashBiMap.create();
|
@ -4,7 +4,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SHA256HashingTest {
|
public class SHA256HashingUnitTest {
|
||||||
|
|
||||||
private static String originalValue = "abc123";
|
private static String originalValue = "abc123";
|
||||||
private static String hashedValue = "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090";
|
private static String hashedValue = "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090";
|
@ -1,13 +1,13 @@
|
|||||||
package com.baeldung.hexToAscii;
|
package com.baeldung.hexToAscii;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class HexToAscii {
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class HexToAsciiUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public static void whenHexToAscii() {
|
public void whenHexToAscii() {
|
||||||
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
|
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
|
||||||
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
|
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ public class HexToAscii {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public static void whenAsciiToHex() {
|
public void whenAsciiToHex() {
|
||||||
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
|
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
|
||||||
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
|
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
|
||||||
|
|
@ -17,7 +17,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class HttpRequestTest {
|
public class HttpRequestLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenGetRequest_thenOk() throws IOException {
|
public void whenGetRequest_thenOk() throws IOException {
|
@ -8,7 +8,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class ConcurrentModificationExceptionTest {
|
public class ConcurrentModificationExceptionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void changingContentWithSetDoesNotThrowConcurrentModificationException() throws Exception {
|
public void changingContentWithSetDoesNotThrowConcurrentModificationException() throws Exception {
|
@ -12,7 +12,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class ConcurrentNavigableMapManualTests {
|
public class ConcurrentNavigableMapManualTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSkipListMap_whenAccessInMultiThreads_thenOrderingStable() throws InterruptedException {
|
public void givenSkipListMap_whenAccessInMultiThreads_thenOrderingStable() throws InterruptedException {
|
@ -11,7 +11,7 @@ import java.util.stream.StreamSupport;
|
|||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
||||||
|
|
||||||
public class IterableStreamConversionTest {
|
public class IterableStreamConversionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenIterable_whenConvertedToStream_thenNotNull() {
|
public void givenIterable_whenConvertedToStream_thenNotNull() {
|
@ -15,7 +15,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import com.baeldung.datetime.UseLocalDateTime;
|
import com.baeldung.datetime.UseLocalDateTime;
|
||||||
|
|
||||||
public class StringConversionTest {
|
public class StringConversionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenConvertedToInt_thenCorrect() {
|
public void whenConvertedToInt_thenCorrect() {
|
@ -0,0 +1,93 @@
|
|||||||
|
package com.baeldung.java.countingChars;
|
||||||
|
|
||||||
|
import com.google.common.base.CharMatcher;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Example of counting chars in a String.
|
||||||
|
*/
|
||||||
|
public class CountCharsExampleUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenUsingLoop_thenCountChars() {
|
||||||
|
String someString = "elephant";
|
||||||
|
char someChar = 'e';
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < someString.length(); i++) {
|
||||||
|
if (someString.charAt(i) == someChar) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(2, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenUsingReplace_thenCountChars() {
|
||||||
|
String someString = "elephant";
|
||||||
|
int count = someString.length() - someString.replace("e", "").length();
|
||||||
|
assertEquals(2, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenUsingSplit_thenCountChars() {
|
||||||
|
String someString = "elephant";
|
||||||
|
int count = someString.split("e", -1).length - 1;
|
||||||
|
assertEquals(2, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenUsingReqExp_thenCountChars() {
|
||||||
|
Pattern pattern = Pattern.compile("[^e]*e");
|
||||||
|
Matcher matcher = pattern.matcher("elephant");
|
||||||
|
int count = 0;
|
||||||
|
while (matcher.find()) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
assertEquals(2, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenUsingRecursion_thenCountChars() {
|
||||||
|
int count = useRecursion("elephant", 'e', 0);
|
||||||
|
assertEquals(2, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int useRecursion(String someString, char searchedChar, int index) {
|
||||||
|
if (index >= someString.length()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = someString.charAt(index) == searchedChar ? 1 : 0;
|
||||||
|
return count + useRecursion(someString, searchedChar, index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenUsingStringUtils_thenCountChars() throws InterruptedException {
|
||||||
|
int count = StringUtils.countMatches("elephant", "e");
|
||||||
|
assertEquals(2, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenUsingJava8Features_thenCountChars() {
|
||||||
|
String someString = "elephant";
|
||||||
|
long count = someString.chars().filter(ch -> ch == 'e').count();
|
||||||
|
assertEquals(2, count);
|
||||||
|
|
||||||
|
long count2 = someString.codePoints().filter(ch -> ch == 'e').count();
|
||||||
|
assertEquals(2, count2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenUsingGuavaCharMatcher_thenCountChars() {
|
||||||
|
int count = CharMatcher.is('e').countIn("elephant");
|
||||||
|
assertEquals(2, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,7 +11,7 @@ import static java.util.stream.Collectors.collectingAndThen;
|
|||||||
import static java.util.stream.Collectors.toSet;
|
import static java.util.stream.Collectors.toSet;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class DoubleBraceTest {
|
public class DoubleBraceUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInitializeSetWithoutDoubleBraces_containsElements() {
|
public void whenInitializeSetWithoutDoubleBraces_containsElements() {
|
@ -9,8 +9,8 @@ import java.util.Map.Entry;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class MapTest {
|
public class MapUnitTest {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MapTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(MapUnitTest.class);
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class FileTest {
|
public class FileIntegrationTest {
|
||||||
private static final String TEMP_DIR = String.format("%s/temp%s", System.getProperty("user.home"), UUID.randomUUID().toString());
|
private static final String TEMP_DIR = String.format("%s/temp%s", System.getProperty("user.home"), UUID.randomUUID().toString());
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
@ -8,7 +8,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class AsyncEchoTest {
|
public class AsyncEchoIntegrationTest {
|
||||||
|
|
||||||
Process server;
|
Process server;
|
||||||
AsyncEchoClient client;
|
AsyncEchoClient client;
|
@ -16,7 +16,7 @@ import java.util.concurrent.Future;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class AsyncFileTest {
|
public class AsyncFileIntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenPath_whenReadsContentWithFuture_thenCorrect() throws IOException, ExecutionException, InterruptedException {
|
public void givenPath_whenReadsContentWithFuture_thenCorrect() throws IOException, ExecutionException, InterruptedException {
|
||||||
Path path = Paths.get(URI.create(this.getClass().getClassLoader().getResource("file.txt").toString()));
|
Path path = Paths.get(URI.create(this.getClass().getClassLoader().getResource("file.txt").toString()));
|
||||||
@ -36,7 +36,7 @@ public class AsyncFileTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPath_whenReadsContentWithCompletionHandler_thenCorrect() throws IOException {
|
public void givenPath_whenReadsContentWithCompletionHandler_thenCorrect() throws IOException {
|
||||||
Path path = Paths.get(URI.create(AsyncFileTest.class.getResource("/file.txt").toString()));
|
Path path = Paths.get(URI.create(AsyncFileIntegrationTest.class.getResource("/file.txt").toString()));
|
||||||
AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ);
|
AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ);
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
@ -16,9 +16,9 @@ import java.nio.file.attribute.FileTime;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class BasicAttribsTest {
|
public class BasicAttribsIntegrationTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BasicAttribsTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BasicAttribsIntegrationTest.class);
|
||||||
|
|
||||||
|
|
||||||
private static final String HOME = System.getProperty("user.home");
|
private static final String HOME = System.getProperty("user.home");
|
@ -9,9 +9,9 @@ import java.util.*;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class SetTest {
|
public class SetUnitTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(SetTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(SetUnitTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTreeSet_whenRetrievesObjects_thenNaturalOrder() {
|
public void givenTreeSet_whenRetrievesObjects_thenNaturalOrder() {
|
@ -11,7 +11,7 @@ import static org.hamcrest.Matchers.is;
|
|||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class Java8FindAnyFindFirstTest {
|
public class Java8FindAnyFindFirstUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createStream_whenFindAnyResultIsPresent_thenCorrect() {
|
public void createStream_whenFindAnyResultIsPresent_thenCorrect() {
|
@ -8,9 +8,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class Java8ForEachTest {
|
public class Java8ForEachUnitTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Java8ForEachTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Java8ForEachUnitTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareForEachMethods_thenPrintResults() {
|
public void compareForEachMethods_thenPrintResults() {
|
@ -10,7 +10,7 @@ import java.util.NoSuchElementException;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class Java8MaxMinTest {
|
public class Java8MaxMinUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenListIsOfIntegerThenMaxCanBeDoneUsingIntegerComparator() {
|
public void whenListIsOfIntegerThenMaxCanBeDoneUsingIntegerComparator() {
|
@ -8,7 +8,7 @@ import org.junit.Test;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class Java8ComparatorTest {
|
public class Java8ComparatorUnitTest {
|
||||||
|
|
||||||
private Employee[] employees;
|
private Employee[] employees;
|
||||||
private Employee[] employeesArrayWithNulls;
|
private Employee[] employeesArrayWithNulls;
|
@ -11,9 +11,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import static com.baeldung.java8.lambda.exceptions.LambdaExceptionWrappers.*;
|
import static com.baeldung.java8.lambda.exceptions.LambdaExceptionWrappers.*;
|
||||||
|
|
||||||
public class LambdaExceptionWrappersTest {
|
public class LambdaExceptionWrappersUnitTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(LambdaExceptionWrappersTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(LambdaExceptionWrappersUnitTest.class);
|
||||||
|
|
||||||
|
|
||||||
private List<Integer> integers;
|
private List<Integer> integers;
|
@ -13,9 +13,9 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class OptionalTest {
|
public class OptionalUnitTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(OptionalTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(OptionalUnitTest.class);
|
||||||
|
|
||||||
|
|
||||||
// creating Optional
|
// creating Optional
|
@ -21,9 +21,9 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class JdbcTest {
|
public class JdbcIntegrationTest {
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(JdbcTest.class);
|
private static final Logger LOG = Logger.getLogger(JdbcIntegrationTest.class);
|
||||||
|
|
||||||
private Connection con;
|
private Connection con;
|
||||||
|
|
@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class DivisibilityTest {
|
public class DivisibilityUnitTest {
|
||||||
|
|
||||||
private static int number;
|
private static int number;
|
||||||
|
|
@ -11,12 +11,12 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@RunWith(value = Parameterized.class)
|
@RunWith(value = Parameterized.class)
|
||||||
public class ParametrizedTests {
|
public class ParametrizedUnitTest {
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
private boolean isEven;
|
private boolean isEven;
|
||||||
|
|
||||||
public ParametrizedTests(int value, boolean isEven) {
|
public ParametrizedUnitTest(int value, boolean isEven) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.isEven = isEven;
|
this.isEven = isEven;
|
||||||
}
|
}
|
@ -5,8 +5,8 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
public class RegistrationTest {
|
public class RegistrationUnitTest {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationTest.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationUnitTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledFromSuite_thanOK() {
|
public void whenCalledFromSuite_thanOK() {
|
@ -4,8 +4,8 @@ import org.junit.Test;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class SignInTest {
|
public class SignInUnitTest {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SignInTest.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(SignInUnitTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledFromSuite_thanOK() {
|
public void whenCalledFromSuite_thanOK() {
|
@ -7,7 +7,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class SortedTests {
|
public class SortedUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void a_givenString_whenChangedtoInt_thenTrue() {
|
public void a_givenString_whenChangedtoInt_thenTrue() {
|
@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class StringCaseTest {
|
public class StringCaseUnitTest {
|
||||||
|
|
||||||
private static String data;
|
private static String data;
|
||||||
|
|
@ -4,7 +4,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.junit.runners.Suite;
|
import org.junit.runners.Suite;
|
||||||
|
|
||||||
@RunWith(Suite.class)
|
@RunWith(Suite.class)
|
||||||
@Suite.SuiteClasses({ RegistrationTest.class, SignInTest.class })
|
@Suite.SuiteClasses({ RegistrationUnitTest.class, SignInUnitTest.class })
|
||||||
public class SuiteTest {
|
public class SuiteTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import org.junit.Test;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SummationServiceTest {
|
public class SummationServiceIntegrationTest {
|
||||||
private static List<Integer> numbers;
|
private static List<Integer> numbers;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
@ -13,7 +13,7 @@ import java.util.stream.Collectors;
|
|||||||
import org.hamcrest.collection.IsIterableContainingInOrder;
|
import org.hamcrest.collection.IsIterableContainingInOrder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class FlattenNestedListTest {
|
public class FlattenNestedListUnitTest {
|
||||||
List<List<String>> lol = asList(asList("one:one"), asList("two:one", "two:two", "two:three"), asList("three:one", "three:two", "three:three", "three:four"));
|
List<List<String>> lol = asList(asList("one:one"), asList("two:one", "two:two", "two:three"), asList("three:one", "three:two", "three:three", "three:four"));
|
||||||
|
|
||||||
@Test
|
@Test
|
@ -7,7 +7,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ListOfListsTest {
|
public class ListOfListsUnitTest {
|
||||||
|
|
||||||
private List<ArrayList<? extends Stationery>> listOfLists = new ArrayList<ArrayList<? extends Stationery>>();
|
private List<ArrayList<? extends Stationery>> listOfLists = new ArrayList<ArrayList<? extends Stationery>>();
|
||||||
private ArrayList<Pen> penList = new ArrayList<>();
|
private ArrayList<Pen> penList = new ArrayList<>();
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
public class MappedByteBufferTest {
|
public class MappedByteBufferUnitTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
@ -21,7 +21,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class JavaMoneyTest {
|
public class JavaMoneyUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCurrencyCode_whenString_thanExist() {
|
public void givenCurrencyCode_whenString_thanExist() {
|
@ -9,7 +9,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class NashornTest {
|
public class NashornUnitTest {
|
||||||
|
|
||||||
private ScriptEngine engine;
|
private ScriptEngine engine;
|
||||||
|
|
||||||
@ -20,17 +20,17 @@ public class NashornTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void trim() throws ScriptException {
|
public void trim() throws ScriptException {
|
||||||
engine.eval(new InputStreamReader(NashornTest.class.getResourceAsStream("/js/trim.js")));
|
engine.eval(new InputStreamReader(NashornUnitTest.class.getResourceAsStream("/js/trim.js")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void locations() throws ScriptException {
|
public void locations() throws ScriptException {
|
||||||
engine.eval(new InputStreamReader(NashornTest.class.getResourceAsStream("/js/locations.js")));
|
engine.eval(new InputStreamReader(NashornUnitTest.class.getResourceAsStream("/js/locations.js")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindProperties() throws ScriptException {
|
public void bindProperties() throws ScriptException {
|
||||||
engine.eval(new InputStreamReader(NashornTest.class.getResourceAsStream("/js/bind.js")));
|
engine.eval(new InputStreamReader(NashornUnitTest.class.getResourceAsStream("/js/bind.js")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -40,7 +40,7 @@ public class NashornTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void typedArrays() throws ScriptException {
|
public void typedArrays() throws ScriptException {
|
||||||
engine.eval(new InputStreamReader(NashornTest.class.getResourceAsStream("/js/typed_arrays.js")));
|
engine.eval(new InputStreamReader(NashornUnitTest.class.getResourceAsStream("/js/typed_arrays.js")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.baeuldung.serialization;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class PersonUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSerializingAndDeserializing_ThenObjectIsTheSame() throws IOException, ClassNotFoundException {
|
||||||
|
Person p = new Person();
|
||||||
|
p.setAge(20);
|
||||||
|
p.setName("Joe");
|
||||||
|
|
||||||
|
FileOutputStream fileOutputStream = new FileOutputStream("yofile.txt");
|
||||||
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
||||||
|
objectOutputStream.writeObject(p);
|
||||||
|
objectOutputStream.flush();
|
||||||
|
objectOutputStream.close();
|
||||||
|
|
||||||
|
FileInputStream fileInputStream = new FileInputStream("yofile.txt");
|
||||||
|
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
||||||
|
Person p2 = (Person) objectInputStream.readObject();
|
||||||
|
objectInputStream.close();
|
||||||
|
|
||||||
|
assertTrue(p2.getAge() == p.getAge());
|
||||||
|
assertTrue(p2.getName().equals(p.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCustomSerializingAndDeserializing_ThenObjectIsTheSame() throws IOException, ClassNotFoundException {
|
||||||
|
Person p = new Person();
|
||||||
|
p.setAge(20);
|
||||||
|
p.setName("Joe");
|
||||||
|
|
||||||
|
Address a = new Address();
|
||||||
|
a.setHouseNumber(1);
|
||||||
|
|
||||||
|
Employee e = new Employee();
|
||||||
|
e.setPerson(p);
|
||||||
|
e.setAddress(a);
|
||||||
|
|
||||||
|
FileOutputStream fileOutputStream = new FileOutputStream("yofile2.txt");
|
||||||
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
||||||
|
objectOutputStream.writeObject(e);
|
||||||
|
objectOutputStream.flush();
|
||||||
|
objectOutputStream.close();
|
||||||
|
|
||||||
|
FileInputStream fileInputStream = new FileInputStream("yofile2.txt");
|
||||||
|
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
||||||
|
Employee e2 = (Employee) objectInputStream.readObject();
|
||||||
|
objectInputStream.close();
|
||||||
|
|
||||||
|
assertTrue(e2.getPerson().getAge() == e.getPerson().getAge());
|
||||||
|
assertTrue(e2.getAddress().getHouseNumber() == (e.getAddress().getHouseNumber()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,13 +4,8 @@ import static org.junit.Assert.fail;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CyclicDependancyManualTest {
|
public class CyclicDependancyManualTest {
|
||||||
@Test
|
@Test(expected = StackOverflowError.class)
|
||||||
public void whenInstanciatingClassOne_thenThrowsException() {
|
public void whenInstanciatingClassOne_thenThrowsException() {
|
||||||
try {
|
|
||||||
ClassOne obj = new ClassOne();
|
ClassOne obj = new ClassOne();
|
||||||
fail();
|
|
||||||
} catch (StackOverflowError soe) {
|
|
||||||
soe.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class InfiniteRecursionWithTerminationConditionManualTest {
|
public class InfiniteRecursionWithTerminationConditionManualTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenPositiveIntNoOne_whenCalcFact_thenThrowsException() {
|
public void givenPositiveIntNoOne_whenCalcFact_thenCorrectlyCalc() {
|
||||||
int numToCalcFactorial = 1;
|
int numToCalcFactorial = 1;
|
||||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||||
|
|
||||||
@ -14,23 +14,18 @@ public class InfiniteRecursionWithTerminationConditionManualTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
|
public void givenPositiveIntGtOne_whenCalcFact_thenCorrectlyCalc() {
|
||||||
int numToCalcFactorial = 5;
|
int numToCalcFactorial = 5;
|
||||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||||
|
|
||||||
assertEquals(120, irtc.calculateFactorial(numToCalcFactorial));
|
assertEquals(120, irtc.calculateFactorial(numToCalcFactorial));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = StackOverflowError.class)
|
||||||
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
|
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
|
||||||
try {
|
|
||||||
int numToCalcFactorial = -1;
|
int numToCalcFactorial = -1;
|
||||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||||
|
|
||||||
irtc.calculateFactorial(numToCalcFactorial);
|
irtc.calculateFactorial(numToCalcFactorial);
|
||||||
fail();
|
|
||||||
} catch (StackOverflowError soe) {
|
|
||||||
soe.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.baeldung.stackoverflowerror;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class RecursionWithCorrectTerminationConditionManualTest {
|
||||||
|
@Test
|
||||||
|
public void givenNegativeInt_whenCalcFact_thenCorrectlyCalc() {
|
||||||
|
int numToCalcFactorial = -1;
|
||||||
|
RecursionWithCorrectTerminationCondition rctc = new RecursionWithCorrectTerminationCondition();
|
||||||
|
|
||||||
|
assertEquals(1, rctc.calculateFactorial(numToCalcFactorial));
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user