1 /*
2 * *************************************************************************************************************************************************************
3 *
4 * SteelBlue: DCI User Interfaces
5 * http://tidalwave.it/projects/steelblue
6 *
7 * Copyright (C) 2015 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8 *
9 * *************************************************************************************************************************************************************
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18 *
19 * *************************************************************************************************************************************************************
20 *
21 * git clone https://bitbucket.org/tidalwave/steelblue-src
22 * git clone https://github.com/tidalwave-it/steelblue-src
23 *
24 * *************************************************************************************************************************************************************
25 */
26 package it.tidalwave.ui.core;
27
28 import it.tidalwave.util.Callback;
29 import org.testng.annotations.BeforeMethod;
30 import org.testng.annotations.Test;
31 import static it.tidalwave.ui.core.UserNotificationWithFeedback.*;
32 import static org.mockito.Mockito.*;
33 import static org.assertj.core.api.Assertions.assertThat;
34
35 /***************************************************************************************************************************************************************
36 *
37 * @author Fabrizio Giudici
38 *
39 **************************************************************************************************************************************************************/
40 public class UserNotificationWithFeedbackTest
41 {
42 private Callback onConfirm;
43
44 private Callback onCancel;
45
46 /**********************************************************************************************************************************************************/
47 @BeforeMethod
48 public void setup()
49 {
50 onConfirm = mock(Callback.class);
51 onCancel = mock(Callback.class);
52 }
53
54 /**********************************************************************************************************************************************************/
55 @Test
56 public void test_default_notification()
57 {
58 // when
59 final var underTest = notificationWithFeedback();
60 // then
61 assertThat(underTest.getText()).isEmpty();
62 assertThat(underTest.getCaption()).isEmpty();
63 assertThat(underTest.getFeedback().canCancel()).isFalse();
64 assertThat(underTest.getFeedback().canConfirm()).isFalse();
65 }
66
67 /**********************************************************************************************************************************************************/
68 @Test
69 public void test_notification_with_hardwired_attributes()
70 {
71 // when
72 final var underTest = notificationWithFeedback().withText("text")
73 .withCaption("caption");
74 // then
75 assertThat(underTest.getText()).isEqualTo("text");
76 assertThat(underTest.getCaption()).isEqualTo("caption");
77 assertThat(underTest.getFeedback().canCancel()).isFalse();
78 assertThat(underTest.getFeedback().canConfirm()).isFalse();
79 }
80
81 /**********************************************************************************************************************************************************/
82 @Test
83 public void test_notification_with_bundle_attributes()
84 {
85 // when
86 final var underTest = notificationWithFeedback().withText(UserNotificationWithFeedbackTest.class, "text", "param")
87 .withCaption(UserNotificationWithFeedbackTest.class, "caption", "param");
88 // then
89 assertThat(underTest.getText()).isEqualTo("The text with param");
90 assertThat(underTest.getCaption()).isEqualTo("The caption with param");
91 assertThat(underTest.getFeedback().canCancel()).isFalse();
92 assertThat(underTest.getFeedback().canConfirm()).isFalse();
93 }
94
95 /**********************************************************************************************************************************************************/
96 @Test
97 public void test_notification_with_confirm()
98 throws Throwable
99 {
100 // given
101 final var underTest = notificationWithFeedback().withFeedback(feedback().withOnConfirm(onConfirm));
102 // when
103 underTest.confirm();
104 // then
105 assertThat(underTest.getFeedback().canCancel()).isFalse();
106 assertThat(underTest.getFeedback().canConfirm()).isTrue();
107 verify(onConfirm).call();
108 verifyNoInteractions(onCancel);
109 }
110
111 /**********************************************************************************************************************************************************/
112 @Test
113 public void test_notification_with_cancel()
114 throws Throwable
115 {
116 // given
117 final var underTest = notificationWithFeedback().withFeedback(feedback().withOnCancel(onCancel));
118 // when
119 underTest.cancel();
120 // then
121 assertThat(underTest.getFeedback().canCancel()).isTrue();
122 assertThat(underTest.getFeedback().canConfirm()).isFalse();
123 verify(onCancel).call();
124 verifyNoInteractions(onConfirm);
125 }
126 }