Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,11 @@
package com.baeldung.exceptions.classnotfoundexception;
import org.junit.Test;
public class ClassNotFoundExceptionUnitTest {
@Test(expected = ClassNotFoundException.class)
public void givenNoDriversInClassPath_whenLoadDrivers_thenClassNotFoundException() throws ClassNotFoundException {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
}
@@ -0,0 +1,29 @@
package com.baeldung.exceptions.customexception;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import org.junit.Test;
public class IncorrectFileExtensionExceptionUnitTest {
@Test
public void testWhenCorrectFileExtensionGiven_ReceivesNoException() throws IncorrectFileNameException {
assertThat(FileManager.getFirstLine("correctFileNameWithProperExtension.txt")).isEqualTo("Default First Line");
}
@Test(expected = IncorrectFileExtensionException.class)
public void testWhenCorrectFileNameExceptionThrown_ReceivesNoException() throws IncorrectFileNameException {
StringBuffer sBuffer = new StringBuffer();
sBuffer.append("src");
sBuffer.append(File.separator);
sBuffer.append("test");
sBuffer.append(File.separator);
sBuffer.append("resources");
sBuffer.append(File.separator);
sBuffer.append("correctFileNameWithoutProperExtension");
FileManager.getFirstLine(sBuffer.toString());
}
}
@@ -0,0 +1,19 @@
package com.baeldung.exceptions.customexception;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class IncorrectFileNameExceptionUnitTest {
@Test(expected = IncorrectFileNameException.class)
public void testWhenIncorrectFileNameExceptionThrown_ReceivesIncorrectFileNameException() throws IncorrectFileNameException {
FileManager.getFirstLine("wrongFileName.txt");
}
@Test
public void testWhenCorrectFileNameExceptionThrown_ReceivesNoException() throws IncorrectFileNameException {
assertThat(FileManager.getFirstLine("correctFileName.txt")).isEqualTo("Default First Line");
}
}
@@ -0,0 +1,80 @@
package com.baeldung.exceptions.exceptionhandling;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
public class ExceptionsUnitTest {
Exceptions exceptions = new Exceptions();
@Test
public void getPlayers() {
assertThatThrownBy(() -> exceptions.getPlayers())
.isInstanceOf(NoSuchFileException.class);
}
@Test
public void loadAllPlayers() {
assertThatThrownBy(() -> exceptions.loadAllPlayers(""))
.isInstanceOf(IllegalStateException.class);
}
@Test
public void getPlayerScoreThrows() {
assertThatThrownBy(() -> exceptions.getPlayerScoreThrows(""))
.isInstanceOf(FileNotFoundException.class);
}
@Test
public void getPlayerScoreTryCatch() {
assertThatThrownBy(() -> exceptions.getPlayerScoreTryCatch(""))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
public void getPlayerScoreFinally() {
assertThatThrownBy(() -> exceptions.getPlayerScoreFinally(""))
.isInstanceOf(FileNotFoundException.class);
}
@Test
public void loadAllPlayersThrowingChecked() {
assertThatThrownBy(() -> exceptions.loadAllPlayersThrowingChecked(""))
.isInstanceOf(TimeoutException.class);
}
@Test
public void loadAllPlayersThrowingUnchecked() {
assertThatThrownBy(() -> exceptions.loadAllPlayersThrowingUnchecked(""))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
public void loadAllPlayersWrapping() {
assertThatThrownBy(() -> exceptions.loadAllPlayersWrapping(""))
.isInstanceOf(IOException.class);
}
@Test
public void loadAllPlayersRethrowing() {
assertThatThrownBy(() -> exceptions.loadAllPlayersRethrowing(""))
.isInstanceOf(PlayerLoadException.class);
}
@Test
public void loadAllPlayersThrowable() {
assertThatThrownBy(() -> exceptions.loadAllPlayersThrowable(""))
.isInstanceOf(NullPointerException.class);
}
@Test
public void getPlayerScoreSwallowingExceptionAntiPatternAlternative2() {
assertThatThrownBy(() -> exceptions.getPlayerScoreSwallowingExceptionAntiPatternAlternative2(""))
.isInstanceOf(PlayerScoreException.class);
}
}
@@ -0,0 +1,12 @@
package com.baeldung.exceptions.noclassdeffounderror;
import org.junit.Test;
public class NoClassDefFoundErrorUnitTest {
@Test(expected = NoClassDefFoundError.class)
public void givenInitErrorInClass_whenloadClass_thenNoClassDefFoundError() {
NoClassDefFoundErrorExample sample = new NoClassDefFoundErrorExample();
sample.getClassWithInitErrors();
}
}
@@ -0,0 +1,17 @@
package com.baeldung.exceptions.sneakythrows;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class SneakyRunnableUnitTest {
@Test
public void whenCallSneakyRunnableMethod_thenThrowException() {
try {
new SneakyRunnable().run();
} catch (Exception e) {
assertEquals(InterruptedException.class, e.getStackTrace());
}
}
}
@@ -0,0 +1,18 @@
package com.baeldung.exceptions.sneakythrows;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class SneakyThrowsUnitTest {
@Test
public void whenCallSneakyMethod_thenThrowSneakyException() {
try {
SneakyThrows.throwsSneakyIOException();
} catch (Exception ex) {
assertEquals("sneaky", ex.getMessage().toString());
}
}
}
@@ -0,0 +1,10 @@
package com.baeldung.exceptions.stackoverflowerror;
import org.junit.Test;
public class AccountHolderManualTest {
@Test(expected = StackOverflowError.class)
public void whenInstanciatingAccountHolder_thenThrowsException() {
AccountHolder holder = new AccountHolder();
}
}
@@ -0,0 +1,10 @@
package com.baeldung.exceptions.stackoverflowerror;
import org.junit.Test;
public class CyclicDependancyManualTest {
@Test(expected = StackOverflowError.class)
public void whenInstanciatingClassOne_thenThrowsException() {
ClassOne obj = new ClassOne();
}
}
@@ -0,0 +1,31 @@
package com.baeldung.exceptions.stackoverflowerror;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class InfiniteRecursionWithTerminationConditionManualTest {
@Test
public void givenPositiveIntNoOne_whenCalcFact_thenCorrectlyCalc() {
int numToCalcFactorial = 1;
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
assertEquals(1, irtc.calculateFactorial(numToCalcFactorial));
}
@Test
public void givenPositiveIntGtOne_whenCalcFact_thenCorrectlyCalc() {
int numToCalcFactorial = 5;
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
assertEquals(120, irtc.calculateFactorial(numToCalcFactorial));
}
@Test(expected = StackOverflowError.class)
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
int numToCalcFactorial = -1;
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
irtc.calculateFactorial(numToCalcFactorial);
}
}
@@ -0,0 +1,15 @@
package com.baeldung.exceptions.stackoverflowerror;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class RecursionWithCorrectTerminationConditionManualTest {
@Test
public void givenNegativeInt_whenCalcFact_thenCorrectlyCalc() {
int numToCalcFactorial = -1;
RecursionWithCorrectTerminationCondition rctc = new RecursionWithCorrectTerminationCondition();
assertEquals(1, rctc.calculateFactorial(numToCalcFactorial));
}
}
@@ -0,0 +1,30 @@
package com.baeldung.exceptions.stackoverflowerror;
import org.junit.Test;
public class UnintendedInfiniteRecursionManualTest {
@Test(expected = StackOverflowError.class)
public void givenPositiveIntNoOne_whenCalFact_thenThrowsException() {
int numToCalcFactorial = 1;
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
uir.calculateFactorial(numToCalcFactorial);
}
@Test(expected = StackOverflowError.class)
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
int numToCalcFactorial = 2;
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
uir.calculateFactorial(numToCalcFactorial);
}
@Test(expected = StackOverflowError.class)
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
int numToCalcFactorial = -1;
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
uir.calculateFactorial(numToCalcFactorial);
}
}
@@ -0,0 +1,22 @@
package com.baeldung.exceptions.throwvsthrows;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class SimpleServiceUnitTest {
SimpleService simpleService = new SimpleService();
@Test
void whenSQLExceptionIsThrown_thenShouldBeRethrownWithWrappedException() {
assertThrows(DataAccessException.class,
() -> simpleService.wrappingException());
}
@Test
void whenCalled_thenNullPointerExceptionIsThrown() {
assertThrows(NullPointerException.class,
() -> simpleService.runtimeNullPointerException());
}
}