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.spi;
27  
28  import jakarta.annotation.Nonnull;
29  import java.util.Collection;
30  import java.util.List;
31  import java.util.Map;
32  import java.util.function.Function;
33  import it.tidalwave.ui.core.PanelGroupProvider;
34  import it.tidalwave.ui.core.PanelGroupControl.Group;
35  import it.tidalwave.util.As;
36  import org.testng.annotations.Test;
37  import static it.tidalwave.ui.core.PanelGroupControl.Options.*;
38  import static it.tidalwave.ui.core.PanelGroupControl.DefaultGroups.*;
39  import static org.mockito.Mockito.*;
40  
41  /***************************************************************************************************************************************************************
42   *
43   * @author      Fabrizio Giudici
44   *
45   **************************************************************************************************************************************************************/
46  public class PanelGroupControlSupportTest
47    {
48      static class MockPanel {}
49  
50      static class MockNode {}
51  
52      static class Fixture extends PanelGroupControlSupport<MockPanel, MockNode>
53        {
54          public Fixture (@Nonnull final Function<As, Collection<? extends PanelGroupProvider<MockNode>>> pgpProvider)
55            {
56              super(pgpProvider);
57            }
58  
59          @Override
60          protected void assemble (@Nonnull final Group group,
61                                   @Nonnull final List<? extends PanelGroupProvider<MockNode>> panelProviders,
62                                   @Nonnull final MockPanel topContainer,
63                                   @Nonnull final Map<Group, List<Options>> groupOptions,
64                                   @Nonnull final List<Options> options)
65            {
66              // not needed in tests
67            }
68  
69          @Override
70          public void show (@Nonnull final Object object)
71            {
72              // not needed in tests
73            }
74        }
75  
76      @Test @SuppressWarnings("unchecked")
77      public void test()
78        {
79          // given
80          final var panelLeft   = mock(MockPanel.class);
81          final var panelCenter = mock(MockPanel.class);
82          final var panelBottom = mock(MockPanel.class);
83          final var panelRight  = mock(MockPanel.class);
84          final var ppLeft1   = createMock(LEFT,   "Left 1");
85          final var ppLeft2   = createMock(LEFT,   "Left 2");
86          final var ppRight1  = createMock(RIGHT,  "Right 1");;
87          final var ppRight2  = createMock(RIGHT,  "Right 2");
88          final var ppCenter1 = createMock(CENTER, "Center 1");
89          final var ppCenter2 = createMock(CENTER, "Center 2");
90          final var ppBottom1 = createMock(BOTTOM, "Bottom 1");
91          final var ppBottom2 = createMock(BOTTOM, "Bottom 2");
92          final var underTest = spy(new Fixture(ignored -> List.of(ppLeft1, ppLeft2, ppRight1, ppRight2, ppCenter1, ppCenter2, ppBottom1, ppBottom2)));
93          final var configuration = underTest.config()
94                                             .withGroup(LEFT, panelLeft, ALWAYS_WRAP)
95                                             .withGroup(CENTER, panelCenter, ALWAYS_WRAP)
96                                             .withGroup(BOTTOM, panelBottom, ALWAYS_WRAP)
97                                             .withGroup(RIGHT, panelRight, ALWAYS_WRAP)
98                                             .withOptions(DISABLE_ACCORDION_ANIMATION);
99          // when
100         underTest.setup(configuration);
101         // then
102         verify(underTest).assemble(eq(LEFT),   eq(List.of(ppLeft1,   ppLeft2)),   same(panelLeft),   any(Map.class), any(List.class));
103         verify(underTest).assemble(eq(RIGHT),  eq(List.of(ppRight1,  ppRight2)),  same(panelRight),  any(Map.class), any(List.class));
104         verify(underTest).assemble(eq(CENTER), eq(List.of(ppCenter1, ppCenter2)), same(panelCenter), any(Map.class), any(List.class));
105         verify(underTest).assemble(eq(BOTTOM), eq(List.of(ppBottom1, ppBottom2)), same(panelBottom), any(Map.class), any(List.class));
106       }
107 
108     @Nonnull
109     private static PanelGroupProviderSupport<MockNode> createMock (@Nonnull final Group group, @Nonnull final String name)
110       {
111         return new PanelGroupProviderSupport<>(group, name, MockNode::new) {};
112       }
113   }