Skip to content

Commit 2f569d6

Browse files
committed
Made minor changes in some patterns such as removed throws clause where not needed, changed incorrect order of arguments in assertEquals
1 parent db33cc5 commit 2f569d6

File tree

39 files changed

+96
-146
lines changed

39 files changed

+96
-146
lines changed

abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import static org.junit.jupiter.api.Assertions.assertEquals;
3434
import static org.junit.jupiter.api.Assertions.assertNotNull;
35+
import static org.junit.jupiter.api.Assertions.assertTrue;
3536

3637
/**
3738
* AbstractDocument test class
@@ -81,8 +82,8 @@ public void shouldIncludePropsInToString() {
8182
Map<String, Object> props = new HashMap<>();
8283
props.put(KEY, VALUE);
8384
DocumentImplementation document = new DocumentImplementation(props);
84-
assertNotNull(document.toString().contains(KEY));
85-
assertNotNull(document.toString().contains(VALUE));
85+
assertTrue(document.toString().contains(KEY));
86+
assertTrue(document.toString().contains(VALUE));
8687
}
8788

8889
}

acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646
public class ConfigureForUnixVisitorTest {
4747

48-
TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForUnixVisitor.class);
48+
private TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForUnixVisitor.class);
4949

5050
@AfterEach
5151
public void clearLoggers() {

aggregator-microservices/inventory-microservice/src/test/java/com/iluwatar/inventory/microservice/InventoryControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
public class InventoryControllerTest {
3333
@Test
34-
public void testGetProductInventories() throws Exception {
34+
public void testGetProductInventories() {
3535
InventoryController inventoryController = new InventoryController();
3636

3737
int numberOfInventories = inventoryController.getProductInventories();

bridge/src/test/java/com/iluwatar/bridge/HammerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class HammerTest extends WeaponTest {
3737
* underlying weapon implementation.
3838
*/
3939
@Test
40-
public void testHammer() throws Exception {
40+
public void testHammer() {
4141
final Hammer hammer = spy(new Hammer(mock(FlyingEnchantment.class)));
4242
testBasicWeaponActions(hammer);
4343
}

bridge/src/test/java/com/iluwatar/bridge/SwordTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class SwordTest extends WeaponTest {
3737
* underlying weapon implementation.
3838
*/
3939
@Test
40-
public void testSword() throws Exception {
40+
public void testSword() {
4141
final Sword sword = spy(new Sword(mock(FlyingEnchantment.class)));
4242
testBasicWeaponActions(sword);
4343
}

callback/src/main/java/com/iluwatar/callback/App.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ public class App {
4141
*/
4242
public static void main(String[] args) {
4343
Task task = new SimpleTask();
44-
Callback callback = new Callback() {
45-
@Override
46-
public void call() {
47-
LOGGER.info("I'm done now.");
48-
}
49-
};
44+
Callback callback = () -> LOGGER.info("I'm done now.");
5045
task.executeWith(callback);
5146
}
5247
}

callback/src/test/java/com/iluwatar/callback/CallbackTest.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,6 @@ public class CallbackTest {
3838

3939
@Test
4040
public void test() {
41-
Callback callback = new Callback() {
42-
@Override
43-
public void call() {
44-
callingCount++;
45-
}
46-
};
47-
48-
Task task = new SimpleTask();
49-
50-
assertEquals(new Integer(0), callingCount, "Initial calling count of 0");
51-
52-
task.executeWith(callback);
53-
54-
assertEquals(new Integer(1), callingCount, "Callback called once");
55-
56-
task.executeWith(callback);
57-
58-
assertEquals(new Integer(2), callingCount, "Callback called twice");
59-
60-
}
61-
62-
@Test
63-
public void testWithLambdasExample() {
6441
Callback callback = () -> callingCount++;
6542

6643
Task task = new SimpleTask();

chain/src/test/java/com/iluwatar/chain/OrcKingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class OrcKingTest {
4343
};
4444

4545
@Test
46-
public void testMakeRequest() throws Exception {
46+
public void testMakeRequest() {
4747
final OrcKing king = new OrcKing();
4848

4949
for (final Request request : REQUESTS) {

collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/Car.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
* A Car class that has the properties of make, model, year and category.
2727
*/
2828
public class Car {
29-
private String make;
30-
private String model;
31-
private int year;
32-
private Category category;
29+
private final String make;
30+
private final String model;
31+
private final int year;
32+
private final Category category;
3333

3434
/**
3535
* Constructor to create an instance of car.

converter/src/test/java/com/iluwatar/converter/ConverterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void testCustomConverter() {
7171
user.getFirstName().toLowerCase() + user.getLastName().toLowerCase() + "@whatever.com"));
7272
User u1 = new User("John", "Doe", false, "12324");
7373
UserDto userDto = converter.convertFromEntity(u1);
74-
assertEquals(userDto.getEmail(), "johndoe@whatever.com");
74+
assertEquals("johndoe@whatever.com", userDto.getEmail());
7575
}
7676

7777
/**
@@ -83,6 +83,6 @@ public void testCollectionConversion() {
8383
ArrayList<User> users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"),
8484
new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243"));
8585
List<User> fromDtos = userConverter.createFromDtos(userConverter.createFromEntities(users));
86-
assertEquals(fromDtos, users);
86+
assertEquals(users, fromDtos);
8787
}
8888
}

cqrs/src/test/java/com/iluwatar/cqrs/IntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void testGetBook() {
9696
@Test
9797
public void testGetAuthorBooks() {
9898
List<Book> books = queryService.getAuthorBooks("username1");
99-
assertTrue(books.size() == 2);
99+
assertEquals(2, books.size());
100100
assertTrue(books.contains(new Book("title1", 10)));
101101
assertTrue(books.contains(new Book("new_title2", 30)));
102102
}

dao/src/test/java/com/iluwatar/dao/CustomerTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@ public void equalsWithSameObjects() {
8888

8989
@Test
9090
public void testToString() {
91-
final StringBuffer buffer = new StringBuffer();
92-
buffer.append("Customer{id=")
93-
.append("" + customer.getId())
94-
.append(", firstName='")
95-
.append(customer.getFirstName())
96-
.append("\', lastName='")
97-
.append(customer.getLastName() + "\'}");
98-
assertEquals(buffer.toString(), customer.toString());
91+
assertEquals(String.format("Customer{id=%s, firstName='%s', lastName='%s'}",
92+
customer.getId(), customer.getFirstName(), customer.getLastName()), customer.toString());
9993
}
10094
}

dao/src/test/java/com/iluwatar/dao/DbCustomerDaoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public void deleteSchema() throws SQLException {
257257

258258
private void assertCustomerCountIs(int count) throws Exception {
259259
try (Stream<Customer> allCustomers = dao.getAll()) {
260-
assertTrue(allCustomers.count() == count);
260+
assertEquals(count, allCustomers.count());
261261
}
262262
}
263263

dao/src/test/java/com/iluwatar/dao/InMemoryCustomerDaoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private int getNonExistingCustomerId() {
156156

157157
private void assertCustomerCountIs(int count) throws Exception {
158158
try (Stream<Customer> allCustomers = dao.getAll()) {
159-
assertTrue(allCustomers.count() == count);
159+
assertEquals(count, allCustomers.count());
160160
}
161161
}
162162
}

data-mapper/src/test/java/com/iluwatar/datamapper/DataMapperTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.junit.jupiter.api.Test;
2222

2323
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertFalse;
2425

2526
/**
2627
* The Data Mapper (DM) is a layer of software that separates the in-memory objects from the
@@ -58,12 +59,12 @@ public void testFirstDataMapper() {
5859
mapper.update(student);
5960

6061
/* Check if student is updated in db */
61-
assertEquals(mapper.find(student.getStudentId()).get().getName(), "AdamUpdated");
62+
assertEquals("AdamUpdated", mapper.find(student.getStudentId()).get().getName());
6263

6364
/* Delete student in db */
6465
mapper.delete(student);
6566

6667
/* Result should be false */
67-
assertEquals(false, mapper.find(student.getStudentId()).isPresent());
68+
assertFalse(mapper.find(student.getStudentId()).isPresent());
6869
}
6970
}

data-mapper/src/test/java/com/iluwatar/datamapper/StudentTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,37 @@
2020

2121
import org.junit.jupiter.api.Test;
2222

23+
import static org.junit.jupiter.api.Assertions.assertEquals;
2324
import static org.junit.jupiter.api.Assertions.assertFalse;
25+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2426
import static org.junit.jupiter.api.Assertions.assertTrue;
2527

2628
/**
2729
* Tests {@link Student}.
2830
*/
2931
public final class StudentTest {
3032

31-
@Test
3233
/**
3334
* This API tests the equality behaviour of Student object
3435
* Object Equality should work as per logic defined in equals method
3536
*
3637
* @throws Exception if any execution error during test
3738
*/
39+
@Test
3840
public void testEquality() throws Exception {
3941

4042
/* Create some students */
4143
final Student firstStudent = new Student(1, "Adam", 'A');
4244
final Student secondStudent = new Student(2, "Donald", 'B');
4345
final Student secondSameStudent = new Student(2, "Donald", 'B');
44-
final Student firstSameStudent = firstStudent;
4546

4647
/* Check equals functionality: should return 'true' */
47-
assertTrue(firstStudent.equals(firstSameStudent));
48+
assertEquals(firstStudent, firstStudent);
4849

4950
/* Check equals functionality: should return 'false' */
50-
assertFalse(firstStudent.equals(secondStudent));
51+
assertNotEquals(firstStudent, secondStudent);
5152

5253
/* Check equals functionality: should return 'true' */
53-
assertTrue(secondStudent.equals(secondSameStudent));
54+
assertEquals(secondStudent, secondSameStudent);
5455
}
5556
}

data-transfer-object/src/test/java/com/iluwatar/datatransfer/CustomerResourceTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.List;
3131

3232
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
import static org.junit.jupiter.api.Assertions.assertTrue;
3334

3435
/**
3536
* tests {@link CustomerResource}.
@@ -45,10 +46,10 @@ public void shouldGetAllCustomers() {
4546

4647
List<CustomerDto> allCustomers = customerResource.getAllCustomers();
4748

48-
assertEquals(allCustomers.size(), 1);
49-
assertEquals(allCustomers.get(0).getId(), "1");
50-
assertEquals(allCustomers.get(0).getFirstName(), "Melody");
51-
assertEquals(allCustomers.get(0).getLastName(), "Yates");
49+
assertEquals(1, allCustomers.size());
50+
assertEquals("1", allCustomers.get(0).getId());
51+
assertEquals("Melody", allCustomers.get(0).getFirstName());
52+
assertEquals("Yates", allCustomers.get(0).getLastName());
5253
}
5354

5455
@Test
@@ -59,9 +60,9 @@ public void shouldSaveCustomer() {
5960
customerResource.save(customer);
6061

6162
List<CustomerDto> allCustomers = customerResource.getAllCustomers();
62-
assertEquals(allCustomers.get(0).getId(), "1");
63-
assertEquals(allCustomers.get(0).getFirstName(), "Rita");
64-
assertEquals(allCustomers.get(0).getLastName(), "Reynolds");
63+
assertEquals("1", allCustomers.get(0).getId());
64+
assertEquals("Rita", allCustomers.get(0).getFirstName());
65+
assertEquals("Reynolds", allCustomers.get(0).getLastName());
6566
}
6667

6768
@Test
@@ -75,7 +76,7 @@ public void shouldDeleteCustomer() {
7576
customerResource.delete(customer.getId());
7677

7778
List<CustomerDto> allCustomers = customerResource.getAllCustomers();
78-
assertEquals(allCustomers.size(), 0);
79+
assertTrue(allCustomers.isEmpty());
7980
}
8081

8182
}

delegation/src/main/java/com/iluwatar/delegation/simple/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
public class App {
4242

43-
public static final String MESSAGE_TO_PRINT = "hello world";
43+
private static final String MESSAGE_TO_PRINT = "hello world";
4444

4545
/**
4646
* Program entry point

dirty-flag/src/test/java/org/dirty/flag/DirtyFlagTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package org.dirty.flag;
2424

25+
import static org.junit.jupiter.api.Assertions.assertFalse;
2526
import static org.junit.jupiter.api.Assertions.assertTrue;
2627

2728
import java.util.List;
@@ -41,7 +42,7 @@ public class DirtyFlagTest {
4142
public void testIsDirty() {
4243
DataFetcher df = new DataFetcher();
4344
List<String> countries = df.fetch();
44-
assertTrue(!countries.isEmpty());
45+
assertFalse(countries.isEmpty());
4546
}
4647

4748
@Test

eip-aggregator/src/main/java/com/iluwatar/eip/aggregator/routes/AggregatorRoute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class AggregatorRoute extends RouteBuilder {
5151
* @throws Exception in case of exception during configuration
5252
*/
5353
@Override
54-
public void configure() throws Exception {
54+
public void configure() {
5555
// Main route
5656
from("{{entry}}").aggregate(constant(true), aggregator)
5757
.completionSize(3).completionInterval(2000)

eip-message-channel/src/main/java/com/iluwatar/eip/message/channel/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void configure() throws Exception {
7070
});
7171

7272
context.start();
73-
context.getRoutes().stream().forEach(r -> LOGGER.info(r.toString()));
73+
context.getRoutes().forEach(r -> LOGGER.info(r.toString()));
7474
context.stop();
7575
}
7676
}

eip-publish-subscribe/src/main/java/com/iluwatar/eip/publish/subscribe/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void configure() throws Exception {
6565
});
6666
ProducerTemplate template = context.createProducerTemplate();
6767
context.start();
68-
context.getRoutes().stream().forEach(r -> LOGGER.info(r.toString()));
68+
context.getRoutes().forEach(r -> LOGGER.info(r.toString()));
6969
template.sendBody("direct:origin", "Hello from origin");
7070
context.stop();
7171
}

event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingJoffreyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void testOnEvent() {
7676
private class InMemoryAppender extends AppenderBase<ILoggingEvent> {
7777
private List<ILoggingEvent> log = new LinkedList<>();
7878

79-
public InMemoryAppender(Class clazz) {
79+
public InMemoryAppender(Class<?> clazz) {
8080
((Logger) LoggerFactory.getLogger(clazz)).addAppender(this);
8181
start();
8282
}

event-aggregator/src/test/java/com/iluwatar/event/aggregator/WeekdayTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public class WeekdayTest {
3636

3737
@Test
38-
public void testToString() throws Exception {
38+
public void testToString() {
3939
for (final Weekday weekday : Weekday.values()) {
4040
final String toString = weekday.toString();
4141
assertNotNull(toString);

0 commit comments

Comments
 (0)