View Javadoc
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.hamcrest.CoreMatchers.is;
34  import static org.hamcrest.MatcherAssert.assertThat;
35  
36  /***************************************************************************************************************************************************************
37   *
38   * @author  Fabrizio Giudici
39   *
40   **************************************************************************************************************************************************************/
41  public class UserNotificationWithFeedbackTest
42    {
43      private Callback onConfirm;
44  
45      private Callback onCancel;
46  
47      /**********************************************************************************************************************************************************/
48      @BeforeMethod
49      public void setup()
50        {
51          onConfirm = mock(Callback.class);
52          onCancel = mock(Callback.class);
53        }
54  
55      /**********************************************************************************************************************************************************/
56      @Test
57      public void test_default_notification()
58        {
59          // when
60          final var underTest = notificationWithFeedback();
61          // then
62          assertThat(underTest.getText(), is(""));
63          assertThat(underTest.getCaption(), is(""));
64          assertThat(underTest.getFeedback().canCancel(), is(false));
65          assertThat(underTest.getFeedback().canConfirm(), is(false));
66        }
67  
68      /**********************************************************************************************************************************************************/
69      @Test
70      public void test_notification_with_hardwired_attributes()
71        {
72          // when
73          final var underTest = notificationWithFeedback().withText("text")
74                                                          .withCaption("caption");
75          // then
76          assertThat(underTest.getText(), is("text"));
77          assertThat(underTest.getCaption(), is("caption"));
78          assertThat(underTest.getFeedback().canCancel(), is(false));
79          assertThat(underTest.getFeedback().canConfirm(), is(false));
80        }
81  
82      /**********************************************************************************************************************************************************/
83      @Test
84      public void test_notification_with_bundle_attributes()
85        {
86          // when
87          final var underTest = notificationWithFeedback().withText(UserNotificationWithFeedbackTest.class, "text", "param")
88                                                          .withCaption(UserNotificationWithFeedbackTest.class, "caption", "param");
89          // then
90          assertThat(underTest.getText(), is("The text with param"));
91          assertThat(underTest.getCaption(), is("The caption with param"));
92          assertThat(underTest.getFeedback().canCancel(), is(false));
93          assertThat(underTest.getFeedback().canConfirm(), is(false));
94        }
95  
96      /**********************************************************************************************************************************************************/
97      @Test
98      public void test_notification_with_confirm()
99              throws Throwable
100       {
101         // given
102         final var underTest = notificationWithFeedback().withFeedback(feedback().withOnConfirm(onConfirm));
103         // when
104         underTest.confirm();
105         // then
106         assertThat(underTest.getFeedback().canCancel(), is(false));
107         assertThat(underTest.getFeedback().canConfirm(), is(true));
108         verify(onConfirm).call();
109         verifyNoInteractions(onCancel);
110       }
111 
112     /**********************************************************************************************************************************************************/
113     @Test
114     public void test_notification_with_cancel()
115             throws Throwable
116       {
117         // given
118         final var underTest = notificationWithFeedback().withFeedback(feedback().withOnCancel(onCancel));
119         // when
120         underTest.cancel();
121         // then
122         assertThat(underTest.getFeedback().canCancel(), is(true));
123         assertThat(underTest.getFeedback().canConfirm(), is(false));
124         verify(onCancel).call();
125         verifyNoInteractions(onConfirm);
126       }
127   }