diff --git a/client/src/main/java/client/Main.java b/client/src/main/java/client/Main.java index 356878d..f7c5a00 100644 --- a/client/src/main/java/client/Main.java +++ b/client/src/main/java/client/Main.java @@ -31,27 +31,27 @@ import javafx.stage.Stage; public class Main extends Application { - private static final Injector INJECTOR = createInjector(new MyModule()); - private static final MyFXML FXML = new MyFXML(INJECTOR); + private static final Injector INJECTOR = createInjector(new MyModule()); + private static final MyFXML FXML = new MyFXML(INJECTOR); - public static void main(String[] args) throws URISyntaxException, IOException { - launch(); - } + public static void main(String[] args) throws URISyntaxException, IOException { + launch(); + } - @Override - public void start(Stage primaryStage) throws Exception { + @Override + public void start(Stage primaryStage) throws Exception { - var serverUtils = INJECTOR.getInstance(ServerUtils.class); - if (!serverUtils.isServerAvailable()) { - var msg = "Server needs to be started before the client, but it does not seem to be available. Shutting down."; - System.err.println(msg); - return; - } + var serverUtils = INJECTOR.getInstance(ServerUtils.class); + if (!serverUtils.isServerAvailable()) { + var msg = "Server needs to be started before the client, but it does not seem to be available. Shutting down."; + System.err.println(msg); + return; + } - var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml"); - var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml"); + var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml"); + var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml"); - var mainCtrl = INJECTOR.getInstance(MainCtrl.class); - mainCtrl.initialize(primaryStage, overview, add); - } + var mainCtrl = INJECTOR.getInstance(MainCtrl.class); + mainCtrl.initialize(primaryStage, overview, add); + } } \ No newline at end of file diff --git a/client/src/main/java/client/scenes/AddQuoteCtrl.java b/client/src/main/java/client/scenes/AddQuoteCtrl.java index 733ac58..ecedcd5 100644 --- a/client/src/main/java/client/scenes/AddQuoteCtrl.java +++ b/client/src/main/java/client/scenes/AddQuoteCtrl.java @@ -29,68 +29,68 @@ import javafx.stage.Modality; public class AddQuoteCtrl { - private final ServerUtils server; - private final MainCtrl mainCtrl; + private final ServerUtils server; + private final MainCtrl mainCtrl; - @FXML - private TextField firstName; + @FXML + private TextField firstName; - @FXML - private TextField lastName; + @FXML + private TextField lastName; - @FXML - private TextField quote; + @FXML + private TextField quote; - @Inject - public AddQuoteCtrl(ServerUtils server, MainCtrl mainCtrl) { - this.mainCtrl = mainCtrl; - this.server = server; + @Inject + public AddQuoteCtrl(ServerUtils server, MainCtrl mainCtrl) { + this.mainCtrl = mainCtrl; + this.server = server; - } + } - public void cancel() { - clearFields(); - mainCtrl.showOverview(); - } + public void cancel() { + clearFields(); + mainCtrl.showOverview(); + } - public void ok() { - try { - server.addQuote(getQuote()); - } catch (WebApplicationException e) { + public void ok() { + try { + server.addQuote(getQuote()); + } catch (WebApplicationException e) { - var alert = new Alert(Alert.AlertType.ERROR); - alert.initModality(Modality.APPLICATION_MODAL); - alert.setContentText(e.getMessage()); - alert.showAndWait(); - return; - } + var alert = new Alert(Alert.AlertType.ERROR); + alert.initModality(Modality.APPLICATION_MODAL); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + return; + } - clearFields(); - mainCtrl.showOverview(); - } + clearFields(); + mainCtrl.showOverview(); + } - private Quote getQuote() { - var p = new Person(firstName.getText(), lastName.getText()); - var q = quote.getText(); - return new Quote(p, q); - } + private Quote getQuote() { + var p = new Person(firstName.getText(), lastName.getText()); + var q = quote.getText(); + return new Quote(p, q); + } - private void clearFields() { - firstName.clear(); - lastName.clear(); - quote.clear(); - } + private void clearFields() { + firstName.clear(); + lastName.clear(); + quote.clear(); + } - public void keyPressed(KeyEvent e) { - switch (e.getCode()) { - case ENTER: - ok(); - break; - case ESCAPE: - cancel(); - break; - default: - break; - } - } + public void keyPressed(KeyEvent e) { + switch (e.getCode()) { + case ENTER: + ok(); + break; + case ESCAPE: + cancel(); + break; + default: + break; + } + } } \ No newline at end of file diff --git a/client/src/main/java/client/utils/ServerUtils.java b/client/src/main/java/client/utils/ServerUtils.java index d92a0e7..483eed1 100644 --- a/client/src/main/java/client/utils/ServerUtils.java +++ b/client/src/main/java/client/utils/ServerUtils.java @@ -35,43 +35,43 @@ import jakarta.ws.rs.core.GenericType; public class ServerUtils { - private static final String SERVER = "http://localhost:8080/"; + private static final String SERVER = "http://localhost:8080/"; - public void getQuotesTheHardWay() throws IOException, URISyntaxException { - var url = new URI("http://localhost:8080/api/quotes").toURL(); - var is = url.openConnection().getInputStream(); - var br = new BufferedReader(new InputStreamReader(is)); - String line; - while ((line = br.readLine()) != null) { - System.out.println(line); - } - } + public void getQuotesTheHardWay() throws IOException, URISyntaxException { + var url = new URI("http://localhost:8080/api/quotes").toURL(); + var is = url.openConnection().getInputStream(); + var br = new BufferedReader(new InputStreamReader(is)); + String line; + while ((line = br.readLine()) != null) { + System.out.println(line); + } + } - public List getQuotes() { - return ClientBuilder.newClient(new ClientConfig()) // - .target(SERVER).path("api/quotes") // - .request(APPLICATION_JSON) // - .get(new GenericType>() {}); - } + public List getQuotes() { + return ClientBuilder.newClient(new ClientConfig()) // + .target(SERVER).path("api/quotes") // + .request(APPLICATION_JSON) // + .get(new GenericType>() {}); + } - public Quote addQuote(Quote quote) { - return ClientBuilder.newClient(new ClientConfig()) // - .target(SERVER).path("api/quotes") // - .request(APPLICATION_JSON) // - .post(Entity.entity(quote, APPLICATION_JSON), Quote.class); - } + public Quote addQuote(Quote quote) { + return ClientBuilder.newClient(new ClientConfig()) // + .target(SERVER).path("api/quotes") // + .request(APPLICATION_JSON) // + .post(Entity.entity(quote, APPLICATION_JSON), Quote.class); + } - public boolean isServerAvailable() { - try { - ClientBuilder.newClient(new ClientConfig()) // - .target(SERVER) // - .request(APPLICATION_JSON) // - .get(); - } catch (ProcessingException e) { - if (e.getCause() instanceof ConnectException) { - return false; - } - } - return true; - } + public boolean isServerAvailable() { + try { + ClientBuilder.newClient(new ClientConfig()) // + .target(SERVER) // + .request(APPLICATION_JSON) // + .get(); + } catch (ProcessingException e) { + if (e.getCause() instanceof ConnectException) { + return false; + } + } + return true; + } } \ No newline at end of file diff --git a/commons/src/main/java/commons/Person.java b/commons/src/main/java/commons/Person.java index 299d5d1..f7d2d31 100644 --- a/commons/src/main/java/commons/Person.java +++ b/commons/src/main/java/commons/Person.java @@ -29,35 +29,35 @@ import jakarta.persistence.Id; @Entity public class Person { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - public long id; + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public long id; - public String firstName; - public String lastName; + public String firstName; + public String lastName; - @SuppressWarnings("unused") - private Person() { - // for object mapper - } + @SuppressWarnings("unused") + private Person() { + // for object mapper + } - public Person(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } + public Person(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } - @Override - public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } + @Override + public boolean equals(Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE); - } + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE); + } } \ No newline at end of file diff --git a/commons/src/main/java/commons/Quote.java b/commons/src/main/java/commons/Quote.java index d91f868..60cb27d 100644 --- a/commons/src/main/java/commons/Quote.java +++ b/commons/src/main/java/commons/Quote.java @@ -31,36 +31,36 @@ import jakarta.persistence.OneToOne; @Entity public class Quote { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - public long id; + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public long id; - @OneToOne(cascade = CascadeType.PERSIST) - public Person person; - public String quote; + @OneToOne(cascade = CascadeType.PERSIST) + public Person person; + public String quote; - @SuppressWarnings("unused") - private Quote() { - // for object mappers - } + @SuppressWarnings("unused") + private Quote() { + // for object mappers + } - public Quote(Person person, String quote) { - this.person = person; - this.quote = quote; - } + public Quote(Person person, String quote) { + this.person = person; + this.quote = quote; + } - @Override - public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } + @Override + public boolean equals(Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE); - } + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE); + } } \ No newline at end of file diff --git a/commons/src/test/java/commons/PersonTest.java b/commons/src/test/java/commons/PersonTest.java index d753178..93c545c 100644 --- a/commons/src/test/java/commons/PersonTest.java +++ b/commons/src/test/java/commons/PersonTest.java @@ -23,34 +23,34 @@ import org.junit.jupiter.api.Test; public class PersonTest { - @Test - public void checkConstructor() { - var p = new Person("f", "l"); - assertEquals("f", p.firstName); - assertEquals("l", p.lastName); - } + @Test + public void checkConstructor() { + var p = new Person("f", "l"); + assertEquals("f", p.firstName); + assertEquals("l", p.lastName); + } - @Test - public void equalsHashCode() { - var a = new Person("a", "b"); - var b = new Person("a", "b"); - assertEquals(a, b); - assertEquals(a.hashCode(), b.hashCode()); - } + @Test + public void equalsHashCode() { + var a = new Person("a", "b"); + var b = new Person("a", "b"); + assertEquals(a, b); + assertEquals(a.hashCode(), b.hashCode()); + } - @Test - public void notEqualsHashCode() { - var a = new Person("a", "b"); - var b = new Person("a", "c"); - assertNotEquals(a, b); - assertNotEquals(a.hashCode(), b.hashCode()); - } + @Test + public void notEqualsHashCode() { + var a = new Person("a", "b"); + var b = new Person("a", "c"); + assertNotEquals(a, b); + assertNotEquals(a.hashCode(), b.hashCode()); + } - @Test - public void hasToString() { - var actual = new Person("a", "b").toString(); - assertTrue(actual.contains(Person.class.getSimpleName())); - assertTrue(actual.contains("\n")); - assertTrue(actual.contains("firstName")); - } + @Test + public void hasToString() { + var actual = new Person("a", "b").toString(); + assertTrue(actual.contains(Person.class.getSimpleName())); + assertTrue(actual.contains("\n")); + assertTrue(actual.contains("firstName")); + } } \ No newline at end of file diff --git a/commons/src/test/java/commons/QuoteTest.java b/commons/src/test/java/commons/QuoteTest.java index bca55f1..85ee201 100644 --- a/commons/src/test/java/commons/QuoteTest.java +++ b/commons/src/test/java/commons/QuoteTest.java @@ -23,36 +23,36 @@ import org.junit.jupiter.api.Test; public class QuoteTest { - private static final Person SOME_PERSON = new Person("a", "b"); + private static final Person SOME_PERSON = new Person("a", "b"); - @Test - public void checkConstructor() { - var q = new Quote(SOME_PERSON, "q"); - assertEquals(SOME_PERSON, q.person); - assertEquals("q", q.quote); - } + @Test + public void checkConstructor() { + var q = new Quote(SOME_PERSON, "q"); + assertEquals(SOME_PERSON, q.person); + assertEquals("q", q.quote); + } - @Test - public void equalsHashCode() { - var a = new Quote(new Person("a", "b"), "c"); - var b = new Quote(new Person("a", "b"), "c"); - assertEquals(a, b); - assertEquals(a.hashCode(), b.hashCode()); - } + @Test + public void equalsHashCode() { + var a = new Quote(new Person("a", "b"), "c"); + var b = new Quote(new Person("a", "b"), "c"); + assertEquals(a, b); + assertEquals(a.hashCode(), b.hashCode()); + } - @Test - public void notEqualsHashCode() { - var a = new Quote(new Person("a", "b"), "c"); - var b = new Quote(new Person("a", "b"), "d"); - assertNotEquals(a, b); - assertNotEquals(a.hashCode(), b.hashCode()); - } + @Test + public void notEqualsHashCode() { + var a = new Quote(new Person("a", "b"), "c"); + var b = new Quote(new Person("a", "b"), "d"); + assertNotEquals(a, b); + assertNotEquals(a.hashCode(), b.hashCode()); + } - @Test - public void hasToString() { - var actual = new Quote(new Person("a", "b"), "c").toString(); - assertTrue(actual.contains(Quote.class.getSimpleName())); - assertTrue(actual.contains("\n")); - assertTrue(actual.contains("person")); - } + @Test + public void hasToString() { + var actual = new Quote(new Person("a", "b"), "c").toString(); + assertTrue(actual.contains(Quote.class.getSimpleName())); + assertTrue(actual.contains("\n")); + assertTrue(actual.contains("person")); + } } \ No newline at end of file diff --git a/server/src/main/java/server/api/PersonListingController.java b/server/src/main/java/server/api/PersonListingController.java index 5f2bf96..ea06a74 100644 --- a/server/src/main/java/server/api/PersonListingController.java +++ b/server/src/main/java/server/api/PersonListingController.java @@ -30,23 +30,23 @@ import commons.Person; @RequestMapping("/api/people") public class PersonListingController { - private List people = new LinkedList<>(); + private List people = new LinkedList<>(); - public PersonListingController() { - people.add(new Person("Mickey", "Mouse")); - people.add(new Person("Donald", "Duck")); - } + public PersonListingController() { + people.add(new Person("Mickey", "Mouse")); + people.add(new Person("Donald", "Duck")); + } - @GetMapping("/") - public List list() { - return people; - } + @GetMapping("/") + public List list() { + return people; + } - @PostMapping("/") - public List add(@RequestBody Person p) { - if (!people.contains(p)) { - people.add(p); - } - return people; - } + @PostMapping("/") + public List add(@RequestBody Person p) { + if (!people.contains(p)) { + people.add(p); + } + return people; + } } \ No newline at end of file diff --git a/server/src/test/java/server/api/PersonListingControllerTest.java b/server/src/test/java/server/api/PersonListingControllerTest.java index 2aee4ab..97b15fe 100644 --- a/server/src/test/java/server/api/PersonListingControllerTest.java +++ b/server/src/test/java/server/api/PersonListingControllerTest.java @@ -26,28 +26,28 @@ import commons.Person; public class PersonListingControllerTest { - private static final Person MICKEY = new Person("Mickey", "Mouse"); - private static final Person DONALD = new Person("Donald", "Duck"); - private static final Person SCROOGE = new Person("Scrooge", "McDuck"); + private static final Person MICKEY = new Person("Mickey", "Mouse"); + private static final Person DONALD = new Person("Donald", "Duck"); + private static final Person SCROOGE = new Person("Scrooge", "McDuck"); - private PersonListingController sut; + private PersonListingController sut; - @BeforeEach - public void setup() { - sut = new PersonListingController(); - } + @BeforeEach + public void setup() { + sut = new PersonListingController(); + } - @Test - public void containsTwoDefaultNames() { - var actual = sut.list(); - var expected = List.of(MICKEY, DONALD); - assertEquals(expected, actual); - } + @Test + public void containsTwoDefaultNames() { + var actual = sut.list(); + var expected = List.of(MICKEY, DONALD); + assertEquals(expected, actual); + } - @Test - public void canAddPeople() { - var actual = sut.add(SCROOGE); - var expected = List.of(MICKEY, DONALD, SCROOGE); - assertEquals(expected, actual); - } + @Test + public void canAddPeople() { + var actual = sut.add(SCROOGE); + var expected = List.of(MICKEY, DONALD, SCROOGE); + assertEquals(expected, actual); + } } \ No newline at end of file