/** * Class constructor specifying the evaluator to use and the id of the window we want to test. * The constructor checks if the given id does correspond to a window. * * @param evaluator a technology specific evaluator * @param id the id (unique) of the window */ public Window(Evaluator evaluator, String id) { super(evaluator, id); checkIsExpectedComponent(Window); } }
/** * To simulate the closing of a window * * @param window the window to close */ public static void close(Window window) { window.close(); }
@Test public void test_toString() { Window window = new Window(evaluator, id); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.title(window)).thenReturn("windowTitle"); assertThat(window.toString(), is("class org.testatoo.core.component.Window with state : enabled:true, visible:true, title:windowTitle")); } }
@Test public void test_component_can_contain_other_component() { when(evaluator.componentType(id)).thenReturn(Window); Window container = new Window(evaluator, id); Component contained_component = new Component(evaluator, id); Component not_contained_component = new Component(evaluator, id); when(evaluator.contains(container, contained_component)).thenReturn(true); assertThat(container.contains(contained_component), is(true)); when(evaluator.contains(container, not_contained_component)).thenReturn(false); assertThat(container.contains(not_contained_component), is(false)); verify(evaluator, times(2)).contains(any(Container.class), any(Component.class)); }
@Test public void test_window_usage_through_language() { when(evaluator.componentType(id)).thenReturn(Window); Window window = new Window(evaluator, id); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.title(window)).thenReturn("windowTitle"); close(window); verify(evaluator, times(1)).close(window); }
@Test public void test_component_type() { evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(Radio); try { new Window(evaluator, id); fail(); } catch (ComponentException e) { assertThat(e.getMessage(), is("The component with id=" + id + " is not a Window but a Radio")); } }