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,22 @@
package com.baeldung.junit4;
import com.baeldung.junit4.categories.Annotations;
import com.baeldung.junit4.categories.JUnit4UnitTest;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category(value = { Annotations.class, JUnit4UnitTest.class })
public class AnnotationTestExampleUnitTest {
@Test(expected = Exception.class)
public void shouldRaiseAnException() throws Exception {
throw new Exception("This is my expected exception");
}
@Test(timeout = 1)
@Ignore
public void shouldFailBecauseTimeout() throws InterruptedException {
Thread.sleep(10);
}
}
@@ -0,0 +1,36 @@
package com.baeldung.junit4;
import org.junit.Assert;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
@DisplayName("Test case for assertions")
public class AssertionUnitTest {
@Test
@DisplayName("Arrays should be equals")
public void whenAssertingArraysEquality_thenEqual() {
char[] expected = {'J', 'u', 'p', 'i', 't', 'e', 'r'};
char[] actual = "Jupiter".toCharArray();
assertArrayEquals("Arrays should be equal", expected, actual);
}
@Test
public void givenMultipleAssertion_whenAssertingAll_thenOK() {
assertEquals("4 is 2 times 2", 4, 2 * 2);
assertEquals("java", "JAVA".toLowerCase());
assertEquals("null is equal to null", null, null);
}
@Test
public void testAssertThatHasItems() {
assertThat(Arrays.asList("Java", "Kotlin", "Scala"), hasItems("Java", "Kotlin"));
}
}
@@ -0,0 +1,23 @@
package com.baeldung.junit4;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
public class AssumeUnitTest {
@Test
public void trueAssumption() {
assumeTrue("5 is greater the 1", 5 > 1);
assertEquals(5 + 2, 7);
}
@Test
public void falseAssumption() {
assumeFalse("5 is less then 1", 5 < 1);
assertEquals(5 + 2, 7);
}
}
@@ -0,0 +1,24 @@
package com.baeldung.junit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class ExceptionAssertionUnitTest {
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Test(expected = NullPointerException.class)
public void whenExceptionThrown_thenExpectationSatisfied() {
String test = null;
test.length();
}
@Test
public void whenExceptionThrown_thenRuleIsApplied() {
exceptionRule.expect(NumberFormatException.class);
exceptionRule.expectMessage("For input string");
Integer.parseInt("1a");
}
}
@@ -0,0 +1,16 @@
package com.baeldung.junit4;
import org.junit.Rule;
import org.junit.Test;
public class RuleExampleUnitTest {
@Rule
public final TraceUnitTestRule traceRuleTests = new TraceUnitTestRule();
@Test
public void whenTracingTests() {
System.out.println("This is my test");
/*...*/
}
}
@@ -0,0 +1,34 @@
package com.baeldung.junit4;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import java.util.logging.Logger;
public class TestAnnotationsUnitTest {
private static final Logger log = Logger.getLogger(TestAnnotationsUnitTest.class.getName());
@BeforeClass
static void setup() {
log.info("@BeforeAll - executes once before all test methods in this class");
}
@Before
void init() {
log.info("@BeforeEach - executes before each test method in this class");
}
@After
void tearDown() {
log.info("@AfterEach - executed after each test method.");
}
@AfterClass
static void done() {
log.info("@AfterAll - executed after all test methods.");
}
}
@@ -0,0 +1,35 @@
package com.baeldung.junit4;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.MultipleFailureException;
import org.junit.runners.model.Statement;
import java.util.ArrayList;
import java.util.List;
public class TraceUnitTestRule implements TestRule {
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
List<Throwable> errors = new ArrayList<Throwable>();
System.out.println("Starting test ... " + description.getMethodName());
try {
base.evaluate();
} catch (Throwable e) {
errors.add(e);
} finally {
System.out.println("... test finished. " + description.getMethodName());
}
MultipleFailureException.assertEmpty(errors);
}
};
}
}
@@ -0,0 +1,5 @@
package com.baeldung.junit4.categories;
public interface Annotations {
}
@@ -0,0 +1,5 @@
package com.baeldung.junit4.categories;
public interface JUnit4UnitTest {
}