fix(client): to Guice DI pattern
This commit is contained in:
parent
7320dd1e46
commit
96b7241056
4 changed files with 9 additions and 5 deletions
|
|
@ -35,6 +35,7 @@ import com.google.inject.TypeLiteral;
|
||||||
import commons.Ingredient;
|
import commons.Ingredient;
|
||||||
import commons.Recipe;
|
import commons.Recipe;
|
||||||
|
|
||||||
|
import java.net.http.HttpClient;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class MyModule implements Module {
|
public class MyModule implements Module {
|
||||||
|
|
@ -51,6 +52,7 @@ public class MyModule implements Module {
|
||||||
binder.bind(WebSocketUtils.class).in(Scopes.SINGLETON);
|
binder.bind(WebSocketUtils.class).in(Scopes.SINGLETON);
|
||||||
binder.bind(NutritionDetailsCtrl.class).in(Scopes.SINGLETON);
|
binder.bind(NutritionDetailsCtrl.class).in(Scopes.SINGLETON);
|
||||||
binder.bind(NutritionViewCtrl.class).in(Scopes.SINGLETON);
|
binder.bind(NutritionViewCtrl.class).in(Scopes.SINGLETON);
|
||||||
|
binder.bind(HttpClient.class).in(Scopes.SINGLETON);
|
||||||
binder.bind(ConfigService.class).toInstance(new ConfigService(Path.of("config.json")));
|
binder.bind(ConfigService.class).toInstance(new ConfigService(Path.of("config.json")));
|
||||||
binder.bind(new TypeLiteral<WebSocketDataService<Long, Recipe>>() {}).toInstance(
|
binder.bind(new TypeLiteral<WebSocketDataService<Long, Recipe>>() {}).toInstance(
|
||||||
new WebSocketDataService<>()
|
new WebSocketDataService<>()
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ public class ServerUtils {
|
||||||
private final int statusOK = 200;
|
private final int statusOK = 200;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ServerUtils() {
|
public ServerUtils(HttpClient client) {
|
||||||
client = HttpClient.newHttpClient();
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -40,7 +41,7 @@ class ServerUtilsMockTest {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() {
|
void setup() {
|
||||||
objectMapper = new ObjectMapper();
|
objectMapper = new ObjectMapper();
|
||||||
serverUtils = new ServerUtils();
|
serverUtils = new ServerUtils(HttpClient.newHttpClient());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
@ -32,7 +33,7 @@ class ServerUtilsTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() throws IOException, InterruptedException {
|
void setup() throws IOException, InterruptedException {
|
||||||
dv = new ServerUtils();
|
dv = new ServerUtils(HttpClient.newHttpClient());
|
||||||
|
|
||||||
Assumptions.assumeTrue(dv.isServerAvailable(), "Server not available");
|
Assumptions.assumeTrue(dv.isServerAvailable(), "Server not available");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue