1 /* 2 * Copyright (c) 2007, 2017 Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package org.jemmy.control; 26 27 import java.util.Map; 28 import org.jemmy.Rectangle; 29 import org.jemmy.action.GetAction; 30 import org.jemmy.env.Environment; 31 import org.testng.annotations.AfterClass; 32 import org.testng.annotations.AfterMethod; 33 import org.testng.annotations.BeforeClass; 34 import org.testng.annotations.BeforeMethod; 35 import org.testng.annotations.Test; 36 37 import static org.testng.Assert.assertEquals; 38 import static org.testng.Assert.fail; 39 40 41 /** 42 * 43 * @author shura 44 */ 45 public class PropertiesTest { 46 47 public PropertiesTest() { 48 } 49 50 @BeforeClass 51 public static void setUpClass() throws Exception { 52 } 53 54 @AfterClass 55 public static void tearDownClass() throws Exception { 56 } 57 58 @BeforeMethod 59 public void setUp() { 60 } 61 62 @AfterMethod 63 public void tearDown() { 64 } 65 66 @Test 67 public void testNoException() { 68 Wrap<?> wrap = new TestWrap(false); 69 Map props = wrap.getProperties(); 70 assertEquals(props.get("x"), 10); 71 assertEquals(props.get("X"), 10); 72 assertEquals(props.get("getX"), 10.); 73 props = wrap.getPropertiesQiuet(); 74 assertEquals(props.get("x"), 10); 75 assertEquals(props.get("X"), 10); 76 assertEquals(props.get("getX"), 10.); 77 } 78 79 @Test 80 public void testException() { 81 Wrap<?> wrap = new TestWrap(true); 82 try { 83 wrap.getProperties(); 84 fail("No exception thrown"); 85 } catch (RuntimeException e) { 86 Map props = wrap.getPropertiesQiuet(); 87 assertEquals(props.get("x"), 10); 88 assertEquals(props.get("getX"), 10.); 89 } 90 } 91 92 @MethodProperties("getX") 93 @FieldProperties("x") 94 class TestWrap extends Wrap<Rectangle> { 95 96 boolean throwException; 97 98 public TestWrap(boolean throwException) { 99 super(Environment.getEnvironment(), new Rectangle(10, 20, 30, 40)); 100 this.throwException = throwException; 101 } 102 103 @Property("X") 104 public int getX() { 105 if (throwException) { 106 throw new RuntimeException("Exception while getting a property"); 107 } 108 return new GetAction<Integer>() { 109 110 @Override 111 public void run(Object... parameters) throws Exception { 112 setResult(getControl().x); 113 } 114 }.dispatch(getEnvironment()); 115 } 116 117 @Override 118 public Rectangle getScreenBounds() { 119 return getControl(); 120 } 121 } 122 }