mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-04 20:13:21 +00:00
Minor refactorings and code style changes (#807)
* Made minor changes in some patterns such as removed throws clause where not needed, changed incorrect order of arguments in assertEquals * Minor refactorings and code style changes. 1) Removed several use of raw types 2) Removed unnecessary throws clauses 3) Used lambda expressions wherever applicable 4) Used apt assertion methods for readability 5) Use of try with resources wherever applicable 6) Corrected incorrect order of assertXXX arguments * Removed unused import from Promise * Addressed review comments * Addressed checkstyle issue
This commit is contained in:
1 parent
25ed7c09c5
commit
2aa9e78ddd
112 files changed
+312
-463
No files matched your search
+13
-19
@@ -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