Made minor changes in some patterns such as removed throws clause where not needed, changed incorrect order of arguments in assertEquals
This commit is contained in:
@@ -16,11 +16,12 @@
|
||||
*/
|
||||
package com.iluwatar.event.asynchronous;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -30,26 +31,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
*
|
||||
*/
|
||||
public class EventAsynchronousTest {
|
||||
App app;
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(EventAsynchronousTest.class);
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
app = new App();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsynchronousEvent() {
|
||||
EventManager eventManager = new EventManager();
|
||||
try {
|
||||
int aEventId = eventManager.createAsync(60);
|
||||
eventManager.start(aEventId);
|
||||
assertTrue(eventManager.getEventPool().size() == 1);
|
||||
assertEquals(1, eventManager.getEventPool().size());
|
||||
assertTrue(eventManager.getEventPool().size() < EventManager.MAX_RUNNING_EVENTS);
|
||||
assertTrue(eventManager.numOfCurrentlyRunningSyncEvent() == -1);
|
||||
assertEquals(-1, eventManager.numOfCurrentlyRunningSyncEvent());
|
||||
eventManager.cancel(aEventId);
|
||||
assertTrue(eventManager.getEventPool().size() == 0);
|
||||
assertTrue(eventManager.getEventPool().isEmpty());
|
||||
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
@@ -61,11 +55,11 @@ public class EventAsynchronousTest {
|
||||
try {
|
||||
int sEventId = eventManager.create(60);
|
||||
eventManager.start(sEventId);
|
||||
assertTrue(eventManager.getEventPool().size() == 1);
|
||||
assertEquals(1, eventManager.getEventPool().size());
|
||||
assertTrue(eventManager.getEventPool().size() < EventManager.MAX_RUNNING_EVENTS);
|
||||
assertTrue(eventManager.numOfCurrentlyRunningSyncEvent() != -1);
|
||||
assertNotEquals(-1, eventManager.numOfCurrentlyRunningSyncEvent());
|
||||
eventManager.cancel(sEventId);
|
||||
assertTrue(eventManager.getEventPool().size() == 0);
|
||||
assertTrue(eventManager.getEventPool().isEmpty());
|
||||
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException
|
||||
| InvalidOperationException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
@@ -73,7 +67,7 @@ public class EventAsynchronousTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsuccessfulSynchronousEvent() throws InvalidOperationException {
|
||||
public void testUnsuccessfulSynchronousEvent() {
|
||||
assertThrows(InvalidOperationException.class, () -> {
|
||||
EventManager eventManager = new EventManager();
|
||||
try {
|
||||
@@ -94,7 +88,7 @@ public class EventAsynchronousTest {
|
||||
int eventTime = 1;
|
||||
|
||||
int sEventId = eventManager.create(eventTime);
|
||||
assertTrue(eventManager.getEventPool().size() == 1);
|
||||
assertEquals(1, eventManager.getEventPool().size());
|
||||
eventManager.start(sEventId);
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
@@ -104,7 +98,7 @@ public class EventAsynchronousTest {
|
||||
while (System.currentTimeMillis() < endTime) {
|
||||
}
|
||||
|
||||
assertTrue(eventManager.getEventPool().size() == 0);
|
||||
assertTrue(eventManager.getEventPool().isEmpty());
|
||||
|
||||
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException
|
||||
| InvalidOperationException e) {
|
||||
@@ -121,7 +115,7 @@ public class EventAsynchronousTest {
|
||||
int aEventId1 = eventManager.createAsync(eventTime);
|
||||
int aEventId2 = eventManager.createAsync(eventTime);
|
||||
int aEventId3 = eventManager.createAsync(eventTime);
|
||||
assertTrue(eventManager.getEventPool().size() == 3);
|
||||
assertEquals(3, eventManager.getEventPool().size());
|
||||
|
||||
eventManager.start(aEventId1);
|
||||
eventManager.start(aEventId2);
|
||||
@@ -133,7 +127,7 @@ public class EventAsynchronousTest {
|
||||
while (System.currentTimeMillis() < endTime) {
|
||||
}
|
||||
|
||||
assertTrue(eventManager.getEventPool().size() == 0);
|
||||
assertTrue(eventManager.getEventPool().isEmpty());
|
||||
|
||||
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
|
Reference in New Issue
Block a user