Compare commits
5 Commits
all-contri
...
broken-lin
Author | SHA1 | Date | |
---|---|---|---|
81f9291e76 | |||
58c0008b75 | |||
bc7040566e | |||
bb49e3c4e9 | |||
842b400fee |
@ -1586,33 +1586,6 @@
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "tan31989",
|
||||
"name": "Nagaraj Tantri",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/3784194?v=4",
|
||||
"profile": "https://stackoverflow.com/users/308565/nagaraj-tantri",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "frascu",
|
||||
"name": "Francesco Scuccimarri",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/7107651?v=4",
|
||||
"profile": "http://scuccimarri.it",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Conhan93",
|
||||
"name": "Conny Hansson",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/71334757?v=4",
|
||||
"profile": "https://github.com/Conhan93",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 4,
|
||||
|
@ -10,7 +10,7 @@
|
||||
[](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
|
||||
[](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
[](#contributors-)
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
|
||||
<br/>
|
||||
@ -336,11 +336,6 @@ This project is licensed under the terms of the MIT license.
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/karthikbhat13"><img src="https://avatars.githubusercontent.com/u/22431014?v=4?s=100" width="100px;" alt=""/><br /><sub><b>karthikbhat13</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=karthikbhat13" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/mortezaadi"><img src="https://avatars.githubusercontent.com/u/1329687?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Morteza Adigozalpour</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=mortezaadi" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://stackoverflow.com/users/308565/nagaraj-tantri"><img src="https://avatars.githubusercontent.com/u/3784194?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nagaraj Tantri</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=tan31989" title="Code">💻</a></td>
|
||||
<td align="center"><a href="http://scuccimarri.it"><img src="https://avatars.githubusercontent.com/u/7107651?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Francesco Scuccimarri</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=frascu" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/Conhan93"><img src="https://avatars.githubusercontent.com/u/71334757?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Conny Hansson</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=Conhan93" title="Documentation">📖</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
@ -11,7 +11,7 @@ tags:
|
||||
|
||||
|
||||
## Intent
|
||||
The active object design pattern decouples method execution from method invocation for objects that each reside in their thread of control. The goal is to introduce concurrency, by using asynchronous method invocation, and a scheduler for handling requests.
|
||||
The active object design pattern decouples method execution from method invocation for objects that each reside in their thread of control. The goal is to introduce concurrency, by using asynchronous method invocation and a scheduler for handling requests.
|
||||
|
||||
## Explanation
|
||||
|
||||
@ -70,7 +70,7 @@ public abstract class ActiveCreature{
|
||||
requests.put(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logger.info("{} has started to roam the wastelands.",name());
|
||||
logger.info("{} has started to roam and the wastelands.",name());
|
||||
}
|
||||
}
|
||||
);
|
||||
@ -82,7 +82,7 @@ public abstract class ActiveCreature{
|
||||
}
|
||||
```
|
||||
|
||||
We can see that any class that will extend the ActiveCreature class will have its own thread of control to invoke and execute methods.
|
||||
We can see that any class that will extend the ActiveCreature class will have its own thread of control to execute and invocate methods.
|
||||
|
||||
For example, the Orc class:
|
||||
|
||||
@ -96,7 +96,7 @@ public class Orc extends ActiveCreature {
|
||||
}
|
||||
```
|
||||
|
||||
Now, we can create multiple creatures such as Orcs, tell them to eat and roam, and they will execute it on their own thread of control:
|
||||
Now, we can create multiple creatures such as Orcs, tell them to eat and roam and they will execute it on their own thread of control:
|
||||
|
||||
```java
|
||||
public static void main(String[] args) {
|
||||
|
@ -82,7 +82,7 @@ public abstract class ActiveCreature {
|
||||
}
|
||||
|
||||
/**
|
||||
* Roam the wastelands.
|
||||
* Roam in the wastelands.
|
||||
* @throws InterruptedException due to firing a new Runnable.
|
||||
*/
|
||||
public void roam() throws InterruptedException {
|
||||
|
@ -48,7 +48,7 @@ class AggregatorTest {
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ class ApiGatewayTest {
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,7 +68,7 @@ class ThreadAsyncExecutorTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@ class DataBusTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -48,7 +48,7 @@ que lorsqu’ils sont nécessaires pour une extensibilité pratique.
|
||||
|
||||
Une fois que vous êtes familiarisé avec ces concepts, vous pouvez commencer à explorer les
|
||||
[modèles de conception disponibles](https://java-design-patterns.com/patterns/)
|
||||
par n’importe laquelle des approches suivantes :
|
||||
par n’importe laquelle les approches suivantes :
|
||||
|
||||
- Recherchez un modèle spécifique par son nom.
|
||||
Vous n’en trouvez pas ? Veuillez signaler un nouveau modèle [ici](https://github.com/iluwatar/java-design-patterns/issues).
|
||||
|
6
pom.xml
6
pom.xml
@ -62,7 +62,7 @@
|
||||
<slf4j.version>1.7.30</slf4j.version>
|
||||
<logback.version>1.2.3</logback.version>
|
||||
<aws-lambda-core.version>1.1.0</aws-lambda-core.version>
|
||||
<aws-java-sdk-dynamodb.version>1.12.13</aws-java-sdk-dynamodb.version>
|
||||
<aws-java-sdk-dynamodb.version>1.11.289</aws-java-sdk-dynamodb.version>
|
||||
<aws-lambda-java-events.version>2.0.1</aws-lambda-java-events.version>
|
||||
<jackson.version>2.12.3</jackson.version>
|
||||
<jaxb-api.version>2.3.1</jaxb-api.version>
|
||||
@ -71,8 +71,8 @@
|
||||
<system-lambda.version>1.1.0</system-lambda.version>
|
||||
<urm.version>2.0.0</urm.version>
|
||||
<mockito-junit-jupiter.version>3.5.0</mockito-junit-jupiter.version>
|
||||
<lombok.version>1.18.20</lombok.version>
|
||||
<byte-buddy.version>1.11.5</byte-buddy.version>
|
||||
<lombok.version>1.18.14</lombok.version>
|
||||
<byte-buddy.version>1.10.21</byte-buddy.version>
|
||||
<javassist.version>3.27.0-GA</javassist.version>
|
||||
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
|
||||
<maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
|
||||
|
@ -44,6 +44,16 @@
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-dynamodb</artifactId>
|
||||
<version>${aws-java-sdk-dynamodb.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-kms</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
@ -70,15 +80,15 @@
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<scope>test</scope>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -23,9 +23,6 @@
|
||||
|
||||
package com.iluwatar.serverless.baas.api;
|
||||
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -35,29 +32,31 @@ import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||
import com.iluwatar.serverless.baas.model.Person;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* Unit tests for FindPersonApiHandler Created by dheeraj.mummar on 3/5/18.
|
||||
*/
|
||||
class FindPersonApiHandlerTest {
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class FindPersonApiHandlerTest {
|
||||
|
||||
private FindPersonApiHandler findPersonApiHandler;
|
||||
|
||||
@Mock
|
||||
private DynamoDBMapper dynamoDbMapper;
|
||||
|
||||
@BeforeEach
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
this.findPersonApiHandler = new FindPersonApiHandler();
|
||||
this.findPersonApiHandler.setDynamoDbMapper(dynamoDbMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void handleRequest() {
|
||||
public void handleRequest() {
|
||||
findPersonApiHandler.handleRequest(apiGatewayProxyRequestEvent(), mock(Context.class));
|
||||
verify(dynamoDbMapper, times(1)).load(Person.class, "37e7a1fe-3544-473d-b764-18128f02d72d");
|
||||
}
|
||||
|
@ -34,18 +34,18 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.iluwatar.serverless.baas.model.Address;
|
||||
import com.iluwatar.serverless.baas.model.Person;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* Unit tests for SavePersonApiHandler Created by dheeraj.mummar on 3/4/18.
|
||||
*/
|
||||
class SavePersonApiHandlerTest {
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SavePersonApiHandlerTest {
|
||||
|
||||
private SavePersonApiHandler savePersonApiHandler;
|
||||
|
||||
@ -54,32 +54,31 @@ class SavePersonApiHandlerTest {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@BeforeEach
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
this.savePersonApiHandler = new SavePersonApiHandler();
|
||||
this.savePersonApiHandler.setDynamoDbMapper(dynamoDbMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void handleRequestSavePersonSuccessful() throws JsonProcessingException {
|
||||
public void handleRequestSavePersonSuccessful() throws JsonProcessingException {
|
||||
var person = newPerson();
|
||||
var body = objectMapper.writeValueAsString(person);
|
||||
var request = apiGatewayProxyRequestEvent(body);
|
||||
var ctx = mock(Context.class);
|
||||
var apiGatewayProxyResponseEvent = this.savePersonApiHandler.handleRequest(request, ctx);
|
||||
verify(dynamoDbMapper, times(1)).save(person);
|
||||
assertNotNull(apiGatewayProxyResponseEvent);
|
||||
assertEquals(Integer.valueOf(201), apiGatewayProxyResponseEvent.getStatusCode());
|
||||
Assert.assertNotNull(apiGatewayProxyResponseEvent);
|
||||
Assert.assertEquals(Integer.valueOf(201), apiGatewayProxyResponseEvent.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void handleRequestSavePersonException() {
|
||||
public void handleRequestSavePersonException() {
|
||||
var request = apiGatewayProxyRequestEvent("invalid sample request");
|
||||
var ctx = mock(Context.class);
|
||||
var apiGatewayProxyResponseEvent = this.savePersonApiHandler.handleRequest(request, ctx);
|
||||
assertNotNull(apiGatewayProxyResponseEvent);
|
||||
assertEquals(Integer.valueOf(400), apiGatewayProxyResponseEvent.getStatusCode());
|
||||
Assert.assertNotNull(apiGatewayProxyResponseEvent);
|
||||
Assert.assertEquals(Integer.valueOf(400), apiGatewayProxyResponseEvent.getStatusCode());
|
||||
}
|
||||
|
||||
private APIGatewayProxyRequestEvent apiGatewayProxyRequestEvent(String body) {
|
||||
|
Reference in New Issue
Block a user