diff --git a/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java b/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java index 63a9974b99eb..03b2126c6edc 100644 --- a/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java +++ b/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java @@ -32,6 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * AbstractDocument test class @@ -81,8 +82,8 @@ public void shouldIncludePropsInToString() { Map props = new HashMap<>(); props.put(KEY, VALUE); DocumentImplementation document = new DocumentImplementation(props); - assertNotNull(document.toString().contains(KEY)); - assertNotNull(document.toString().contains(VALUE)); + assertTrue(document.toString().contains(KEY)); + assertTrue(document.toString().contains(VALUE)); } } diff --git a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitorTest.java b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitorTest.java index 0cee046a87d2..1e7724c5eec6 100644 --- a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitorTest.java +++ b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitorTest.java @@ -25,27 +25,19 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.groups.Tuple.tuple; import static uk.org.lidalia.slf4jext.Level.INFO; -import static org.mockito.Mockito.mock; -import uk.org.lidalia.slf4jtest.TestLogger; -import uk.org.lidalia.slf4jtest.TestLoggerFactory; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor; -import com.iluwatar.acyclicvisitor.Hayes; -import com.iluwatar.acyclicvisitor.HayesVisitor; -import com.iluwatar.acyclicvisitor.Zoom; -import com.iluwatar.acyclicvisitor.ZoomVisitor; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; +import uk.org.lidalia.slf4jtest.TestLogger; +import uk.org.lidalia.slf4jtest.TestLoggerFactory; /** * ConfigureForUnixVisitor test class */ public class ConfigureForUnixVisitorTest { - TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForUnixVisitor.class); + private static final TestLogger LOGGER = TestLoggerFactory.getTestLogger(ConfigureForUnixVisitor.class); @AfterEach public void clearLoggers() { @@ -59,7 +51,7 @@ public void testVisitForZoom() { conUnix.visit(zoom); - assertThat(logger.getLoggingEvents()).extracting("level", "message").contains( + assertThat(LOGGER.getLoggingEvents()).extracting("level", "message").contains( tuple(INFO, zoom + " used with Unix configurator.")); } } diff --git a/aggregator-microservices/inventory-microservice/src/test/java/com/iluwatar/inventory/microservice/InventoryControllerTest.java b/aggregator-microservices/inventory-microservice/src/test/java/com/iluwatar/inventory/microservice/InventoryControllerTest.java index 78af8582e00e..c53a86b21d26 100644 --- a/aggregator-microservices/inventory-microservice/src/test/java/com/iluwatar/inventory/microservice/InventoryControllerTest.java +++ b/aggregator-microservices/inventory-microservice/src/test/java/com/iluwatar/inventory/microservice/InventoryControllerTest.java @@ -31,7 +31,7 @@ */ public class InventoryControllerTest { @Test - public void testGetProductInventories() throws Exception { + public void testGetProductInventories() { InventoryController inventoryController = new InventoryController(); int numberOfInventories = inventoryController.getProductInventories(); diff --git a/bridge/src/test/java/com/iluwatar/bridge/HammerTest.java b/bridge/src/test/java/com/iluwatar/bridge/HammerTest.java index 4cb3bd69e925..905e94aa48d8 100644 --- a/bridge/src/test/java/com/iluwatar/bridge/HammerTest.java +++ b/bridge/src/test/java/com/iluwatar/bridge/HammerTest.java @@ -37,7 +37,7 @@ public class HammerTest extends WeaponTest { * underlying weapon implementation. */ @Test - public void testHammer() throws Exception { + public void testHammer() { final Hammer hammer = spy(new Hammer(mock(FlyingEnchantment.class))); testBasicWeaponActions(hammer); } diff --git a/bridge/src/test/java/com/iluwatar/bridge/SwordTest.java b/bridge/src/test/java/com/iluwatar/bridge/SwordTest.java index e1cccb39afb6..61cb59f571aa 100644 --- a/bridge/src/test/java/com/iluwatar/bridge/SwordTest.java +++ b/bridge/src/test/java/com/iluwatar/bridge/SwordTest.java @@ -37,7 +37,7 @@ public class SwordTest extends WeaponTest { * underlying weapon implementation. */ @Test - public void testSword() throws Exception { + public void testSword() { final Sword sword = spy(new Sword(mock(FlyingEnchantment.class))); testBasicWeaponActions(sword); } diff --git a/callback/src/main/java/com/iluwatar/callback/App.java b/callback/src/main/java/com/iluwatar/callback/App.java index 278975db9bae..ec8f3f20ee98 100644 --- a/callback/src/main/java/com/iluwatar/callback/App.java +++ b/callback/src/main/java/com/iluwatar/callback/App.java @@ -41,12 +41,7 @@ public class App { */ public static void main(String[] args) { Task task = new SimpleTask(); - Callback callback = new Callback() { - @Override - public void call() { - LOGGER.info("I'm done now."); - } - }; + Callback callback = () -> LOGGER.info("I'm done now."); task.executeWith(callback); } } diff --git a/callback/src/test/java/com/iluwatar/callback/CallbackTest.java b/callback/src/test/java/com/iluwatar/callback/CallbackTest.java index 7a14b0a4a600..f2e51751a79b 100644 --- a/callback/src/test/java/com/iluwatar/callback/CallbackTest.java +++ b/callback/src/test/java/com/iluwatar/callback/CallbackTest.java @@ -38,29 +38,6 @@ public class CallbackTest { @Test public void test() { - Callback callback = new Callback() { - @Override - public void call() { - callingCount++; - } - }; - - Task task = new SimpleTask(); - - assertEquals(new Integer(0), callingCount, "Initial calling count of 0"); - - task.executeWith(callback); - - assertEquals(new Integer(1), callingCount, "Callback called once"); - - task.executeWith(callback); - - assertEquals(new Integer(2), callingCount, "Callback called twice"); - - } - - @Test - public void testWithLambdasExample() { Callback callback = () -> callingCount++; Task task = new SimpleTask(); diff --git a/chain/src/test/java/com/iluwatar/chain/OrcKingTest.java b/chain/src/test/java/com/iluwatar/chain/OrcKingTest.java index c7cfb687c01a..bc1c6f91c9e9 100644 --- a/chain/src/test/java/com/iluwatar/chain/OrcKingTest.java +++ b/chain/src/test/java/com/iluwatar/chain/OrcKingTest.java @@ -43,7 +43,7 @@ public class OrcKingTest { }; @Test - public void testMakeRequest() throws Exception { + public void testMakeRequest() { final OrcKing king = new OrcKing(); for (final Request request : REQUESTS) { diff --git a/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/Car.java b/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/Car.java index ffd52cca3bb6..e3cb9e11fba1 100644 --- a/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/Car.java +++ b/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/Car.java @@ -26,10 +26,10 @@ * A Car class that has the properties of make, model, year and category. */ public class Car { - private String make; - private String model; - private int year; - private Category category; + private final String make; + private final String model; + private final int year; + private final Category category; /** * Constructor to create an instance of car. diff --git a/converter/src/test/java/com/iluwatar/converter/ConverterTest.java b/converter/src/test/java/com/iluwatar/converter/ConverterTest.java index f5c41256d8b3..3c8c4e9fc287 100644 --- a/converter/src/test/java/com/iluwatar/converter/ConverterTest.java +++ b/converter/src/test/java/com/iluwatar/converter/ConverterTest.java @@ -71,7 +71,7 @@ public void testCustomConverter() { user.getFirstName().toLowerCase() + user.getLastName().toLowerCase() + "@whatever.com")); User u1 = new User("John", "Doe", false, "12324"); UserDto userDto = converter.convertFromEntity(u1); - assertEquals(userDto.getEmail(), "johndoe@whatever.com"); + assertEquals("johndoe@whatever.com", userDto.getEmail()); } /** @@ -83,6 +83,6 @@ public void testCollectionConversion() { ArrayList users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"), new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243")); List fromDtos = userConverter.createFromDtos(userConverter.createFromEntities(users)); - assertEquals(fromDtos, users); + assertEquals(users, fromDtos); } } diff --git a/cqrs/src/test/java/com/iluwatar/cqrs/IntegrationTest.java b/cqrs/src/test/java/com/iluwatar/cqrs/IntegrationTest.java index 536418cbe8e3..22cbb4db31c8 100644 --- a/cqrs/src/test/java/com/iluwatar/cqrs/IntegrationTest.java +++ b/cqrs/src/test/java/com/iluwatar/cqrs/IntegrationTest.java @@ -96,7 +96,7 @@ public void testGetBook() { @Test public void testGetAuthorBooks() { List books = queryService.getAuthorBooks("username1"); - assertTrue(books.size() == 2); + assertEquals(2, books.size()); assertTrue(books.contains(new Book("title1", 10))); assertTrue(books.contains(new Book("new_title2", 30))); } diff --git a/dao/src/test/java/com/iluwatar/dao/CustomerTest.java b/dao/src/test/java/com/iluwatar/dao/CustomerTest.java index 1a55e3bebcd1..6bc8689fd87d 100644 --- a/dao/src/test/java/com/iluwatar/dao/CustomerTest.java +++ b/dao/src/test/java/com/iluwatar/dao/CustomerTest.java @@ -88,13 +88,7 @@ public void equalsWithSameObjects() { @Test public void testToString() { - final StringBuffer buffer = new StringBuffer(); - buffer.append("Customer{id=") - .append("" + customer.getId()) - .append(", firstName='") - .append(customer.getFirstName()) - .append("\', lastName='") - .append(customer.getLastName() + "\'}"); - assertEquals(buffer.toString(), customer.toString()); + assertEquals(String.format("Customer{id=%s, firstName='%s', lastName='%s'}", + customer.getId(), customer.getFirstName(), customer.getLastName()), customer.toString()); } } diff --git a/dao/src/test/java/com/iluwatar/dao/DbCustomerDaoTest.java b/dao/src/test/java/com/iluwatar/dao/DbCustomerDaoTest.java index 80920aa371d9..23caf14ec28e 100644 --- a/dao/src/test/java/com/iluwatar/dao/DbCustomerDaoTest.java +++ b/dao/src/test/java/com/iluwatar/dao/DbCustomerDaoTest.java @@ -257,7 +257,7 @@ public void deleteSchema() throws SQLException { private void assertCustomerCountIs(int count) throws Exception { try (Stream allCustomers = dao.getAll()) { - assertTrue(allCustomers.count() == count); + assertEquals(count, allCustomers.count()); } } diff --git a/dao/src/test/java/com/iluwatar/dao/InMemoryCustomerDaoTest.java b/dao/src/test/java/com/iluwatar/dao/InMemoryCustomerDaoTest.java index 7cb14b0b1d9f..0aa86576b1b2 100644 --- a/dao/src/test/java/com/iluwatar/dao/InMemoryCustomerDaoTest.java +++ b/dao/src/test/java/com/iluwatar/dao/InMemoryCustomerDaoTest.java @@ -156,7 +156,7 @@ private int getNonExistingCustomerId() { private void assertCustomerCountIs(int count) throws Exception { try (Stream allCustomers = dao.getAll()) { - assertTrue(allCustomers.count() == count); + assertEquals(count, allCustomers.count()); } } } diff --git a/data-mapper/src/test/java/com/iluwatar/datamapper/DataMapperTest.java b/data-mapper/src/test/java/com/iluwatar/datamapper/DataMapperTest.java index 5f63cf045ce4..0e1552a78cce 100644 --- a/data-mapper/src/test/java/com/iluwatar/datamapper/DataMapperTest.java +++ b/data-mapper/src/test/java/com/iluwatar/datamapper/DataMapperTest.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; /** * The Data Mapper (DM) is a layer of software that separates the in-memory objects from the @@ -43,27 +44,29 @@ public void testFirstDataMapper() { final StudentDataMapper mapper = new StudentDataMapperImpl(); /* Create new student */ - Student student = new Student(1, "Adam", 'A'); + int studentId = 1; + Student student = new Student(studentId, "Adam", 'A'); /* Add student in respectibe db */ mapper.insert(student); /* Check if student is added in db */ - assertEquals(student.getStudentId(), mapper.find(student.getStudentId()).get().getStudentId()); + assertEquals(studentId, mapper.find(student.getStudentId()).get().getStudentId()); /* Update existing student object */ - student = new Student(student.getStudentId(), "AdamUpdated", 'A'); + String updatedName = "AdamUpdated"; + student = new Student(student.getStudentId(), updatedName, 'A'); /* Update student in respectibe db */ mapper.update(student); /* Check if student is updated in db */ - assertEquals(mapper.find(student.getStudentId()).get().getName(), "AdamUpdated"); + assertEquals(updatedName, mapper.find(student.getStudentId()).get().getName()); /* Delete student in db */ mapper.delete(student); /* Result should be false */ - assertEquals(false, mapper.find(student.getStudentId()).isPresent()); + assertFalse(mapper.find(student.getStudentId()).isPresent()); } } diff --git a/data-mapper/src/test/java/com/iluwatar/datamapper/StudentTest.java b/data-mapper/src/test/java/com/iluwatar/datamapper/StudentTest.java index 523a6509a324..7bf396a5d2da 100644 --- a/data-mapper/src/test/java/com/iluwatar/datamapper/StudentTest.java +++ b/data-mapper/src/test/java/com/iluwatar/datamapper/StudentTest.java @@ -20,7 +20,9 @@ import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -28,28 +30,27 @@ */ public final class StudentTest { - @Test /** * This API tests the equality behaviour of Student object * Object Equality should work as per logic defined in equals method * * @throws Exception if any execution error during test */ + @Test public void testEquality() throws Exception { /* Create some students */ final Student firstStudent = new Student(1, "Adam", 'A'); final Student secondStudent = new Student(2, "Donald", 'B'); final Student secondSameStudent = new Student(2, "Donald", 'B'); - final Student firstSameStudent = firstStudent; /* Check equals functionality: should return 'true' */ - assertTrue(firstStudent.equals(firstSameStudent)); + assertEquals(firstStudent, firstStudent); /* Check equals functionality: should return 'false' */ - assertFalse(firstStudent.equals(secondStudent)); + assertNotEquals(firstStudent, secondStudent); /* Check equals functionality: should return 'true' */ - assertTrue(secondStudent.equals(secondSameStudent)); + assertEquals(secondStudent, secondSameStudent); } } diff --git a/data-transfer-object/src/test/java/com/iluwatar/datatransfer/CustomerResourceTest.java b/data-transfer-object/src/test/java/com/iluwatar/datatransfer/CustomerResourceTest.java index db669b785f1f..b7e3f8de835f 100644 --- a/data-transfer-object/src/test/java/com/iluwatar/datatransfer/CustomerResourceTest.java +++ b/data-transfer-object/src/test/java/com/iluwatar/datatransfer/CustomerResourceTest.java @@ -30,6 +30,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * tests {@link CustomerResource}. @@ -45,10 +46,10 @@ public void shouldGetAllCustomers() { List allCustomers = customerResource.getAllCustomers(); - assertEquals(allCustomers.size(), 1); - assertEquals(allCustomers.get(0).getId(), "1"); - assertEquals(allCustomers.get(0).getFirstName(), "Melody"); - assertEquals(allCustomers.get(0).getLastName(), "Yates"); + assertEquals(1, allCustomers.size()); + assertEquals("1", allCustomers.get(0).getId()); + assertEquals("Melody", allCustomers.get(0).getFirstName()); + assertEquals("Yates", allCustomers.get(0).getLastName()); } @Test @@ -59,9 +60,9 @@ public void shouldSaveCustomer() { customerResource.save(customer); List allCustomers = customerResource.getAllCustomers(); - assertEquals(allCustomers.get(0).getId(), "1"); - assertEquals(allCustomers.get(0).getFirstName(), "Rita"); - assertEquals(allCustomers.get(0).getLastName(), "Reynolds"); + assertEquals("1", allCustomers.get(0).getId()); + assertEquals("Rita", allCustomers.get(0).getFirstName()); + assertEquals("Reynolds", allCustomers.get(0).getLastName()); } @Test @@ -75,7 +76,7 @@ public void shouldDeleteCustomer() { customerResource.delete(customer.getId()); List allCustomers = customerResource.getAllCustomers(); - assertEquals(allCustomers.size(), 0); + assertTrue(allCustomers.isEmpty()); } } \ No newline at end of file diff --git a/delegation/src/main/java/com/iluwatar/delegation/simple/App.java b/delegation/src/main/java/com/iluwatar/delegation/simple/App.java index 5f410d09bb8a..83e00fd1fb1c 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/App.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/App.java @@ -40,7 +40,7 @@ */ public class App { - public static final String MESSAGE_TO_PRINT = "hello world"; + private static final String MESSAGE_TO_PRINT = "hello world"; /** * Program entry point diff --git a/dirty-flag/src/test/java/org/dirty/flag/DirtyFlagTest.java b/dirty-flag/src/test/java/org/dirty/flag/DirtyFlagTest.java index 8f651b2678bb..fffb12d55a75 100644 --- a/dirty-flag/src/test/java/org/dirty/flag/DirtyFlagTest.java +++ b/dirty-flag/src/test/java/org/dirty/flag/DirtyFlagTest.java @@ -22,6 +22,7 @@ */ package org.dirty.flag; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; @@ -41,7 +42,7 @@ public class DirtyFlagTest { public void testIsDirty() { DataFetcher df = new DataFetcher(); List countries = df.fetch(); - assertTrue(!countries.isEmpty()); + assertFalse(countries.isEmpty()); } @Test diff --git a/eip-aggregator/src/main/java/com/iluwatar/eip/aggregator/routes/AggregatorRoute.java b/eip-aggregator/src/main/java/com/iluwatar/eip/aggregator/routes/AggregatorRoute.java index 536565339f1a..5f130ff69159 100644 --- a/eip-aggregator/src/main/java/com/iluwatar/eip/aggregator/routes/AggregatorRoute.java +++ b/eip-aggregator/src/main/java/com/iluwatar/eip/aggregator/routes/AggregatorRoute.java @@ -51,7 +51,7 @@ public class AggregatorRoute extends RouteBuilder { * @throws Exception in case of exception during configuration */ @Override - public void configure() throws Exception { + public void configure() { // Main route from("{{entry}}").aggregate(constant(true), aggregator) .completionSize(3).completionInterval(2000) diff --git a/eip-message-channel/src/main/java/com/iluwatar/eip/message/channel/App.java b/eip-message-channel/src/main/java/com/iluwatar/eip/message/channel/App.java index d5929d0db3aa..51d75b8e6a38 100644 --- a/eip-message-channel/src/main/java/com/iluwatar/eip/message/channel/App.java +++ b/eip-message-channel/src/main/java/com/iluwatar/eip/message/channel/App.java @@ -70,7 +70,7 @@ public void configure() throws Exception { }); context.start(); - context.getRoutes().stream().forEach(r -> LOGGER.info(r.toString())); + context.getRoutes().forEach(r -> LOGGER.info(r.toString())); context.stop(); } } diff --git a/eip-publish-subscribe/src/main/java/com/iluwatar/eip/publish/subscribe/App.java b/eip-publish-subscribe/src/main/java/com/iluwatar/eip/publish/subscribe/App.java index 7c7e77a1848a..2ff372fbe6c8 100644 --- a/eip-publish-subscribe/src/main/java/com/iluwatar/eip/publish/subscribe/App.java +++ b/eip-publish-subscribe/src/main/java/com/iluwatar/eip/publish/subscribe/App.java @@ -65,7 +65,7 @@ public void configure() throws Exception { }); ProducerTemplate template = context.createProducerTemplate(); context.start(); - context.getRoutes().stream().forEach(r -> LOGGER.info(r.toString())); + context.getRoutes().forEach(r -> LOGGER.info(r.toString())); template.sendBody("direct:origin", "Hello from origin"); context.stop(); } diff --git a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingJoffreyTest.java b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingJoffreyTest.java index 3f3296c575e3..c6e8e11db969 100644 --- a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingJoffreyTest.java +++ b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingJoffreyTest.java @@ -76,7 +76,7 @@ public void testOnEvent() { private class InMemoryAppender extends AppenderBase { private List log = new LinkedList<>(); - public InMemoryAppender(Class clazz) { + public InMemoryAppender(Class clazz) { ((Logger) LoggerFactory.getLogger(clazz)).addAppender(this); start(); } diff --git a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/WeekdayTest.java b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/WeekdayTest.java index df2d8ac79549..908024c9bbd5 100644 --- a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/WeekdayTest.java +++ b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/WeekdayTest.java @@ -35,7 +35,7 @@ public class WeekdayTest { @Test - public void testToString() throws Exception { + public void testToString() { for (final Weekday weekday : Weekday.values()) { final String toString = weekday.toString(); assertNotNull(toString); diff --git a/event-asynchronous/src/test/java/com/iluwatar/event/asynchronous/EventAsynchronousTest.java b/event-asynchronous/src/test/java/com/iluwatar/event/asynchronous/EventAsynchronousTest.java index aa2c644cb5a9..5271e4ec8e2f 100644 --- a/event-asynchronous/src/test/java/com/iluwatar/event/asynchronous/EventAsynchronousTest.java +++ b/event-asynchronous/src/test/java/com/iluwatar/event/asynchronous/EventAsynchronousTest.java @@ -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 @@ * */ 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 void testSynchronousEvent() { 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 void testSynchronousEvent() { } @Test - public void testUnsuccessfulSynchronousEvent() throws InvalidOperationException { + public void testUnsuccessfulSynchronousEvent() { assertThrows(InvalidOperationException.class, () -> { EventManager eventManager = new EventManager(); try { @@ -94,7 +88,7 @@ public void testFullSynchronousEvent() { 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 void testFullSynchronousEvent() { while (System.currentTimeMillis() < endTime) { } - assertTrue(eventManager.getEventPool().size() == 0); + assertTrue(eventManager.getEventPool().isEmpty()); } catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException | InvalidOperationException e) { @@ -121,7 +115,7 @@ public void testFullAsynchronousEvent() { 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 void testFullAsynchronousEvent() { while (System.currentTimeMillis() < endTime) { } - assertTrue(eventManager.getEventPool().size() == 0); + assertTrue(eventManager.getEventPool().isEmpty()); } catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) { LOGGER.error(e.getMessage()); diff --git a/event-sourcing/src/main/java/com/iluwatar/event/sourcing/app/App.java b/event-sourcing/src/main/java/com/iluwatar/event/sourcing/app/App.java index 50e9b503edbd..ad3120803ef5 100644 --- a/event-sourcing/src/main/java/com/iluwatar/event/sourcing/app/App.java +++ b/event-sourcing/src/main/java/com/iluwatar/event/sourcing/app/App.java @@ -74,7 +74,7 @@ public static void main(String[] args) { LOGGER.info("Running the system first time............"); eventProcessor.reset(); - LOGGER.info("Creating th accounts............"); + LOGGER.info("Creating the accounts............"); eventProcessor.process(new AccountCreateEvent( 0, new Date().getTime(), ACCOUNT_OF_DAENERYS, "Daenerys Targaryen")); @@ -98,7 +98,7 @@ public static void main(String[] args) { LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_DAENERYS).toString()); LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_JON).toString()); - LOGGER.info("At that point system had a shot down, state in memory is cleared............"); + LOGGER.info("At that point system had a shut down, state in memory is cleared............"); AccountAggregate.resetState(); LOGGER.info("Recover the system by the events in journal file............"); diff --git a/event-sourcing/src/main/java/com/iluwatar/event/sourcing/event/MoneyTransferEvent.java b/event-sourcing/src/main/java/com/iluwatar/event/sourcing/event/MoneyTransferEvent.java index 0307d3af712f..b78484ffd130 100644 --- a/event-sourcing/src/main/java/com/iluwatar/event/sourcing/event/MoneyTransferEvent.java +++ b/event-sourcing/src/main/java/com/iluwatar/event/sourcing/event/MoneyTransferEvent.java @@ -92,7 +92,7 @@ public void process() { } Account accountTo = AccountAggregate.getAccount(accountNoTo); if (accountTo == null) { - throw new RuntimeException("Account not found" + accountTo); + throw new RuntimeException("Account not found " + accountNoTo); } accountFrom.handleTransferFromEvent(this); diff --git a/execute-around/src/test/java/com/iluwatar/execute/around/SimpleFileWriterTest.java b/execute-around/src/test/java/com/iluwatar/execute/around/SimpleFileWriterTest.java index 22bdf68f7ea6..acd91f4b95ec 100644 --- a/execute-around/src/test/java/com/iluwatar/execute/around/SimpleFileWriterTest.java +++ b/execute-around/src/test/java/com/iluwatar/execute/around/SimpleFileWriterTest.java @@ -44,26 +44,17 @@ @EnableRuleMigrationSupport public class SimpleFileWriterTest { - /** - * Create a temporary folder, used to generate files in during this test - */ @Rule public final TemporaryFolder testFolder = new TemporaryFolder(); - /** - * Verify if the given writer is not 'null' - */ @Test public void testWriterNotNull() throws Exception { final File temporaryFile = this.testFolder.newFile(); new SimpleFileWriter(temporaryFile.getPath(), Assertions::assertNotNull); } - /** - * Test if the {@link SimpleFileWriter} creates a file if it doesn't exist - */ @Test - public void testNonExistentFile() throws Exception { + public void testCreatesNonExistentFile() throws Exception { final File nonExistingFile = new File(this.testFolder.getRoot(), "non-existing-file"); assertFalse(nonExistingFile.exists()); @@ -71,11 +62,8 @@ public void testNonExistentFile() throws Exception { assertTrue(nonExistingFile.exists()); } - /** - * Test if the data written to the file writer actually gets in the file - */ @Test - public void testActualWrite() throws Exception { + public void testContentsAreWrittenToFile() throws Exception { final String testMessage = "Test message"; final File temporaryFile = this.testFolder.newFile(); @@ -85,17 +73,15 @@ public void testActualWrite() throws Exception { assertTrue(Files.lines(temporaryFile.toPath()).allMatch(testMessage::equals)); } - /** - * Verify if an {@link IOException} during the write ripples through - */ @Test - public void testIoException() throws Exception { + public void testRipplesIoExceptionOccurredWhileWriting() { + String message = "Some error"; assertThrows(IOException.class, () -> { final File temporaryFile = this.testFolder.newFile(); new SimpleFileWriter(temporaryFile.getPath(), writer -> { - throw new IOException(""); + throw new IOException(message); }); - }); + }, message); } } diff --git a/extension-objects/src/main/java/concreteextensions/Commander.java b/extension-objects/src/main/java/concreteextensions/Commander.java index 8094d2887ab9..7e978d59eda5 100644 --- a/extension-objects/src/main/java/concreteextensions/Commander.java +++ b/extension-objects/src/main/java/concreteextensions/Commander.java @@ -32,16 +32,16 @@ */ public class Commander implements CommanderExtension { + private static final Logger LOGGER = LoggerFactory.getLogger(Commander.class); + private CommanderUnit unit; public Commander(CommanderUnit commanderUnit) { this.unit = commanderUnit; } - final Logger logger = LoggerFactory.getLogger(Commander.class); - @Override public void commanderReady() { - logger.info("[Commander] " + unit.getName() + " is ready!"); + LOGGER.info("[Commander] " + unit.getName() + " is ready!"); } } diff --git a/extension-objects/src/main/java/concreteextensions/Sergeant.java b/extension-objects/src/main/java/concreteextensions/Sergeant.java index 892a3d3728c5..a47fa07c30f9 100644 --- a/extension-objects/src/main/java/concreteextensions/Sergeant.java +++ b/extension-objects/src/main/java/concreteextensions/Sergeant.java @@ -32,16 +32,16 @@ */ public class Sergeant implements SergeantExtension { + private static final Logger LOGGER = LoggerFactory.getLogger(Sergeant.class); + private SergeantUnit unit; public Sergeant(SergeantUnit sergeantUnit) { this.unit = sergeantUnit; } - final Logger logger = LoggerFactory.getLogger(Sergeant.class); - @Override public void sergeantReady() { - logger.info("[Sergeant] " + unit.getName() + " is ready! "); + LOGGER.info("[Sergeant] " + unit.getName() + " is ready! "); } } diff --git a/extension-objects/src/main/java/concreteextensions/Soldier.java b/extension-objects/src/main/java/concreteextensions/Soldier.java index 79db74d6cf29..1671347a62c1 100644 --- a/extension-objects/src/main/java/concreteextensions/Soldier.java +++ b/extension-objects/src/main/java/concreteextensions/Soldier.java @@ -31,6 +31,7 @@ * Class defining Soldier */ public class Soldier implements SoldierExtension { + private static final Logger LOGGER = LoggerFactory.getLogger(Soldier.class); private SoldierUnit unit; @@ -38,10 +39,8 @@ public Soldier(SoldierUnit soldierUnit) { this.unit = soldierUnit; } - final Logger logger = LoggerFactory.getLogger(Soldier.class); - @Override public void soldierReady() { - logger.info("[Solider] " + unit.getName() + " is ready!"); + LOGGER.info("[Solider] " + unit.getName() + " is ready!"); } } diff --git a/extension-objects/src/test/java/concreteextensions/CommanderTest.java b/extension-objects/src/test/java/concreteextensions/CommanderTest.java index 5dac551f437e..95e70e480560 100644 --- a/extension-objects/src/test/java/concreteextensions/CommanderTest.java +++ b/extension-objects/src/test/java/concreteextensions/CommanderTest.java @@ -30,7 +30,7 @@ */ public class CommanderTest { @Test - public void commanderReady() throws Exception { + public void commanderReady() { final Commander commander = new Commander(new CommanderUnit("CommanderUnitTest")); commander.commanderReady(); diff --git a/extension-objects/src/test/java/units/CommanderUnitTest.java b/extension-objects/src/test/java/units/CommanderUnitTest.java index 536c3ae3f501..7fa29946a2e2 100644 --- a/extension-objects/src/test/java/units/CommanderUnitTest.java +++ b/extension-objects/src/test/java/units/CommanderUnitTest.java @@ -33,13 +33,13 @@ */ public class CommanderUnitTest { @Test - public void getUnitExtension() throws Exception { + public void getUnitExtension() { final Unit unit = new CommanderUnit("CommanderUnitName"); assertNull(unit.getUnitExtension("SoldierExtension")); assertNull(unit.getUnitExtension("SergeantExtension")); - assertNotNull((CommanderExtension) unit.getUnitExtension("CommanderExtension")); + assertNotNull(unit.getUnitExtension("CommanderExtension")); } } \ No newline at end of file diff --git a/extension-objects/src/test/java/units/SergeantUnitTest.java b/extension-objects/src/test/java/units/SergeantUnitTest.java index ac518b48828e..df42313f1b1a 100644 --- a/extension-objects/src/test/java/units/SergeantUnitTest.java +++ b/extension-objects/src/test/java/units/SergeantUnitTest.java @@ -33,12 +33,12 @@ */ public class SergeantUnitTest { @Test - public void getUnitExtension() throws Exception { + public void getUnitExtension() { final Unit unit = new SergeantUnit("SergeantUnitName"); assertNull(unit.getUnitExtension("SoldierExtension")); - assertNotNull((SergeantExtension) unit.getUnitExtension("SergeantExtension")); + assertNotNull(unit.getUnitExtension("SergeantExtension")); assertNull(unit.getUnitExtension("CommanderExtension")); } diff --git a/extension-objects/src/test/java/units/SoldierUnitTest.java b/extension-objects/src/test/java/units/SoldierUnitTest.java index 1aeb9a3cddc2..5a16d6e8ebc6 100644 --- a/extension-objects/src/test/java/units/SoldierUnitTest.java +++ b/extension-objects/src/test/java/units/SoldierUnitTest.java @@ -33,11 +33,11 @@ */ public class SoldierUnitTest { @Test - public void getUnitExtension() throws Exception { + public void getUnitExtension() { final Unit unit = new SoldierUnit("SoldierUnitName"); - assertNotNull((SoldierExtension) unit.getUnitExtension("SoldierExtension")); + assertNotNull(unit.getUnitExtension("SoldierExtension")); assertNull(unit.getUnitExtension("SergeantExtension")); assertNull(unit.getUnitExtension("CommanderExtension")); diff --git a/factory-kit/src/test/java/com/iluwatar/factorykit/factorykit/FactoryKitTest.java b/factory-kit/src/test/java/com/iluwatar/factorykit/factorykit/FactoryKitTest.java index f15223feb43c..544e62c0642b 100644 --- a/factory-kit/src/test/java/com/iluwatar/factorykit/factorykit/FactoryKitTest.java +++ b/factory-kit/src/test/java/com/iluwatar/factorykit/factorykit/FactoryKitTest.java @@ -83,7 +83,7 @@ public void testWeapon() { * @param weapon weapon object which is to be verified * @param clazz expected class of the weapon */ - private void verifyWeapon(Weapon weapon, Class clazz) { + private void verifyWeapon(Weapon weapon, Class clazz) { assertTrue(clazz.isInstance(weapon), "Weapon must be an object of: " + clazz.getName()); } } diff --git a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java index 9f0d377fa380..8b85e93496ae 100644 --- a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java +++ b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java @@ -40,14 +40,14 @@ public class PropertiesFeatureToggleVersionTest { @Test - public void testNullPropertiesPassed() throws Exception { + public void testNullPropertiesPassed() { assertThrows(IllegalArgumentException.class, () -> { new PropertiesFeatureToggleVersion(null); }); } @Test - public void testNonBooleanProperty() throws Exception { + public void testNonBooleanProperty() { assertThrows(IllegalArgumentException.class, () -> { final Properties properties = new Properties(); properties.setProperty("enhancedWelcome", "Something"); @@ -56,7 +56,7 @@ public void testNonBooleanProperty() throws Exception { } @Test - public void testFeatureTurnedOn() throws Exception { + public void testFeatureTurnedOn() { final Properties properties = new Properties(); properties.put("enhancedWelcome", true); Service service = new PropertiesFeatureToggleVersion(properties); @@ -66,7 +66,7 @@ public void testFeatureTurnedOn() throws Exception { } @Test - public void testFeatureTurnedOff() throws Exception { + public void testFeatureTurnedOff() { final Properties properties = new Properties(); properties.put("enhancedWelcome", false); Service service = new PropertiesFeatureToggleVersion(properties); diff --git a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersionTest.java b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersionTest.java index 0ed0afea96a3..4755d569e09e 100644 --- a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersionTest.java +++ b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersionTest.java @@ -41,27 +41,27 @@ public class TieredFeatureToggleVersionTest { final Service service = new TieredFeatureToggleVersion(); @BeforeEach - public void setUp() throws Exception { + public void setUp() { UserGroup.addUserToPaidGroup(paidUser); UserGroup.addUserToFreeGroup(freeUser); } @Test - public void testGetWelcomeMessageForPaidUser() throws Exception { + public void testGetWelcomeMessageForPaidUser() { final String welcomeMessage = service.getWelcomeMessage(paidUser); final String expected = "You're amazing Jamie Coder. Thanks for paying for this awesome software."; assertEquals(expected, welcomeMessage); } @Test - public void testGetWelcomeMessageForFreeUser() throws Exception { + public void testGetWelcomeMessageForFreeUser() { final String welcomeMessage = service.getWelcomeMessage(freeUser); final String expected = "I suppose you can use this software."; assertEquals(expected, welcomeMessage); } @Test - public void testIsEnhancedAlwaysTrueAsTiered() throws Exception { + public void testIsEnhancedAlwaysTrueAsTiered() { assertTrue(service.isEnhanced()); } } diff --git a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/simple/SimpleFluentIterable.java b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/simple/SimpleFluentIterable.java index fde259f9b03c..3ffde22cb1d9 100644 --- a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/simple/SimpleFluentIterable.java +++ b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/simple/SimpleFluentIterable.java @@ -171,11 +171,11 @@ public List asList() { /** * @return a FluentIterable from a given iterable. Calls the SimpleFluentIterable constructor. */ - public static final FluentIterable from(Iterable iterable) { + public static FluentIterable from(Iterable iterable) { return new SimpleFluentIterable<>(iterable); } - public static final FluentIterable fromCopyOf(Iterable iterable) { + public static FluentIterable fromCopyOf(Iterable iterable) { List copy = FluentIterable.copyToList(iterable); return new SimpleFluentIterable<>(copy); } diff --git a/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java b/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java index 0eb9e003a053..5a99b96edb3d 100644 --- a/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java +++ b/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java @@ -179,15 +179,15 @@ public void testMap() throws Exception { } @Test - public void testForEach() throws Exception { + public void testForEach() { final List integers = Arrays.asList(1, 2, 3); final Consumer consumer = mock(Consumer.class); createFluentIterable(integers).forEach(consumer); - verify(consumer, times(1)).accept(Integer.valueOf(1)); - verify(consumer, times(1)).accept(Integer.valueOf(2)); - verify(consumer, times(1)).accept(Integer.valueOf(3)); + verify(consumer, times(1)).accept(1); + verify(consumer, times(1)).accept(2); + verify(consumer, times(1)).accept(3); verifyNoMoreInteractions(consumer); } diff --git a/front-controller/src/main/java/com/iluwatar/front/controller/FrontController.java b/front-controller/src/main/java/com/iluwatar/front/controller/FrontController.java index 19f4a39f1812..5dc7f3287904 100644 --- a/front-controller/src/main/java/com/iluwatar/front/controller/FrontController.java +++ b/front-controller/src/main/java/com/iluwatar/front/controller/FrontController.java @@ -36,7 +36,7 @@ public void handleRequest(String request) { } private Command getCommand(String request) { - Class commandClass = getCommandClass(request); + Class commandClass = getCommandClass(request); try { return (Command) commandClass.newInstance(); } catch (Exception e) { @@ -44,8 +44,8 @@ private Command getCommand(String request) { } } - private static Class getCommandClass(String request) { - Class result; + private static Class getCommandClass(String request) { + Class result; try { result = Class.forName("com.iluwatar.front.controller." + request + "Command"); } catch (ClassNotFoundException e) { diff --git a/front-controller/src/test/java/com/iluwatar/front/controller/ApplicationExceptionTest.java b/front-controller/src/test/java/com/iluwatar/front/controller/ApplicationExceptionTest.java index ee13d47d706f..429b97abb083 100644 --- a/front-controller/src/test/java/com/iluwatar/front/controller/ApplicationExceptionTest.java +++ b/front-controller/src/test/java/com/iluwatar/front/controller/ApplicationExceptionTest.java @@ -34,7 +34,7 @@ public class ApplicationExceptionTest { @Test - public void testCause() throws Exception { + public void testCause() { final Exception cause = new Exception(); assertSame(cause, new ApplicationException(cause).getCause()); } diff --git a/guarded-suspension/src/test/java/com/iluwatar/guarded/suspension/GuardedQueueTest.java b/guarded-suspension/src/test/java/com/iluwatar/guarded/suspension/GuardedQueueTest.java index 2834bd4ef825..794c7e9086c6 100644 --- a/guarded-suspension/src/test/java/com/iluwatar/guarded/suspension/GuardedQueueTest.java +++ b/guarded-suspension/src/test/java/com/iluwatar/guarded/suspension/GuardedQueueTest.java @@ -41,7 +41,7 @@ public void testGet() { GuardedQueue g = new GuardedQueue(); ExecutorService executorService = Executors.newFixedThreadPool(2); executorService.submit(() -> value = g.get()); - executorService.submit(() -> g.put(Integer.valueOf(10))); + executorService.submit(() -> g.put(10)); executorService.shutdown(); try { executorService.awaitTermination(30, TimeUnit.SECONDS); diff --git a/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AppTest.java b/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AppTest.java index dea242f85a6c..d8c76b2814fb 100644 --- a/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AppTest.java +++ b/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AppTest.java @@ -34,7 +34,7 @@ public class AppTest { @Test - public void test() throws InterruptedException, ExecutionException { + public void test() { App.main(null); } } diff --git a/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AsynchronousServiceTest.java b/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AsynchronousServiceTest.java index a5496415e36b..c10d4df50615 100644 --- a/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AsynchronousServiceTest.java +++ b/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AsynchronousServiceTest.java @@ -22,6 +22,7 @@ */ package com.iluwatar.halfsynchalfasync; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -44,11 +45,17 @@ * @author Jeroen Meulemeester */ public class AsynchronousServiceTest { + private AsynchronousService service; + private AsyncTask task; + + @BeforeEach + public void setUp() { + service = new AsynchronousService(new LinkedBlockingQueue<>()); + task = mock(AsyncTask.class); + } @Test public void testPerfectExecution() throws Exception { - final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>()); - final AsyncTask task = mock(AsyncTask.class); final Object result = new Object(); when(task.call()).thenReturn(result); service.execute(task); @@ -65,8 +72,6 @@ public void testPerfectExecution() throws Exception { @Test public void testCallException() throws Exception { - final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>()); - final AsyncTask task = mock(AsyncTask.class); final IOException exception = new IOException(); when(task.call()).thenThrow(exception); service.execute(task); @@ -82,9 +87,7 @@ public void testCallException() throws Exception { } @Test - public void testPreCallException() throws Exception { - final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>()); - final AsyncTask task = mock(AsyncTask.class); + public void testPreCallException() { final IllegalStateException exception = new IllegalStateException(); doThrow(exception).when(task).onPreCall(); service.execute(task); diff --git a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java index 60b888dc7c1b..54ab90385244 100644 --- a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java +++ b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java @@ -22,9 +22,6 @@ */ package com.iluwatar.intercepting.filter; -import java.awt.BorderLayout; -import java.awt.GridLayout; - import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; @@ -33,6 +30,9 @@ import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; +import java.awt.BorderLayout; +import java.awt.GridLayout; /** * The Client class is responsible for handling the input and running them through filters inside the @@ -60,7 +60,7 @@ public class Client extends JFrame { // NOSONAR */ public Client() { super("Client System"); - setDefaultCloseOperation(EXIT_ON_CLOSE); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(300, 300); jl = new JLabel("RUNNING..."); jtFields = new JTextField[3]; diff --git a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Target.java b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Target.java index 6652d1eb49cb..c08503fa7e71 100644 --- a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Target.java +++ b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Target.java @@ -22,11 +22,6 @@ */ package com.iluwatar.intercepting.filter; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; @@ -34,7 +29,12 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; import javax.swing.table.DefaultTableModel; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** * This is where the requests are displayed after being validated by filters. @@ -47,7 +47,6 @@ public class Target extends JFrame { //NOSONAR private static final long serialVersionUID = 1L; private JTable jt; - private JScrollPane jsp; private DefaultTableModel dtm; private JButton del; @@ -56,7 +55,7 @@ public class Target extends JFrame { //NOSONAR */ public Target() { super("Order System"); - setDefaultCloseOperation(EXIT_ON_CLOSE); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(640, 480); dtm = new DefaultTableModel(new Object[] {"Name", "Contact Number", "Address", "Deposit Number", @@ -73,7 +72,7 @@ private void setup() { bot.setLayout(new BorderLayout()); bot.add(del, BorderLayout.EAST); add(bot, BorderLayout.SOUTH); - jsp = new JScrollPane(jt); + JScrollPane jsp = new JScrollPane(jt); jsp.setPreferredSize(new Dimension(500, 250)); add(jsp, BorderLayout.CENTER); diff --git a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterManagerTest.java b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterManagerTest.java index 74259c152a22..87846552c8e1 100644 --- a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterManagerTest.java +++ b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterManagerTest.java @@ -40,7 +40,7 @@ public class FilterManagerTest { @Test - public void testFilterRequest() throws Exception { + public void testFilterRequest() { final Target target = mock(Target.class); final FilterManager filterManager = new FilterManager(); assertEquals("RUNNING...", filterManager.filterRequest(mock(Order.class))); @@ -48,7 +48,7 @@ public void testFilterRequest() throws Exception { } @Test - public void testAddFilter() throws Exception { + public void testAddFilter() { final Target target = mock(Target.class); final FilterManager filterManager = new FilterManager(); diff --git a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterTest.java b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterTest.java index 43170af426f9..7af268550b8f 100644 --- a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterTest.java +++ b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterTest.java @@ -89,7 +89,7 @@ static List getTestData() { @ParameterizedTest @MethodSource("getTestData") - public void testExecute(Filter filter, Order order, String expectedResult) throws Exception { + public void testExecute(Filter filter, Order order, String expectedResult) { final String result = filter.execute(order); assertNotNull(result); assertEquals(expectedResult, result.trim()); @@ -97,7 +97,7 @@ public void testExecute(Filter filter, Order order, String expectedResult) throw @ParameterizedTest @MethodSource("getTestData") - public void testNext(Filter filter) throws Exception { + public void testNext(Filter filter) { assertNull(filter.getNext()); assertSame(filter, filter.getLast()); } diff --git a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/OrderTest.java b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/OrderTest.java index 3b03e45998a6..40213ba5e675 100644 --- a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/OrderTest.java +++ b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/OrderTest.java @@ -36,35 +36,35 @@ public class OrderTest { private static final String EXPECTED_VALUE = "test"; @Test - public void testSetName() throws Exception { + public void testSetName() { final Order order = new Order(); order.setName(EXPECTED_VALUE); assertEquals(EXPECTED_VALUE, order.getName()); } @Test - public void testSetContactNumber() throws Exception { + public void testSetContactNumber() { final Order order = new Order(); order.setContactNumber(EXPECTED_VALUE); assertEquals(EXPECTED_VALUE, order.getContactNumber()); } @Test - public void testSetAddress() throws Exception { + public void testSetAddress() { final Order order = new Order(); order.setAddress(EXPECTED_VALUE); assertEquals(EXPECTED_VALUE, order.getAddress()); } @Test - public void testSetDepositNumber() throws Exception { + public void testSetDepositNumber() { final Order order = new Order(); order.setDepositNumber(EXPECTED_VALUE); assertEquals(EXPECTED_VALUE, order.getDepositNumber()); } @Test - public void testSetOrder() throws Exception { + public void testSetOrder() { final Order order = new Order(); order.setOrderItem(EXPECTED_VALUE); assertEquals(EXPECTED_VALUE, order.getOrderItem()); diff --git a/iterator/src/test/java/com/iluwatar/iterator/bst/BstIteratorTest.java b/iterator/src/test/java/com/iluwatar/iterator/bst/BstIteratorTest.java index 0e69b341a316..81906333a308 100644 --- a/iterator/src/test/java/com/iluwatar/iterator/bst/BstIteratorTest.java +++ b/iterator/src/test/java/com/iluwatar/iterator/bst/BstIteratorTest.java @@ -50,49 +50,49 @@ void createTrees() { @Test void nextForEmptyTree() { - BstIterator iter = new BstIterator<>(emptyRoot); + BstIterator iter = new BstIterator<>(emptyRoot); assertThrows(NoSuchElementException.class, iter::next, "next() should throw an IllegalStateException if hasNext() is false."); } @Test void nextOverEntirePopulatedTree() { - BstIterator iter = new BstIterator<>(nonEmptyRoot); - assertEquals(1, iter.next().getVal(), "First Node is 1."); - assertEquals(3, iter.next().getVal(), "Second Node is 3."); - assertEquals(4, iter.next().getVal(), "Third Node is 4."); - assertEquals(5, iter.next().getVal(), "Fourth Node is 5."); - assertEquals(6, iter.next().getVal(), "Fifth Node is 6."); - assertEquals(7, iter.next().getVal(), "Sixth Node is 7."); + BstIterator iter = new BstIterator<>(nonEmptyRoot); + assertEquals(Integer.valueOf(1), iter.next().getVal(), "First Node is 1."); + assertEquals(Integer.valueOf(3), iter.next().getVal(), "Second Node is 3."); + assertEquals(Integer.valueOf(4), iter.next().getVal(), "Third Node is 4."); + assertEquals(Integer.valueOf(5), iter.next().getVal(), "Fourth Node is 5."); + assertEquals(Integer.valueOf(6), iter.next().getVal(), "Fifth Node is 6."); + assertEquals(Integer.valueOf(7), iter.next().getVal(), "Sixth Node is 7."); } @Test void hasNextForEmptyTree() { - BstIterator iter = new BstIterator<>(emptyRoot); + BstIterator iter = new BstIterator<>(emptyRoot); assertFalse(iter.hasNext(), "hasNext() should return false for empty tree."); } @Test void hasNextForPopulatedTree() { - BstIterator iter = new BstIterator<>(nonEmptyRoot); + BstIterator iter = new BstIterator<>(nonEmptyRoot); assertTrue(iter.hasNext(), "hasNext() should return true for populated tree."); } @Test void nextAndHasNextOverEntirePopulatedTree() { - BstIterator iter = new BstIterator<>(nonEmptyRoot); + BstIterator iter = new BstIterator<>(nonEmptyRoot); assertTrue(iter.hasNext(), "Iterator hasNext() should be true."); - assertEquals(1, iter.next().getVal(), "First Node is 1."); + assertEquals(Integer.valueOf(1), iter.next().getVal(), "First Node is 1."); assertTrue(iter.hasNext(), "Iterator hasNext() should be true."); - assertEquals(3, iter.next().getVal(), "Second Node is 3."); + assertEquals(Integer.valueOf(3), iter.next().getVal(), "Second Node is 3."); assertTrue(iter.hasNext(), "Iterator hasNext() should be true."); - assertEquals(4, iter.next().getVal(), "Third Node is 4."); + assertEquals(Integer.valueOf(4), iter.next().getVal(), "Third Node is 4."); assertTrue(iter.hasNext(), "Iterator hasNext() should be true."); - assertEquals(5, iter.next().getVal(), "Fourth Node is 5."); + assertEquals(Integer.valueOf(5), iter.next().getVal(), "Fourth Node is 5."); assertTrue(iter.hasNext(), "Iterator hasNext() should be true."); - assertEquals(6, iter.next().getVal(), "Fifth Node is 6."); + assertEquals(Integer.valueOf(6), iter.next().getVal(), "Fifth Node is 6."); assertTrue(iter.hasNext(), "Iterator hasNext() should be true."); - assertEquals(7, iter.next().getVal(), "Sixth Node is 7."); + assertEquals(Integer.valueOf(7), iter.next().getVal(), "Sixth Node is 7."); assertFalse(iter.hasNext(), "Iterator hasNext() should be false, end of tree."); } diff --git a/layers/src/main/java/com/iluwatar/layers/CakeViewImpl.java b/layers/src/main/java/com/iluwatar/layers/CakeViewImpl.java index 57bb0a561b0f..029f64bb6889 100644 --- a/layers/src/main/java/com/iluwatar/layers/CakeViewImpl.java +++ b/layers/src/main/java/com/iluwatar/layers/CakeViewImpl.java @@ -41,6 +41,6 @@ public CakeViewImpl(CakeBakingService cakeBakingService) { } public void render() { - cakeBakingService.getAllCakes().stream().forEach(cake -> LOGGER.info(cake.toString())); + cakeBakingService.getAllCakes().forEach(cake -> LOGGER.info(cake.toString())); } } diff --git a/layers/src/test/java/com/iluwatar/layers/CakeBakingExceptionTest.java b/layers/src/test/java/com/iluwatar/layers/CakeBakingExceptionTest.java index e13e148a3723..481915c63fda 100644 --- a/layers/src/test/java/com/iluwatar/layers/CakeBakingExceptionTest.java +++ b/layers/src/test/java/com/iluwatar/layers/CakeBakingExceptionTest.java @@ -35,14 +35,14 @@ public class CakeBakingExceptionTest { @Test - public void testConstructor() throws Exception { + public void testConstructor() { final CakeBakingException exception = new CakeBakingException(); assertNull(exception.getMessage()); assertNull(exception.getCause()); } @Test - public void testConstructorWithMessage() throws Exception { + public void testConstructorWithMessage() { final String expectedMessage = "message"; final CakeBakingException exception = new CakeBakingException(expectedMessage); assertEquals(expectedMessage, exception.getMessage()); diff --git a/layers/src/test/java/com/iluwatar/layers/CakeBakingServiceImplTest.java b/layers/src/test/java/com/iluwatar/layers/CakeBakingServiceImplTest.java index f740fb5f4691..b325b9328555 100644 --- a/layers/src/test/java/com/iluwatar/layers/CakeBakingServiceImplTest.java +++ b/layers/src/test/java/com/iluwatar/layers/CakeBakingServiceImplTest.java @@ -42,7 +42,7 @@ public class CakeBakingServiceImplTest { @Test - public void testLayers() throws CakeBakingException { + public void testLayers() { final CakeBakingServiceImpl service = new CakeBakingServiceImpl(); final List initialLayers = service.getAvailableLayers(); @@ -65,7 +65,7 @@ public void testLayers() throws CakeBakingException { } @Test - public void testToppings() throws CakeBakingException { + public void testToppings() { final CakeBakingServiceImpl service = new CakeBakingServiceImpl(); final List initialToppings = service.getAvailableToppings(); @@ -125,7 +125,7 @@ public void testBakeCakes() throws CakeBakingException { } @Test - public void testBakeCakeMissingTopping() throws CakeBakingException { + public void testBakeCakeMissingTopping() { final CakeBakingServiceImpl service = new CakeBakingServiceImpl(); final CakeLayerInfo layer1 = new CakeLayerInfo("Layer1", 1000); @@ -140,7 +140,7 @@ public void testBakeCakeMissingTopping() throws CakeBakingException { } @Test - public void testBakeCakeMissingLayer() throws CakeBakingException { + public void testBakeCakeMissingLayer() { final CakeBakingServiceImpl service = new CakeBakingServiceImpl(); final List initialCakes = service.getAllCakes(); diff --git a/layers/src/test/java/com/iluwatar/layers/CakeTest.java b/layers/src/test/java/com/iluwatar/layers/CakeTest.java index f71a0b35d4ce..60749287e0b2 100644 --- a/layers/src/test/java/com/iluwatar/layers/CakeTest.java +++ b/layers/src/test/java/com/iluwatar/layers/CakeTest.java @@ -44,7 +44,7 @@ public void testSetId() { final Cake cake = new Cake(); assertNull(cake.getId()); - final Long expectedId = Long.valueOf(1234L); + final Long expectedId = 1234L; cake.setId(expectedId); assertEquals(expectedId, cake.getId()); } diff --git a/lazy-loading/src/main/java/com/iluwatar/lazy/loading/Java8Holder.java b/lazy-loading/src/main/java/com/iluwatar/lazy/loading/Java8Holder.java index faa553c5eb36..7b7a933d43f0 100644 --- a/lazy-loading/src/main/java/com/iluwatar/lazy/loading/Java8Holder.java +++ b/lazy-loading/src/main/java/com/iluwatar/lazy/loading/Java8Holder.java @@ -37,7 +37,7 @@ public class Java8Holder { private static final Logger LOGGER = LoggerFactory.getLogger(Java8Holder.class); - private Supplier heavy = () -> createAndCacheHeavy(); + private Supplier heavy = this::createAndCacheHeavy; public Java8Holder() { LOGGER.info("Java8Holder created"); diff --git a/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java b/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java index bdae597bc2e4..4352b48ebb02 100644 --- a/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java +++ b/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java @@ -27,6 +27,7 @@ import java.io.IOException; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * The Module pattern can be considered a Creational pattern and a Structural pattern. It manages @@ -88,7 +89,7 @@ public void testNoFileMessage() throws IOException { fileLoggerModule.prepare(); /* Test if nothing is printed in file */ - assertEquals(readFirstLine(OUTPUT_FILE), null); + assertNull(readFirstLine(OUTPUT_FILE)); /* Unprepare to cleanup the modules */ fileLoggerModule.unprepare(); @@ -113,7 +114,7 @@ public void testFileErrorMessage() throws FileNotFoundException { fileLoggerModule.printErrorString(ERROR); /* Test if 'Message' is printed in file */ - assertEquals(readFirstLine(ERROR_FILE), ERROR); + assertEquals(ERROR, readFirstLine(ERROR_FILE)); /* Unprepare to cleanup the modules */ fileLoggerModule.unprepare(); @@ -135,7 +136,7 @@ public void testNoFileErrorMessage() throws FileNotFoundException { fileLoggerModule.prepare(); /* Test if nothing is printed in file */ - assertEquals(readFirstLine(ERROR_FILE), null); + assertNull(readFirstLine(ERROR_FILE)); /* Unprepare to cleanup the modules */ fileLoggerModule.unprepare(); @@ -150,11 +151,7 @@ public void testNoFileErrorMessage() throws FileNotFoundException { private static final String readFirstLine(final String file) { String firstLine = null; - BufferedReader bufferedReader = null; - try { - - /* Create a buffered reader */ - bufferedReader = new BufferedReader(new FileReader(file)); + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { while (bufferedReader.ready()) { @@ -166,15 +163,6 @@ private static final String readFirstLine(final String file) { } catch (final IOException e) { LOGGER.error("ModuleTest::readFirstLine()", e); - } finally { - - if (bufferedReader != null) { - try { - bufferedReader.close(); - } catch (final IOException e) { - LOGGER.error("ModuleTest::readFirstLine()", e); - } - } } return firstLine; diff --git a/monostate/src/main/java/com/iluwatar/monostate/LoadBalancer.java b/monostate/src/main/java/com/iluwatar/monostate/LoadBalancer.java index b280de76702d..8a9870531a0f 100644 --- a/monostate/src/main/java/com/iluwatar/monostate/LoadBalancer.java +++ b/monostate/src/main/java/com/iluwatar/monostate/LoadBalancer.java @@ -34,33 +34,31 @@ */ public class LoadBalancer { - private static List servers = new ArrayList<>(); + private static final List SERVERS = new ArrayList<>(); private static int lastServedId; static { int id = 0; - servers.add(new Server("localhost", 8081, ++id)); - servers.add(new Server("localhost", 8080, ++id)); - servers.add(new Server("localhost", 8082, ++id)); - servers.add(new Server("localhost", 8083, ++id)); - servers.add(new Server("localhost", 8084, ++id)); + for (int port : new int[] {8080, 8081, 8082, 8083, 8084}) { + SERVERS.add(new Server("localhost", port, ++id)); + } } /** * Add new server */ public final void addServer(Server server) { - synchronized (servers) { - servers.add(server); + synchronized (SERVERS) { + SERVERS.add(server); } } public final int getNoOfServers() { - return servers.size(); + return SERVERS.size(); } - public static int getLastServedId() { + public int getLastServedId() { return lastServedId; } @@ -68,10 +66,10 @@ public static int getLastServedId() { * Handle request */ public synchronized void serverRequest(Request request) { - if (lastServedId >= servers.size()) { + if (lastServedId >= SERVERS.size()) { lastServedId = 0; } - Server server = servers.get(lastServedId++); + Server server = SERVERS.get(lastServedId++); server.serve(request); } diff --git a/monostate/src/test/java/com/iluwatar/monostate/LoadBalancerTest.java b/monostate/src/test/java/com/iluwatar/monostate/LoadBalancerTest.java index 51cbcdecd831..285e1db2c250 100644 --- a/monostate/src/test/java/com/iluwatar/monostate/LoadBalancerTest.java +++ b/monostate/src/test/java/com/iluwatar/monostate/LoadBalancerTest.java @@ -22,9 +22,7 @@ */ package com.iluwatar.monostate; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; @@ -34,6 +32,8 @@ import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import org.junit.jupiter.api.Test; + /** * Date: 12/21/15 - 12:26 PM * @@ -47,9 +47,9 @@ public void testSameStateAmongstAllInstances() { final LoadBalancer secondBalancer = new LoadBalancer(); firstBalancer.addServer(new Server("localhost", 8085, 6)); // Both should have the same number of servers. - assertTrue(firstBalancer.getNoOfServers() == secondBalancer.getNoOfServers()); + assertEquals(firstBalancer.getNoOfServers(), secondBalancer.getNoOfServers()); // Both Should have the same LastServedId - assertTrue(firstBalancer.getLastServedId() == secondBalancer.getLastServedId()); + assertEquals(firstBalancer.getLastServedId(), secondBalancer.getLastServedId()); } @Test diff --git a/mute-idiom/src/test/java/com/iluwatar/mute/MuteTest.java b/mute-idiom/src/test/java/com/iluwatar/mute/MuteTest.java index 73bab01d2210..07498645e83c 100644 --- a/mute-idiom/src/test/java/com/iluwatar/mute/MuteTest.java +++ b/mute-idiom/src/test/java/com/iluwatar/mute/MuteTest.java @@ -45,27 +45,27 @@ public class MuteTest { @Test public void muteShouldRunTheCheckedRunnableAndNotThrowAnyExceptionIfCheckedRunnableDoesNotThrowAnyException() { - Mute.mute(() -> methodNotThrowingAnyException()); + Mute.mute(this::methodNotThrowingAnyException); } @Test - public void muteShouldRethrowUnexpectedExceptionAsAssertionError() throws Exception { + public void muteShouldRethrowUnexpectedExceptionAsAssertionError() { assertThrows(AssertionError.class, () -> { - Mute.mute(() -> methodThrowingException()); + Mute.mute(this::methodThrowingException); }); } @Test public void loggedMuteShouldRunTheCheckedRunnableAndNotThrowAnyExceptionIfCheckedRunnableDoesNotThrowAnyException() { - Mute.loggedMute(() -> methodNotThrowingAnyException()); + Mute.loggedMute(this::methodNotThrowingAnyException); } @Test - public void loggedMuteShouldLogExceptionTraceBeforeSwallowingIt() throws IOException { + public void loggedMuteShouldLogExceptionTraceBeforeSwallowingIt() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); System.setErr(new PrintStream(stream)); - Mute.loggedMute(() -> methodThrowingException()); + Mute.loggedMute(this::methodThrowingException); assertTrue(new String(stream.toByteArray()).contains(MESSAGE)); } diff --git a/null-object/src/test/java/com/iluwatar/nullobject/NullNodeTest.java b/null-object/src/test/java/com/iluwatar/nullobject/NullNodeTest.java index 0482b7f89218..c7b4aa5fb430 100644 --- a/null-object/src/test/java/com/iluwatar/nullobject/NullNodeTest.java +++ b/null-object/src/test/java/com/iluwatar/nullobject/NullNodeTest.java @@ -56,7 +56,7 @@ public void testFields() { } @Test - public void testWalk() throws Exception { + public void testWalk() { NullNode.getInstance().walk(); } diff --git a/null-object/src/test/java/com/iluwatar/nullobject/TreeTest.java b/null-object/src/test/java/com/iluwatar/nullobject/TreeTest.java index f0cdbf0c9264..2177c6932fed 100644 --- a/null-object/src/test/java/com/iluwatar/nullobject/TreeTest.java +++ b/null-object/src/test/java/com/iluwatar/nullobject/TreeTest.java @@ -110,7 +110,7 @@ public void testWalk() { } @Test - public void testGetLeft() throws Exception { + public void testGetLeft() { final Node level1 = TREE_ROOT.getLeft(); assertNotNull(level1); assertEquals("level1_a", level1.getName()); @@ -130,7 +130,7 @@ public void testGetLeft() throws Exception { } @Test - public void testGetRight() throws Exception { + public void testGetRight() { final Node level1 = TREE_ROOT.getRight(); assertNotNull(level1); assertEquals("level1_b", level1.getName()); diff --git a/object-mother/src/main/java/com/iluwatar/objectmother/King.java b/object-mother/src/main/java/com/iluwatar/objectmother/King.java index b1b5f36100f0..48126265e1a2 100644 --- a/object-mother/src/main/java/com/iluwatar/objectmother/King.java +++ b/object-mother/src/main/java/com/iluwatar/objectmother/King.java @@ -59,7 +59,7 @@ public boolean isHappy() { */ public void flirt(Queen queen) { boolean flirtStatus = queen.getFlirted(this); - if (flirtStatus == false) { + if (!flirtStatus) { this.makeUnhappy(); } else { this.makeHappy(); diff --git a/object-pool/src/main/java/com/iluwatar/object/pool/Oliphaunt.java b/object-pool/src/main/java/com/iluwatar/object/pool/Oliphaunt.java index cc705b2b3698..c4d1aec3eb47 100644 --- a/object-pool/src/main/java/com/iluwatar/object/pool/Oliphaunt.java +++ b/object-pool/src/main/java/com/iluwatar/object/pool/Oliphaunt.java @@ -22,6 +22,8 @@ */ package com.iluwatar.object.pool; +import java.util.concurrent.atomic.AtomicInteger; + /** * * Oliphaunts are expensive to create @@ -29,7 +31,7 @@ */ public class Oliphaunt { - private static int counter = 1; + private static AtomicInteger counter = new AtomicInteger(0); private final int id; @@ -37,7 +39,7 @@ public class Oliphaunt { * Constructor */ public Oliphaunt() { - id = counter++; + id = counter.incrementAndGet(); try { Thread.sleep(1000); } catch (InterruptedException e) { diff --git a/object-pool/src/test/java/com/iluwatar/object/pool/OliphauntPoolTest.java b/object-pool/src/test/java/com/iluwatar/object/pool/OliphauntPoolTest.java index e92709fca491..18ab77c1ffcf 100644 --- a/object-pool/src/test/java/com/iluwatar/object/pool/OliphauntPoolTest.java +++ b/object-pool/src/test/java/com/iluwatar/object/pool/OliphauntPoolTest.java @@ -49,23 +49,23 @@ public class OliphauntPoolTest { public void testSubsequentCheckinCheckout() { assertTimeout(ofMillis(5000), () -> { final OliphauntPool pool = new OliphauntPool(); - assertEquals(pool.toString(), "Pool available=0 inUse=0"); + assertEquals("Pool available=0 inUse=0", pool.toString()); final Oliphaunt expectedOliphaunt = pool.checkOut(); - assertEquals(pool.toString(), "Pool available=0 inUse=1"); + assertEquals("Pool available=0 inUse=1", pool.toString()); pool.checkIn(expectedOliphaunt); - assertEquals(pool.toString(), "Pool available=1 inUse=0"); + assertEquals("Pool available=1 inUse=0", pool.toString()); for (int i = 0; i < 100; i++) { final Oliphaunt oliphaunt = pool.checkOut(); - assertEquals(pool.toString(), "Pool available=0 inUse=1"); + assertEquals("Pool available=0 inUse=1", pool.toString()); assertSame(expectedOliphaunt, oliphaunt); assertEquals(expectedOliphaunt.getId(), oliphaunt.getId()); assertEquals(expectedOliphaunt.toString(), oliphaunt.toString()); pool.checkIn(oliphaunt); - assertEquals(pool.toString(), "Pool available=1 inUse=0"); + assertEquals("Pool available=1 inUse=0", pool.toString()); } }); } diff --git a/observer/src/test/java/com/iluwatar/observer/generic/ObserverTest.java b/observer/src/test/java/com/iluwatar/observer/generic/ObserverTest.java index 7b0c65ea5d7e..8bb9c1ef0eb4 100644 --- a/observer/src/test/java/com/iluwatar/observer/generic/ObserverTest.java +++ b/observer/src/test/java/com/iluwatar/observer/generic/ObserverTest.java @@ -42,7 +42,7 @@ * @author Jeroen Meulemeester */ @TestInstance(TestInstance.Lifecycle.PER_CLASS) -public abstract class ObserverTest { +public abstract class ObserverTest> { private InMemoryAppender appender; diff --git a/poison-pill/src/test/java/com/iluwatar/poison/pill/PoisonMessageTest.java b/poison-pill/src/test/java/com/iluwatar/poison/pill/PoisonMessageTest.java index 334c49809a26..b9200390b225 100644 --- a/poison-pill/src/test/java/com/iluwatar/poison/pill/PoisonMessageTest.java +++ b/poison-pill/src/test/java/com/iluwatar/poison/pill/PoisonMessageTest.java @@ -36,38 +36,34 @@ public class PoisonMessageTest { @Test - public void testAddHeader() throws Exception { + public void testAddHeader() { assertThrows(UnsupportedOperationException.class, () -> { POISON_PILL.addHeader(Headers.SENDER, "sender"); }); } @Test - public void testGetHeader() throws Exception { + public void testGetHeader() { assertThrows(UnsupportedOperationException.class, () -> { POISON_PILL.getHeader(Headers.SENDER); }); } @Test - public void testGetHeaders() throws Exception { - assertThrows(UnsupportedOperationException.class, () -> { - POISON_PILL.getHeaders(); - }); + public void testGetHeaders() { + assertThrows(UnsupportedOperationException.class, POISON_PILL::getHeaders); } @Test - public void testSetBody() throws Exception { + public void testSetBody() { assertThrows(UnsupportedOperationException.class, () -> { POISON_PILL.setBody("Test message."); }); } @Test - public void testGetBody() throws Exception { - assertThrows(UnsupportedOperationException.class, () -> { - POISON_PILL.getBody(); - }); + public void testGetBody() { + assertThrows(UnsupportedOperationException.class, POISON_PILL::getBody); } } diff --git a/producer-consumer/src/test/java/com/iluwatar/producer/consumer/ProducerTest.java b/producer-consumer/src/test/java/com/iluwatar/producer/consumer/ProducerTest.java index c8fe60e094e8..8a6539d87a7a 100644 --- a/producer-consumer/src/test/java/com/iluwatar/producer/consumer/ProducerTest.java +++ b/producer-consumer/src/test/java/com/iluwatar/producer/consumer/ProducerTest.java @@ -39,7 +39,7 @@ public class ProducerTest { @Test - public void testProduce() throws Exception { + public void testProduce() { assertTimeout(ofMillis(6000), () -> { final ItemQueue queue = mock(ItemQueue.class); final Producer producer = new Producer("producer", queue); diff --git a/promise/src/main/java/com/iluwatar/promise/App.java b/promise/src/main/java/com/iluwatar/promise/App.java index dd40ec15b450..c0cadecb719e 100644 --- a/promise/src/main/java/com/iluwatar/promise/App.java +++ b/promise/src/main/java/com/iluwatar/promise/App.java @@ -155,19 +155,15 @@ private Promise countLines() { * This is an async method and does not wait until the file is downloaded. */ private Promise download(String urlString) { - Promise downloadPromise = new Promise() + return new Promise() .fulfillInAsync( - () -> { - return Utility.downloadFile(urlString); - }, executor) + () -> Utility.downloadFile(urlString), executor) .onError( throwable -> { throwable.printStackTrace(); taskCompleted(); } ); - - return downloadPromise; } private void stop() throws InterruptedException { diff --git a/promise/src/main/java/com/iluwatar/promise/Utility.java b/promise/src/main/java/com/iluwatar/promise/Utility.java index 41e07be4593e..f40844f08009 100644 --- a/promise/src/main/java/com/iluwatar/promise/Utility.java +++ b/promise/src/main/java/com/iluwatar/promise/Utility.java @@ -32,7 +32,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; -import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.Iterator; @@ -111,7 +110,7 @@ public static Integer countLines(String fileLocation) { * Downloads the contents from the given urlString, and stores it in a temporary directory. * @return the absolute path of the file downloaded. */ - public static String downloadFile(String urlString) throws MalformedURLException, IOException { + public static String downloadFile(String urlString) throws IOException { LOGGER.info("Downloading contents from url: {}", urlString); URL url = new URL(urlString); File file = File.createTempFile("promise_pattern", null); diff --git a/promise/src/test/java/com/iluwatar/promise/PromiseTest.java b/promise/src/test/java/com/iluwatar/promise/PromiseTest.java index 68868bd1e3ef..5b013217081e 100644 --- a/promise/src/test/java/com/iluwatar/promise/PromiseTest.java +++ b/promise/src/test/java/com/iluwatar/promise/PromiseTest.java @@ -76,12 +76,8 @@ public void promiseIsFulfilledWithAnExceptionIfTaskThrowsAnException() private void testWaitingForeverForPromiseToBeFulfilled() throws InterruptedException, TimeoutException { Promise promise = new Promise<>(); - promise.fulfillInAsync(new Callable() { - - @Override - public Integer call() throws Exception { - throw new RuntimeException("Barf!"); - } + promise.fulfillInAsync(() -> { + throw new RuntimeException("Barf!"); }, executor); try { @@ -104,12 +100,8 @@ public Integer call() throws Exception { private void testWaitingSomeTimeForPromiseToBeFulfilled() throws InterruptedException, TimeoutException { Promise promise = new Promise<>(); - promise.fulfillInAsync(new Callable() { - - @Override - public Integer call() throws Exception { - throw new RuntimeException("Barf!"); - } + promise.fulfillInAsync(() -> { + throw new RuntimeException("Barf!"); }, executor); try { @@ -150,12 +142,8 @@ public void dependentPromiseIsFulfilledWithAnExceptionIfConsumerThrowsAnExceptio throws InterruptedException, ExecutionException, TimeoutException { Promise dependentPromise = promise .fulfillInAsync(new NumberCrunchingTask(), executor) - .thenAccept(new Consumer() { - - @Override - public void accept(Integer value) { - throw new RuntimeException("Barf!"); - } + .thenAccept(value -> { + throw new RuntimeException("Barf!"); }); try { @@ -198,12 +186,8 @@ public void dependentPromiseIsFulfilledWithAnExceptionIfTheFunctionThrowsExcepti throws InterruptedException, ExecutionException, TimeoutException { Promise dependentPromise = promise .fulfillInAsync(new NumberCrunchingTask(), executor) - .thenApply(new Function() { - - @Override - public String apply(Integer value) { - throw new RuntimeException("Barf!"); - } + .thenApply(value -> { + throw new RuntimeException("Barf!"); }); try { diff --git a/property/src/test/java/com/iluwatar/property/CharacterTest.java b/property/src/test/java/com/iluwatar/property/CharacterTest.java index 95a66a2fbe34..dd00d158b7b2 100644 --- a/property/src/test/java/com/iluwatar/property/CharacterTest.java +++ b/property/src/test/java/com/iluwatar/property/CharacterTest.java @@ -73,7 +73,7 @@ public void testCharacterStats() throws Exception { } @Test - public void testToString() throws Exception { + public void testToString() { final Character prototype = new Character(); prototype.set(Stats.ARMOR, 1); prototype.set(Stats.AGILITY, 2); @@ -91,7 +91,7 @@ public void testToString() throws Exception { } @Test - public void testName() throws Exception { + public void testName() { final Character prototype = new Character(); prototype.set(Stats.ARMOR, 1); prototype.set(Stats.INTELLECT, 2); @@ -107,7 +107,7 @@ public void testName() throws Exception { } @Test - public void testType() throws Exception { + public void testType() { final Character prototype = new Character(); prototype.set(Stats.ARMOR, 1); prototype.set(Stats.INTELLECT, 2); diff --git a/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java b/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java index ec90b14b282d..414c61a7ea5b 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java +++ b/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java @@ -40,7 +40,7 @@ public ElfBeast(ElfBeast elfBeast) { } @Override - public Beast copy() throws CloneNotSupportedException { + public Beast copy() { return new ElfBeast(this); } diff --git a/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java b/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java index 7a3e22b1228e..af29b301b2c2 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java +++ b/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java @@ -41,7 +41,7 @@ public ElfMage(ElfMage elfMage) { } @Override - public ElfMage copy() throws CloneNotSupportedException { + public ElfMage copy() { return new ElfMage(this); } diff --git a/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java b/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java index f4aa42012809..1de0687c399f 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java +++ b/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java @@ -40,7 +40,7 @@ public ElfWarlord(ElfWarlord elfWarlord) { } @Override - public ElfWarlord copy() throws CloneNotSupportedException { + public ElfWarlord copy() { return new ElfWarlord(this); } diff --git a/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java b/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java index 07a19f970041..92960a36d654 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java +++ b/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java @@ -40,7 +40,7 @@ public OrcBeast(OrcBeast orcBeast) { } @Override - public Beast copy() throws CloneNotSupportedException { + public Beast copy() { return new OrcBeast(this); } diff --git a/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java b/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java index e662dd44bf49..ace2664c5629 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java +++ b/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java @@ -40,7 +40,7 @@ public OrcMage(OrcMage orcMage) { } @Override - public OrcMage copy() throws CloneNotSupportedException { + public OrcMage copy() { return new OrcMage(this); } diff --git a/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java b/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java index 697ec0b7e826..e46117b02d6b 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java +++ b/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java @@ -40,7 +40,7 @@ public OrcWarlord(OrcWarlord orcWarlord) { } @Override - public OrcWarlord copy() throws CloneNotSupportedException { + public OrcWarlord copy() { return new OrcWarlord(this); } diff --git a/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/App.java b/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/App.java index f71d30c16abf..fd9f020d4781 100644 --- a/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/App.java +++ b/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/App.java @@ -110,8 +110,6 @@ public static void main(String[] args) { LOGGER.info("Executor was shut down and Exiting."); executor.shutdownNow(); } - } catch (InterruptedException ie) { - LOGGER.error(ie.getMessage()); } catch (Exception e) { LOGGER.error(e.getMessage()); } diff --git a/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/ServiceExecutor.java b/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/ServiceExecutor.java index 2b423ffafa4f..416e72ad7c9b 100644 --- a/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/ServiceExecutor.java +++ b/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/ServiceExecutor.java @@ -58,8 +58,6 @@ public void run() { Thread.sleep(1000); } - } catch (InterruptedException ie) { - LOGGER.error(ie.getMessage()); } catch (Exception e) { LOGGER.error(e.getMessage()); } diff --git a/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/TaskGenerator.java b/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/TaskGenerator.java index e99e918dbe4b..2e152b98f7f4 100644 --- a/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/TaskGenerator.java +++ b/queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/TaskGenerator.java @@ -80,8 +80,6 @@ public void run() { // Make the current thread to sleep after every Message submission. Thread.sleep(1000); } - } catch (InterruptedException ie) { - LOGGER.error(ie.getMessage()); } catch (Exception e) { LOGGER.error(e.getMessage()); } diff --git a/queue-load-leveling/src/test/java/com/iluwatar/queue/load/leveling/MessageQueueTest.java b/queue-load-leveling/src/test/java/com/iluwatar/queue/load/leveling/MessageQueueTest.java index 13a1db70667b..1b7252989204 100644 --- a/queue-load-leveling/src/test/java/com/iluwatar/queue/load/leveling/MessageQueueTest.java +++ b/queue-load-leveling/src/test/java/com/iluwatar/queue/load/leveling/MessageQueueTest.java @@ -42,7 +42,7 @@ public void messageQueueTest() { msgQueue.submitMsg(new Message("MessageQueue Test")); // retrieve message - assertEquals(msgQueue.retrieveMsg().getMsg(), "MessageQueue Test"); + assertEquals("MessageQueue Test", msgQueue.retrieveMsg().getMsg()); } } diff --git a/queue-load-leveling/src/test/java/com/iluwatar/queue/load/leveling/MessageTest.java b/queue-load-leveling/src/test/java/com/iluwatar/queue/load/leveling/MessageTest.java index d6b0167cf048..3738ad150e83 100644 --- a/queue-load-leveling/src/test/java/com/iluwatar/queue/load/leveling/MessageTest.java +++ b/queue-load-leveling/src/test/java/com/iluwatar/queue/load/leveling/MessageTest.java @@ -39,6 +39,6 @@ public void messageTest() { // Parameterized constructor test. String testMsg = "Message Test"; Message msg = new Message(testMsg); - assertEquals(msg.getMsg(), testMsg); + assertEquals(testMsg, msg.getMsg()); } } diff --git a/repository/src/test/java/com/iluwatar/repository/AppConfigTest.java b/repository/src/test/java/com/iluwatar/repository/AppConfigTest.java index 882d2bef7272..3fb1b427b232 100644 --- a/repository/src/test/java/com/iluwatar/repository/AppConfigTest.java +++ b/repository/src/test/java/com/iluwatar/repository/AppConfigTest.java @@ -22,14 +22,6 @@ */ package com.iluwatar.repository; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import javax.sql.DataSource; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +30,13 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader; import org.springframework.transaction.annotation.Transactional; +import javax.sql.DataSource; +import java.sql.ResultSet; +import java.sql.SQLException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * This case is Just for test the Annotation Based configuration * @@ -70,7 +69,7 @@ public void testQuery() throws SQLException { result = resultSet.getString(1); } - assertTrue(result.equals(expected)); + assertEquals(expected, result); } } diff --git a/repository/src/test/java/com/iluwatar/repository/AppTest.java b/repository/src/test/java/com/iluwatar/repository/AppTest.java index 17052b51e543..e25f7dd01a7a 100644 --- a/repository/src/test/java/com/iluwatar/repository/AppTest.java +++ b/repository/src/test/java/com/iluwatar/repository/AppTest.java @@ -31,7 +31,7 @@ */ public class AppTest { @Test - public void test() throws IOException { + public void test() { String[] args = {}; App.main(args); } diff --git a/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java b/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java index 6a347ffd4387..5b4b8e80c055 100644 --- a/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java +++ b/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java @@ -109,9 +109,7 @@ public void testFindAllByAgeBetweenSpec() { List persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40)); assertEquals(3, persons.size()); - assertTrue(persons.stream().allMatch((item) -> { - return item.getAge() > 20 && item.getAge() < 40; - })); + assertTrue(persons.stream().allMatch(item -> item.getAge() > 20 && item.getAge() < 40)); } @Test diff --git a/retry/src/test/java/com/iluwatar/retry/FindCustomerTest.java b/retry/src/test/java/com/iluwatar/retry/FindCustomerTest.java index 46c4c62e6e3e..5c0cc66ed36b 100644 --- a/retry/src/test/java/com/iluwatar/retry/FindCustomerTest.java +++ b/retry/src/test/java/com/iluwatar/retry/FindCustomerTest.java @@ -53,7 +53,7 @@ public void noExceptions() throws Exception { * @throws Exception the expected exception */ @Test - public void oneException() throws Exception { + public void oneException() { assertThrows(BusinessException.class, () -> { new FindCustomer("123", new BusinessException("test")).perform(); }); diff --git a/retry/src/test/java/com/iluwatar/retry/RetryTest.java b/retry/src/test/java/com/iluwatar/retry/RetryTest.java index 233e0e58837b..a8307d1cd9f3 100644 --- a/retry/src/test/java/com/iluwatar/retry/RetryTest.java +++ b/retry/src/test/java/com/iluwatar/retry/RetryTest.java @@ -40,7 +40,7 @@ public class RetryTest { * Should contain all errors thrown. */ @Test - public void errors() throws Exception { + public void errors() { final BusinessException e = new BusinessException("unhandled"); final Retry retry = new Retry<>( () -> { throw e; }, diff --git a/semaphore/src/test/java/com/iluwatar/semaphore/AppTest.java b/semaphore/src/test/java/com/iluwatar/semaphore/AppTest.java index 6ad023e5d130..8f31fb5dec51 100644 --- a/semaphore/src/test/java/com/iluwatar/semaphore/AppTest.java +++ b/semaphore/src/test/java/com/iluwatar/semaphore/AppTest.java @@ -31,7 +31,7 @@ */ public class AppTest { @Test - public void test() throws IOException { + public void test() { String[] args = {}; App.main(args); } diff --git a/semaphore/src/test/java/com/iluwatar/semaphore/FruitBowlTest.java b/semaphore/src/test/java/com/iluwatar/semaphore/FruitBowlTest.java index 7bc391478d53..ea17319fc16a 100644 --- a/semaphore/src/test/java/com/iluwatar/semaphore/FruitBowlTest.java +++ b/semaphore/src/test/java/com/iluwatar/semaphore/FruitBowlTest.java @@ -37,16 +37,16 @@ public class FruitBowlTest { public void fruitBowlTest() { FruitBowl fbowl = new FruitBowl(); - assertEquals(fbowl.countFruit(), 0); + assertEquals(0, fbowl.countFruit()); for (int i = 1; i <= 10; i++) { fbowl.put(new Fruit(Fruit.FruitType.LEMON)); - assertEquals(fbowl.countFruit(), i); + assertEquals(i, fbowl.countFruit()); } for (int i = 9; i >= 0; i--) { assertNotNull(fbowl.take()); - assertEquals(fbowl.countFruit(), i); + assertEquals(i, fbowl.countFruit()); } assertNull(fbowl.take()); diff --git a/semaphore/src/test/java/com/iluwatar/semaphore/SemaphoreTest.java b/semaphore/src/test/java/com/iluwatar/semaphore/SemaphoreTest.java index ad67026ae7ce..79af70af626e 100644 --- a/semaphore/src/test/java/com/iluwatar/semaphore/SemaphoreTest.java +++ b/semaphore/src/test/java/com/iluwatar/semaphore/SemaphoreTest.java @@ -36,12 +36,12 @@ public class SemaphoreTest { public void acquireReleaseTest() { Semaphore sphore = new Semaphore(3); - assertEquals(sphore.getAvailableLicenses(), 3); + assertEquals(3, sphore.getAvailableLicenses()); for (int i = 2; i >= 0; i--) { try { sphore.acquire(); - assertEquals(sphore.getAvailableLicenses(), i); + assertEquals(i, sphore.getAvailableLicenses()); } catch (InterruptedException e) { fail(e.toString()); } @@ -49,10 +49,10 @@ public void acquireReleaseTest() { for (int i = 1; i <= 3; i++) { sphore.release(); - assertEquals(sphore.getAvailableLicenses(), i); + assertEquals(i, sphore.getAvailableLicenses()); } sphore.release(); - assertEquals(sphore.getAvailableLicenses(), 3); + assertEquals(3, sphore.getAvailableLicenses()); } } diff --git a/servant/src/test/java/com/iluwatar/servant/QueenTest.java b/servant/src/test/java/com/iluwatar/servant/QueenTest.java index 17498e248c65..065dd1802d5b 100644 --- a/servant/src/test/java/com/iluwatar/servant/QueenTest.java +++ b/servant/src/test/java/com/iluwatar/servant/QueenTest.java @@ -36,7 +36,7 @@ public class QueenTest { @Test - public void testNotFlirtyUncomplemented() throws Exception { + public void testNotFlirtyUncomplemented() { final Queen queen = new Queen(); queen.setFlirtiness(false); queen.changeMood(); @@ -44,7 +44,7 @@ public void testNotFlirtyUncomplemented() throws Exception { } @Test - public void testNotFlirtyComplemented() throws Exception { + public void testNotFlirtyComplemented() { final Queen queen = new Queen(); queen.setFlirtiness(false); queen.receiveCompliments(); @@ -53,14 +53,14 @@ public void testNotFlirtyComplemented() throws Exception { } @Test - public void testFlirtyUncomplemented() throws Exception { + public void testFlirtyUncomplemented() { final Queen queen = new Queen(); queen.changeMood(); assertFalse(queen.getMood()); } @Test - public void testFlirtyComplemented() throws Exception { + public void testFlirtyComplemented() { final Queen queen = new Queen(); queen.receiveCompliments(); queen.changeMood(); diff --git a/servant/src/test/java/com/iluwatar/servant/ServantTest.java b/servant/src/test/java/com/iluwatar/servant/ServantTest.java index 16e1d3c00b99..0d01c0804be4 100644 --- a/servant/src/test/java/com/iluwatar/servant/ServantTest.java +++ b/servant/src/test/java/com/iluwatar/servant/ServantTest.java @@ -41,7 +41,7 @@ public class ServantTest { @Test - public void testFeed() throws Exception { + public void testFeed() { final Royalty royalty = mock(Royalty.class); final Servant servant = new Servant("test"); servant.feed(royalty); @@ -50,7 +50,7 @@ public void testFeed() throws Exception { } @Test - public void testGiveWine() throws Exception { + public void testGiveWine() { final Royalty royalty = mock(Royalty.class); final Servant servant = new Servant("test"); servant.giveWine(royalty); @@ -59,7 +59,7 @@ public void testGiveWine() throws Exception { } @Test - public void testGiveCompliments() throws Exception { + public void testGiveCompliments() { final Royalty royalty = mock(Royalty.class); final Servant servant = new Servant("test"); servant.giveCompliments(royalty); @@ -68,7 +68,7 @@ public void testGiveCompliments() throws Exception { } @Test - public void testCheckIfYouWillBeHanged() throws Exception { + public void testCheckIfYouWillBeHanged() { final Royalty goodMoodRoyalty = mock(Royalty.class); when(goodMoodRoyalty.getMood()).thenReturn(true); diff --git a/serverless/src/main/java/com/iluwatar/serverless/baas/api/FindPersonApiHandler.java b/serverless/src/main/java/com/iluwatar/serverless/baas/api/FindPersonApiHandler.java index 2eb1613f89c3..fab448d5c2dd 100644 --- a/serverless/src/main/java/com/iluwatar/serverless/baas/api/FindPersonApiHandler.java +++ b/serverless/src/main/java/com/iluwatar/serverless/baas/api/FindPersonApiHandler.java @@ -33,7 +33,7 @@ * find person from persons collection * Created by dheeraj.mummar on 3/5/18. */ -public class FindPersonApiHandler extends AbstractDynamoDbHandler +public class FindPersonApiHandler extends AbstractDynamoDbHandler implements RequestHandler { private static final Logger LOG = Logger.getLogger(FindPersonApiHandler.class); diff --git a/serverless/src/main/java/com/iluwatar/serverless/baas/api/SavePersonApiHandler.java b/serverless/src/main/java/com/iluwatar/serverless/baas/api/SavePersonApiHandler.java index f00d28b96f32..b66b997d2ec7 100644 --- a/serverless/src/main/java/com/iluwatar/serverless/baas/api/SavePersonApiHandler.java +++ b/serverless/src/main/java/com/iluwatar/serverless/baas/api/SavePersonApiHandler.java @@ -35,7 +35,7 @@ * save person into persons collection * Created by dheeraj.mummar on 3/4/18. */ -public class SavePersonApiHandler extends AbstractDynamoDbHandler +public class SavePersonApiHandler extends AbstractDynamoDbHandler implements RequestHandler { private static final Logger LOG = Logger.getLogger(SavePersonApiHandler.class); diff --git a/service-layer/bin/pom.xml b/service-layer/bin/pom.xml deleted file mode 100644 index 6eadbfa0c471..000000000000 --- a/service-layer/bin/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - 4.0.0 - - com.iluwatar - java-design-patterns - 1.0-SNAPSHOT - - dao - - - org.hibernate - hibernate-core - - - com.h2database - h2 - - - junit - junit - test - - - diff --git a/service-layer/src/main/java/com/iluwatar/servicelayer/spell/SpellDaoImpl.java b/service-layer/src/main/java/com/iluwatar/servicelayer/spell/SpellDaoImpl.java index 81b3b6189576..e185bf57cff4 100644 --- a/service-layer/src/main/java/com/iluwatar/servicelayer/spell/SpellDaoImpl.java +++ b/service-layer/src/main/java/com/iluwatar/servicelayer/spell/SpellDaoImpl.java @@ -38,10 +38,9 @@ public class SpellDaoImpl extends DaoBaseImpl implements SpellDao { @Override public Spell findByName(String name) { - Session session = getSessionFactory().openSession(); Transaction tx = null; Spell result = null; - try { + try (Session session = getSessionFactory().openSession()) { tx = session.beginTransaction(); Criteria criteria = session.createCriteria(persistentClass); criteria.add(Restrictions.eq("name", name)); @@ -52,8 +51,6 @@ public Spell findByName(String name) { tx.rollback(); } throw e; - } finally { - session.close(); } return result; } diff --git a/service-layer/src/test/java/com/iluwatar/servicelayer/app/AppTest.java b/service-layer/src/test/java/com/iluwatar/servicelayer/app/AppTest.java index 295383513abf..e78667ebe4f8 100644 --- a/service-layer/src/test/java/com/iluwatar/servicelayer/app/AppTest.java +++ b/service-layer/src/test/java/com/iluwatar/servicelayer/app/AppTest.java @@ -40,7 +40,7 @@ public void test() { } @AfterEach - public void tearDown() throws Exception { + public void tearDown() { HibernateUtil.dropSession(); } diff --git a/service-layer/src/test/java/com/iluwatar/servicelayer/common/BaseDaoTest.java b/service-layer/src/test/java/com/iluwatar/servicelayer/common/BaseDaoTest.java index 2bc557d759a4..39d84475ac2b 100644 --- a/service-layer/src/test/java/com/iluwatar/servicelayer/common/BaseDaoTest.java +++ b/service-layer/src/test/java/com/iluwatar/servicelayer/common/BaseDaoTest.java @@ -76,7 +76,7 @@ public BaseDaoTest(final Function factory, final D dao) { } @BeforeEach - public void setUp() throws Exception { + public void setUp() { for (int i = 0; i < INITIAL_COUNT; i++) { final String className = dao.persistentClass.getSimpleName(); final String entityName = String.format("%s%d", className, ID_GENERATOR.incrementAndGet()); @@ -85,7 +85,7 @@ public void setUp() throws Exception { } @AfterEach - public void tearDown() throws Exception { + public void tearDown() { HibernateUtil.dropSession(); } @@ -94,7 +94,7 @@ protected final D getDao() { } @Test - public void testFind() throws Exception { + public void testFind() { final List all = this.dao.findAll(); for (final E entity : all) { final E byId = this.dao.find(entity.getId()); @@ -104,7 +104,7 @@ public void testFind() throws Exception { } @Test - public void testDelete() throws Exception { + public void testDelete() { final List originalEntities = this.dao.findAll(); this.dao.delete(originalEntities.get(1)); this.dao.delete(originalEntities.get(2)); @@ -115,24 +115,24 @@ public void testDelete() throws Exception { } @Test - public void testFindAll() throws Exception { + public void testFindAll() { final List all = this.dao.findAll(); assertNotNull(all); assertEquals(INITIAL_COUNT, all.size()); } @Test - public void testSetId() throws Exception { + public void testSetId() { final E entity = this.factory.apply("name"); assertNull(entity.getId()); - final Long expectedId = Long.valueOf(1); + final Long expectedId = 1L; entity.setId(expectedId); assertEquals(expectedId, entity.getId()); } @Test - public void testSetName() throws Exception { + public void testSetName() { final E entity = this.factory.apply("name"); assertEquals("name", entity.getName()); assertEquals("name", entity.toString()); diff --git a/service-layer/src/test/java/com/iluwatar/servicelayer/magic/MagicServiceImplTest.java b/service-layer/src/test/java/com/iluwatar/servicelayer/magic/MagicServiceImplTest.java index 66750c5b26f5..2fd9e15ceb12 100644 --- a/service-layer/src/test/java/com/iluwatar/servicelayer/magic/MagicServiceImplTest.java +++ b/service-layer/src/test/java/com/iluwatar/servicelayer/magic/MagicServiceImplTest.java @@ -51,7 +51,7 @@ public class MagicServiceImplTest { @Test - public void testFindAllWizards() throws Exception { + public void testFindAllWizards() { final WizardDao wizardDao = mock(WizardDao.class); final SpellbookDao spellbookDao = mock(SpellbookDao.class); final SpellDao spellDao = mock(SpellDao.class); diff --git a/service-layer/src/test/java/com/iluwatar/servicelayer/spell/SpellDaoImplTest.java b/service-layer/src/test/java/com/iluwatar/servicelayer/spell/SpellDaoImplTest.java index e4a5bfa65eec..4aa7ec8829b2 100644 --- a/service-layer/src/test/java/com/iluwatar/servicelayer/spell/SpellDaoImplTest.java +++ b/service-layer/src/test/java/com/iluwatar/servicelayer/spell/SpellDaoImplTest.java @@ -42,7 +42,7 @@ public SpellDaoImplTest() { } @Test - public void testFindByName() throws Exception { + public void testFindByName() { final SpellDaoImpl dao = getDao(); final List allSpells = dao.findAll(); for (final Spell spell : allSpells) { diff --git a/service-layer/src/test/java/com/iluwatar/servicelayer/spellbook/SpellbookDaoImplTest.java b/service-layer/src/test/java/com/iluwatar/servicelayer/spellbook/SpellbookDaoImplTest.java index a6f1b3ea35b0..acb9d8123e33 100644 --- a/service-layer/src/test/java/com/iluwatar/servicelayer/spellbook/SpellbookDaoImplTest.java +++ b/service-layer/src/test/java/com/iluwatar/servicelayer/spellbook/SpellbookDaoImplTest.java @@ -42,7 +42,7 @@ public SpellbookDaoImplTest() { } @Test - public void testFindByName() throws Exception { + public void testFindByName() { final SpellbookDaoImpl dao = getDao(); final List allBooks = dao.findAll(); for (final Spellbook book : allBooks) { diff --git a/service-layer/src/test/java/com/iluwatar/servicelayer/wizard/WizardDaoImplTest.java b/service-layer/src/test/java/com/iluwatar/servicelayer/wizard/WizardDaoImplTest.java index d8a093319805..155aca3bbd13 100644 --- a/service-layer/src/test/java/com/iluwatar/servicelayer/wizard/WizardDaoImplTest.java +++ b/service-layer/src/test/java/com/iluwatar/servicelayer/wizard/WizardDaoImplTest.java @@ -42,7 +42,7 @@ public WizardDaoImplTest() { } @Test - public void testFindByName() throws Exception { + public void testFindByName() { final WizardDaoImpl dao = getDao(); final List allWizards = dao.findAll(); for (final Wizard spell : allWizards) { diff --git a/specification/src/main/java/com/iluwatar/specification/app/App.java b/specification/src/main/java/com/iluwatar/specification/app/App.java index d4289f2d883f..6d53d17451e6 100644 --- a/specification/src/main/java/com/iluwatar/specification/app/App.java +++ b/specification/src/main/java/com/iluwatar/specification/app/App.java @@ -70,18 +70,18 @@ public static void main(String[] args) { List walkingCreatures = creatures.stream().filter(new MovementSelector(Movement.WALKING)) .collect(Collectors.toList()); - walkingCreatures.stream().forEach(c -> LOGGER.info(c.toString())); + walkingCreatures.forEach(c -> LOGGER.info(c.toString())); // find all dark creatures LOGGER.info("Find all dark creatures"); List darkCreatures = creatures.stream().filter(new ColorSelector(Color.DARK)).collect(Collectors.toList()); - darkCreatures.stream().forEach(c -> LOGGER.info(c.toString())); + darkCreatures.forEach(c -> LOGGER.info(c.toString())); // find all red and flying creatures LOGGER.info("Find all red and flying creatures"); List redAndFlyingCreatures = creatures.stream() .filter(new ColorSelector(Color.RED).and(new MovementSelector(Movement.FLYING))) .collect(Collectors.toList()); - redAndFlyingCreatures.stream().forEach(c -> LOGGER.info(c.toString())); + redAndFlyingCreatures.forEach(c -> LOGGER.info(c.toString())); } } diff --git a/specification/src/test/java/com/iluwatar/specification/creature/CreatureTest.java b/specification/src/test/java/com/iluwatar/specification/creature/CreatureTest.java index 2d43c8d5986f..370b8b4c0a5e 100644 --- a/specification/src/test/java/com/iluwatar/specification/creature/CreatureTest.java +++ b/specification/src/test/java/com/iluwatar/specification/creature/CreatureTest.java @@ -57,33 +57,33 @@ public static Collection dataProvider() { @ParameterizedTest @MethodSource("dataProvider") - public void testGetName(Creature testedCreature, String name) throws Exception { + public void testGetName(Creature testedCreature, String name) { assertEquals(name, testedCreature.getName()); } @ParameterizedTest @MethodSource("dataProvider") - public void testGetSize(Creature testedCreature, String name, Size size) throws Exception { + public void testGetSize(Creature testedCreature, String name, Size size) { assertEquals(size, testedCreature.getSize()); } @ParameterizedTest @MethodSource("dataProvider") - public void testGetMovement(Creature testedCreature, String name, Size size, Movement movement) throws Exception { + public void testGetMovement(Creature testedCreature, String name, Size size, Movement movement) { assertEquals(movement, testedCreature.getMovement()); } @ParameterizedTest @MethodSource("dataProvider") public void testGetColor(Creature testedCreature, String name, Size size, Movement movement, - Color color) throws Exception { + Color color) { assertEquals(color, testedCreature.getColor()); } @ParameterizedTest @MethodSource("dataProvider") public void testToString(Creature testedCreature, String name, Size size, Movement movement, - Color color) throws Exception { + Color color) { final String toString = testedCreature.toString(); assertNotNull(toString); assertEquals( diff --git a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java index da1b9c2645b2..1b21e00d7848 100644 --- a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java +++ b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java @@ -105,7 +105,7 @@ public static void setup() { * same exception */ @Test - public void testExecptions() { + public void testExceptions() { assertEquals(expectedExceptions, result.getExceptionList()); } diff --git a/tolerant-reader/src/test/java/com/iluwatar/tolerantreader/RainbowFishV2Test.java b/tolerant-reader/src/test/java/com/iluwatar/tolerantreader/RainbowFishV2Test.java index 789da4f1e14f..66583c498d2d 100644 --- a/tolerant-reader/src/test/java/com/iluwatar/tolerantreader/RainbowFishV2Test.java +++ b/tolerant-reader/src/test/java/com/iluwatar/tolerantreader/RainbowFishV2Test.java @@ -24,7 +24,9 @@ import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Date: 12/30/15 - 18:35 PM @@ -43,9 +45,9 @@ public void testValues() { assertEquals(1, fish.getAge()); assertEquals(2, fish.getLengthMeters()); assertEquals(3, fish.getWeightTons()); - assertEquals(false, fish.getSleeping()); - assertEquals(true, fish.getHungry()); - assertEquals(false, fish.getAngry()); + assertFalse(fish.getSleeping()); + assertTrue(fish.getHungry()); + assertFalse(fish.getAngry()); } } \ No newline at end of file diff --git a/trampoline/src/test/java/com/iluwatar/trampoline/TrampolineAppTest.java b/trampoline/src/test/java/com/iluwatar/trampoline/TrampolineAppTest.java index 3680be72eed2..54bef970bb78 100644 --- a/trampoline/src/test/java/com/iluwatar/trampoline/TrampolineAppTest.java +++ b/trampoline/src/test/java/com/iluwatar/trampoline/TrampolineAppTest.java @@ -36,7 +36,7 @@ public class TrampolineAppTest { @Test - public void testTrampolineWithFactorialFunction() throws IOException { + public void testTrampolineWithFactorialFunction() { int result = TrampolineApp.loop(10, 1).result(); assertEquals("Be equal", 3628800, result); } diff --git a/twin/src/test/java/com/iluwatar/twin/BallThreadTest.java b/twin/src/test/java/com/iluwatar/twin/BallThreadTest.java index 010e6c7e2b8b..88fb0345e895 100644 --- a/twin/src/test/java/com/iluwatar/twin/BallThreadTest.java +++ b/twin/src/test/java/com/iluwatar/twin/BallThreadTest.java @@ -73,7 +73,7 @@ public void testSuspend() throws Exception { * Verify if the {@link BallThread} can be resumed */ @Test - public void testResume() throws Exception { + public void testResume() { assertTimeout(ofMillis(5000), () -> { final BallThread ballThread = new BallThread(); @@ -102,7 +102,7 @@ public void testResume() throws Exception { * Verify if the {@link BallThread} is interruptible */ @Test - public void testInterrupt() throws Exception { + public void testInterrupt() { assertTimeout(ofMillis(5000), () -> { final BallThread ballThread = new BallThread(); final UncaughtExceptionHandler exceptionHandler = mock(UncaughtExceptionHandler.class); diff --git a/unit-of-work/src/test/java/com/iluwatar/unitofwork/AppTest.java b/unit-of-work/src/test/java/com/iluwatar/unitofwork/AppTest.java index 942db781f4c7..8256310d7709 100644 --- a/unit-of-work/src/test/java/com/iluwatar/unitofwork/AppTest.java +++ b/unit-of-work/src/test/java/com/iluwatar/unitofwork/AppTest.java @@ -33,7 +33,7 @@ */ public class AppTest { @Test - public void test() throws IOException { + public void test() { String[] args = {}; App.main(args); } diff --git a/unit-of-work/src/test/java/com/iluwatar/unitofwork/StudentRepositoryTest.java b/unit-of-work/src/test/java/com/iluwatar/unitofwork/StudentRepositoryTest.java index ee63442a5b88..1d48d222ee88 100644 --- a/unit-of-work/src/test/java/com/iluwatar/unitofwork/StudentRepositoryTest.java +++ b/unit-of-work/src/test/java/com/iluwatar/unitofwork/StudentRepositoryTest.java @@ -58,7 +58,7 @@ public void setUp() throws Exception { } @Test - public void shouldSaveNewStudentWithoutWritingToDb() throws Exception { + public void shouldSaveNewStudentWithoutWritingToDb() { studentRepository.registerNew(student1); studentRepository.registerNew(student2); @@ -67,7 +67,7 @@ public void shouldSaveNewStudentWithoutWritingToDb() throws Exception { } @Test - public void shouldSaveDeletedStudentWithoutWritingToDb() throws Exception { + public void shouldSaveDeletedStudentWithoutWritingToDb() { studentRepository.registerDeleted(student1); studentRepository.registerDeleted(student2); @@ -76,7 +76,7 @@ public void shouldSaveDeletedStudentWithoutWritingToDb() throws Exception { } @Test - public void shouldSaveModifiedStudentWithoutWritingToDb() throws Exception { + public void shouldSaveModifiedStudentWithoutWritingToDb() { studentRepository.registerModified(student1); studentRepository.registerModified(student2); @@ -85,7 +85,7 @@ public void shouldSaveModifiedStudentWithoutWritingToDb() throws Exception { } @Test - public void shouldSaveAllLocalChangesToDb() throws Exception { + public void shouldSaveAllLocalChangesToDb() { context.put(IUnitOfWork.INSERT, Collections.singletonList(student1)); context.put(IUnitOfWork.MODIFY, Collections.singletonList(student1)); context.put(IUnitOfWork.DELETE, Collections.singletonList(student1)); @@ -98,7 +98,7 @@ public void shouldSaveAllLocalChangesToDb() throws Exception { } @Test - public void shouldNotWriteToDbIfContextIsNull() throws Exception { + public void shouldNotWriteToDbIfContextIsNull() { StudentRepository studentRepository = new StudentRepository(null, studentDatabase); studentRepository.commit(); @@ -107,7 +107,7 @@ public void shouldNotWriteToDbIfContextIsNull() throws Exception { } @Test - public void shouldNotWriteToDbIfNothingToCommit() throws Exception { + public void shouldNotWriteToDbIfNothingToCommit() { StudentRepository studentRepository = new StudentRepository(new HashMap<>(), studentDatabase); studentRepository.commit(); @@ -116,7 +116,7 @@ public void shouldNotWriteToDbIfNothingToCommit() throws Exception { } @Test - public void shouldNotInsertToDbIfNoRegisteredStudentsToBeCommitted() throws Exception { + public void shouldNotInsertToDbIfNoRegisteredStudentsToBeCommitted() { context.put(IUnitOfWork.MODIFY, Collections.singletonList(student1)); context.put(IUnitOfWork.DELETE, Collections.singletonList(student1)); @@ -126,7 +126,7 @@ public void shouldNotInsertToDbIfNoRegisteredStudentsToBeCommitted() throws Exce } @Test - public void shouldNotModifyToDbIfNotRegisteredStudentsToBeCommitted() throws Exception { + public void shouldNotModifyToDbIfNotRegisteredStudentsToBeCommitted() { context.put(IUnitOfWork.INSERT, Collections.singletonList(student1)); context.put(IUnitOfWork.DELETE, Collections.singletonList(student1)); @@ -136,7 +136,7 @@ public void shouldNotModifyToDbIfNotRegisteredStudentsToBeCommitted() throws Exc } @Test - public void shouldNotDeleteFromDbIfNotRegisteredStudentsToBeCommitted() throws Exception { + public void shouldNotDeleteFromDbIfNotRegisteredStudentsToBeCommitted() { context.put(IUnitOfWork.INSERT, Collections.singletonList(student1)); context.put(IUnitOfWork.MODIFY, Collections.singletonList(student1)); diff --git a/visitor/src/test/java/com/iluwatar/visitor/UnitTest.java b/visitor/src/test/java/com/iluwatar/visitor/UnitTest.java index 57fe193976cd..bccc44564aa8 100644 --- a/visitor/src/test/java/com/iluwatar/visitor/UnitTest.java +++ b/visitor/src/test/java/com/iluwatar/visitor/UnitTest.java @@ -55,7 +55,7 @@ public UnitTest(final Function factory) { } @Test - public void testAccept() throws Exception { + public void testAccept() { final Unit[] children = new Unit[5]; Arrays.setAll(children, (i) -> mock(Unit.class));