Skip to content

Commit 57f673e

Browse files
committed
Removed test that connects to real server, style changes
1 parent 72eee3b commit 57f673e

4 files changed

Lines changed: 42 additions & 73 deletions

File tree

src/main/java/com/example/HelloController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
import javafx.scene.control.*;
66
import javafx.util.Callback;
77

8-
import java.io.IOException;
98

109
/**
1110
* Controller layer: mediates between the view (FXML) and the model.
1211
*/
1312
public class HelloController {
1413

1514
private final HelloModel model = new HelloModel(new NtfyConnectionImpl());
16-
public ListView<NtfyMessageDto> messageView;
1715

1816
@FXML
19-
private TextArea myTextArea;
17+
private ListView<NtfyMessageDto> messageView;
2018

2119
@FXML
2220
private TextArea chatArea;
@@ -32,11 +30,13 @@ private void initialize() {
3230
if (messageLabel != null) {
3331
messageLabel.setText(model.getGreeting());
3432
}
35-
messageView.setItems(model.getMessages());
36-
messageView.setCellFactory(showOnlyMessages());
37-
33+
messageView.setItems(model.getMessages());
34+
messageView.setCellFactory(showOnlyMessages());
3835
}
3936

37+
38+
39+
4040
private static Callback<ListView<NtfyMessageDto>, ListCell<NtfyMessageDto>> showOnlyMessages() {
4141
return List -> new ListCell<>() {
4242
@Override

src/main/resources/com/example/hello-view.fxml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,23 @@
33
<?import javafx.geometry.*?>
44
<?import javafx.scene.control.*?>
55
<?import javafx.scene.layout.*?>
6-
<?import javafx.scene.text.*?>
76

8-
<VBox stylesheets="@../../css/style.css" prefHeight="500.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1"
9-
fx:controller="com.example.HelloController">
10-
11-
<Label fx:id="messageLabel" text="Hello, JavaFX!"/>
12-
<BorderPane VBox.vgrow="ALWAYS" >
13-
<center>
14-
<ListView fx:id="messageView" >
15-
<padding>
16-
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0"/>
17-
</padding>
18-
</ListView>
19-
</center>
7+
<VBox prefHeight="500.0" prefWidth="300.0" stylesheets="@../../css/style.css" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.HelloController">
208

9+
<Label fx:id="messageLabel" alignment="CENTER" contentDisplay="CENTER" maxWidth="Infinity" text="Hello, JavaFX!" VBox.vgrow="NEVER" />
10+
<BorderPane VBox.vgrow="ALWAYS">
11+
<center>
12+
<ListView fx:id="messageView">
13+
<padding>
14+
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
15+
</padding>
16+
</ListView>
17+
</center>
2118
</BorderPane>
22-
<SplitPane dividerPositions="0.7" VBox.vgrow="NEVER">
23-
<items>
24-
<TextArea fx:id="chatArea" wrapText="true" maxHeight="-Infinity" prefHeight="100.0" prefRowCount="3"/>
2519

26-
<Button fx:id="chatButton" text="send message" onAction="#sendMessage" />
27-
</items>
28-
</SplitPane>
20+
<HBox VBox.vgrow="NEVER" alignment="CENTER_LEFT"> <padding> <Insets bottom="5.0" left="10.0" right="10.0" top="10.0" /></padding>
21+
<TextArea fx:id="chatArea" opacity="0.8" prefRowCount="3" wrapText="true" HBox.hgrow="ALWAYS" />
22+
<Button fx:id="chatButton" maxWidth="-Infinity" minWidth="-Infinity" onAction="#sendMessage" text="Send Message" />
23+
</HBox>
2924

3025
</VBox>

src/main/resources/css/style.css

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
styles.css
44
*/
55
.root {
6-
-fx-background-color: #ffffff, linear-gradient(to bottom, #8b0000, #ffd700);
6+
-fx-background-color:
7+
linear-gradient(to bottom,
8+
rgba(0,0,0,0.1) 0%,
9+
rgba(0,0,0,0) 10%),
10+
linear-gradient(to bottom,
11+
#8b0000 30%,
12+
#ffd700 100%);
713
-fx-background-insets: 0, 4;
814
-fx-background-radius: 0, 3;
15+
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.4), 10, 0.5, 0, 0)
916

1017
}
1118
.list-view {
@@ -21,41 +28,32 @@ styles.css
2128
-fx-border-color: transparent;
2229
-fx-control-inner-background: transparent;
2330
-fx-font-size: 14;
24-
}
25-
/* Remove background and border on hover */
26-
.list-cell:filled:hover {
27-
-fx-background-color: #e0e0e0;
28-
-fx-text-fill: #000000;
29-
}
30-
31-
.list-cell:filled:selected {
32-
33-
-fx-background-color: #007bff;
34-
-fx-text-fill: white;
35-
36-
-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.2), 5, 0, 0, 0);
37-
}
38-
39-
.list-cell:filled:selected .text {
4031
-fx-font-weight: bold;
32+
-fx-padding: 5 10 5 10;
4133
}
4234
.text-area{
43-
-fx-control-inner-background: transparent;
35+
-fx-control-inner-background: #FFFFFF;
4436
-fx-padding: 5px 7px;
4537
-fx-text-fill: black;
4638
-fx-font-size: 14;
4739

48-
-fx-border-radius: 8px;
40+
-fx-border-radius: 10;
41+
-fx-background-radius: 10;
4942
-fx-background-color: transparent;
5043
-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.2), 5, 0, 0, 0);
5144
}
45+
.text-area .content, .viewport {
46+
-fx-background-radius: 8;
47+
-fx-border-radius: 8;
48+
}
5249
.button{
53-
-fx-background-color: #007bff;
50+
-fx-background-color: #610202;
5451
-fx-text-fill: white;
55-
-fx-font-size: 16px;
56-
-fx-padding: 10px 20px;
52+
-fx-font-size: 12px;
53+
-fx-padding: 10 15 10 15;
5754
-fx-background-radius: 5px;
55+
-fx-border-radius: 8px;
5856
}
5957
.button:hover{
60-
-fx-background-color: #0056b3;
58+
-fx-background-color: #400101;
6159
}

src/test/java/com/example/HelloModelTest.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import com.github.tomakehurst.wiremock.client.WireMock;
55
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
66
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
7-
import javafx.application.Platform;
8-
import org.assertj.core.api.Assertions;
9-
import org.junit.jupiter.api.BeforeAll;
107
import org.junit.jupiter.api.DisplayName;
118
import org.junit.jupiter.api.Test;
129
import org.awaitility.Awaitility;
@@ -50,29 +47,8 @@ void sendMessageToFakeServer(WireMockRuntimeInfo wmRunTimeInfo) throws Interrupt
5047
.withRequestBody(matching("Hello World")));
5148
}
5249

53-
// Test för att se att vi får meddelanden tillbaka. receiveMessage?
5450
@Test
55-
void checkReceivedMessagesAfterSendingAMessageToServer() throws InterruptedException {
56-
//Arrange
57-
var conImp = new NtfyConnectionImpl();
58-
var model = new HelloModel(conImp);
59-
model.setMessageToSend("Hello World");
60-
//Act - When
61-
62-
model.sendMessage().join();
63-
64-
//Assert
65-
Awaitility.await()
66-
.atMost(Duration.ofSeconds(5))
67-
.pollInterval(Duration.ofMillis(100))
68-
.untilAsserted(() -> {
69-
assertThat(model.getMessages()).isNotEmpty();
70-
assertThat(model.getMessages().getLast().message()).contains("Hello World");
71-
});
72-
}
73-
74-
@Test
75-
void checkReceivedMessagesAfterSendingAMessageToAFakeServer(WireMockRuntimeInfo wmRunTimeInfo) throws InterruptedException {
51+
void checkReceivedMessagesAfterSendingAMessageToAFakeServer(WireMockRuntimeInfo wmRunTimeInfo) {
7652
// Arrange
7753
var conImp = new NtfyConnectionImpl("http://localhost:" + wmRunTimeInfo.getHttpPort());
7854

0 commit comments

Comments
 (0)