Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe25c0b

Browse files
ntantriohbus
andauthored
bug-fix: Use Junit5 in the serverless module tests (iluwatar#1794)
*iluwatar#1667: Fixing the serverless tests to use Junit5 and also modifying other classes to remove the deprecated initMock() method*iluwatar#1667: Fixing the sonar code smellsCo-authored-by: Subhrodip Mohanta <hello@subho.xyz>
1 parentbe59e50 commitbe25c0b

File tree

8 files changed

+39
-47
lines changed

8 files changed

+39
-47
lines changed

‎aggregator-microservices/aggregator-service/src/test/java/com/iluwatar/aggregator/microservices/AggregatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AggregatorTest {
4848

4949
@BeforeEach
5050
publicvoidsetup() {
51-
MockitoAnnotations.initMocks(this);
51+
MockitoAnnotations.openMocks(this);
5252
}
5353

5454
/**

‎api-gateway/api-gateway-service/src/test/java/com/iluwatar/api/gateway/ApiGatewayTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ApiGatewayTest {
4848

4949
@BeforeEach
5050
publicvoidsetup() {
51-
MockitoAnnotations.initMocks(this);
51+
MockitoAnnotations.openMocks(this);
5252
}
5353

5454
/**

‎async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ThreadAsyncExecutorTest {
6868

6969
@BeforeEach
7070
voidsetUp() {
71-
MockitoAnnotations.initMocks(this);
71+
MockitoAnnotations.openMocks(this);
7272
}
7373

7474
/**

‎data-bus/src/test/java/com/iluwatar/databus/DataBusTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DataBusTest {
4646

4747
@BeforeEach
4848
voidsetUp() {
49-
MockitoAnnotations.initMocks(this);
49+
MockitoAnnotations.openMocks(this);
5050
}
5151

5252
@Test

‎pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<slf4j.version>1.7.30</slf4j.version>
6363
<logback.version>1.2.3</logback.version>
6464
<aws-lambda-core.version>1.1.0</aws-lambda-core.version>
65-
<aws-java-sdk-dynamodb.version>1.11.289</aws-java-sdk-dynamodb.version>
65+
<aws-java-sdk-dynamodb.version>1.12.13</aws-java-sdk-dynamodb.version>
6666
<aws-lambda-java-events.version>2.0.1</aws-lambda-java-events.version>
6767
<jackson.version>2.12.3</jackson.version>
6868
<jaxb-api.version>2.3.1</jaxb-api.version>
@@ -72,7 +72,7 @@
7272
<urm.version>2.0.0</urm.version>
7373
<mockito-junit-jupiter.version>3.5.0</mockito-junit-jupiter.version>
7474
<lombok.version>1.18.14</lombok.version>
75-
<byte-buddy.version>1.10.21</byte-buddy.version>
75+
<byte-buddy.version>1.11.5</byte-buddy.version>
7676
<javassist.version>3.27.0-GA</javassist.version>
7777
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
7878
<maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>

‎serverless/pom.xml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@
4444
<groupId>com.amazonaws</groupId>
4545
<artifactId>aws-java-sdk-dynamodb</artifactId>
4646
<version>${aws-java-sdk-dynamodb.version}</version>
47-
<exclusions>
48-
<exclusion>
49-
<groupId>com.amazonaws</groupId>
50-
<artifactId>aws-java-sdk-s3</artifactId>
51-
</exclusion>
52-
<exclusion>
53-
<groupId>com.amazonaws</groupId>
54-
<artifactId>aws-java-sdk-kms</artifactId>
55-
</exclusion>
56-
</exclusions>
5747
</dependency>
5848
<dependency>
5949
<groupId>com.amazonaws</groupId>
@@ -80,15 +70,15 @@
8070
<artifactId>junit-jupiter-engine</artifactId>
8171
<scope>test</scope>
8272
</dependency>
73+
<dependency>
74+
<groupId>org.mockito</groupId>
75+
<artifactId>mockito-core</artifactId>
76+
<scope>test</scope>
77+
</dependency>
8378
<dependency>
84-
<groupId>org.mockito</groupId>
85-
<artifactId>mockito-core</artifactId>
86-
<scope>test</scope>
87-
</dependency>
88-
<dependency>
89-
<groupId>junit</groupId>
90-
<artifactId>junit</artifactId>
91-
<scope>test</scope>
79+
<groupId>org.hamcrest</groupId>
80+
<artifactId>hamcrest-core</artifactId>
81+
<scope>test</scope>
9282
</dependency>
9383
</dependencies>
9484

‎serverless/src/test/java/com/iluwatar/serverless/baas/api/FindPersonApiHandlerTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
packagecom.iluwatar.serverless.baas.api;
2525

26+
importorg.mockito.Mock;
27+
importorg.mockito.MockitoAnnotations;
28+
2629
importstaticorg.mockito.Mockito.mock;
2730
importstaticorg.mockito.Mockito.times;
2831
importstaticorg.mockito.Mockito.verify;
@@ -32,31 +35,29 @@
3235
importcom.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
3336
importcom.iluwatar.serverless.baas.model.Person;
3437
importjava.util.Map;
35-
importorg.junit.Before;
36-
importorg.junit.Test;
37-
importorg.junit.runner.RunWith;
38-
importorg.mockito.Mock;
39-
importorg.mockito.runners.MockitoJUnitRunner;
38+
importorg.junit.jupiter.api.BeforeEach;
39+
importorg.junit.jupiter.api.Test;
40+
importorg.junit.jupiter.api.extension.ExtendWith;
4041

4142
/**
4243
* Unit tests for FindPersonApiHandler Created by dheeraj.mummar on 3/5/18.
4344
*/
44-
@RunWith(MockitoJUnitRunner.class)
45-
publicclassFindPersonApiHandlerTest {
45+
classFindPersonApiHandlerTest {
4646

4747
privateFindPersonApiHandlerfindPersonApiHandler;
4848

4949
@Mock
5050
privateDynamoDBMapperdynamoDbMapper;
5151

52-
@Before
52+
@BeforeEach
5353
publicvoidsetUp() {
54+
MockitoAnnotations.openMocks(this);
5455
this.findPersonApiHandler =newFindPersonApiHandler();
5556
this.findPersonApiHandler.setDynamoDbMapper(dynamoDbMapper);
5657
}
5758

5859
@Test
59-
publicvoidhandleRequest() {
60+
voidhandleRequest() {
6061
findPersonApiHandler.handleRequest(apiGatewayProxyRequestEvent(),mock(Context.class));
6162
verify(dynamoDbMapper,times(1)).load(Person.class,"37e7a1fe-3544-473d-b764-18128f02d72d");
6263
}

‎serverless/src/test/java/com/iluwatar/serverless/baas/api/SavePersonApiHandlerTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@
3434
importcom.fasterxml.jackson.databind.ObjectMapper;
3535
importcom.iluwatar.serverless.baas.model.Address;
3636
importcom.iluwatar.serverless.baas.model.Person;
37-
importorg.junit.Assert;
38-
importorg.junit.Before;
39-
importorg.junit.Test;
40-
importorg.junit.runner.RunWith;
37+
importorg.junit.jupiter.api.BeforeEach;
38+
importorg.junit.jupiter.api.Test;
4139
importorg.mockito.Mock;
42-
importorg.mockito.runners.MockitoJUnitRunner;
40+
importorg.mockito.MockitoAnnotations;
41+
42+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
43+
importstaticorg.junit.jupiter.api.Assertions.assertNotNull;
4344

4445
/**
4546
* Unit tests for SavePersonApiHandler Created by dheeraj.mummar on 3/4/18.
4647
*/
47-
@RunWith(MockitoJUnitRunner.class)
48-
publicclassSavePersonApiHandlerTest {
48+
classSavePersonApiHandlerTest {
4949

5050
privateSavePersonApiHandlersavePersonApiHandler;
5151

@@ -54,31 +54,32 @@ public class SavePersonApiHandlerTest {
5454

5555
privatefinalObjectMapperobjectMapper =newObjectMapper();
5656

57-
@Before
57+
@BeforeEach
5858
publicvoidsetUp() {
59+
MockitoAnnotations.openMocks(this);
5960
this.savePersonApiHandler =newSavePersonApiHandler();
6061
this.savePersonApiHandler.setDynamoDbMapper(dynamoDbMapper);
6162
}
6263

6364
@Test
64-
publicvoidhandleRequestSavePersonSuccessful()throwsJsonProcessingException {
65+
voidhandleRequestSavePersonSuccessful()throwsJsonProcessingException {
6566
varperson =newPerson();
6667
varbody =objectMapper.writeValueAsString(person);
6768
varrequest =apiGatewayProxyRequestEvent(body);
6869
varctx =mock(Context.class);
6970
varapiGatewayProxyResponseEvent =this.savePersonApiHandler.handleRequest(request,ctx);
7071
verify(dynamoDbMapper,times(1)).save(person);
71-
Assert.assertNotNull(apiGatewayProxyResponseEvent);
72-
Assert.assertEquals(Integer.valueOf(201),apiGatewayProxyResponseEvent.getStatusCode());
72+
assertNotNull(apiGatewayProxyResponseEvent);
73+
assertEquals(Integer.valueOf(201),apiGatewayProxyResponseEvent.getStatusCode());
7374
}
7475

7576
@Test
76-
publicvoidhandleRequestSavePersonException() {
77+
voidhandleRequestSavePersonException() {
7778
varrequest =apiGatewayProxyRequestEvent("invalid sample request");
7879
varctx =mock(Context.class);
7980
varapiGatewayProxyResponseEvent =this.savePersonApiHandler.handleRequest(request,ctx);
80-
Assert.assertNotNull(apiGatewayProxyResponseEvent);
81-
Assert.assertEquals(Integer.valueOf(400),apiGatewayProxyResponseEvent.getStatusCode());
81+
assertNotNull(apiGatewayProxyResponseEvent);
82+
assertEquals(Integer.valueOf(400),apiGatewayProxyResponseEvent.getStatusCode());
8283
}
8384

8485
privateAPIGatewayProxyRequestEventapiGatewayProxyRequestEvent(Stringbody) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp