Path: blob/master/test/jdk/java/awt/Headless/HeadlessBasicStroke.java
41149 views
/*1* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.*;2425/*26* @test27* @summary Check that BasicStroke constructors and get-methods do not28* throw exceptions in headless mode29* @run main/othervm -Djava.awt.headless=true HeadlessBasicStroke30*/313233public class HeadlessBasicStroke {34public static void main (String[] args) {35BasicStroke bs;3637// Constructors without exceptions38bs = new BasicStroke(1, BasicStroke.CAP_BUTT,39BasicStroke.JOIN_BEVEL, 3, null, -1);40bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 3,41new float[]{(float) 2.0, (float) 3.0}, 0);42bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 3,43new float[]{(float) 2.0, (float) 3.0}, 1);44bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, (float) 3);4546bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, (float) 3);4748bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, (float) 3);4950bs = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3);5152bs = new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 3);5354bs = new BasicStroke(1, BasicStroke.JOIN_ROUND, BasicStroke.CAP_SQUARE, 3);5556bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);5758bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);5960bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);6162bs = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);6364bs = new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND);6566bs = new BasicStroke(1, BasicStroke.JOIN_ROUND, BasicStroke.CAP_SQUARE);6768bs = new BasicStroke((float) 0.1);6970bs = new BasicStroke((float) 0.9);7172bs = new BasicStroke(4);7374bs = new BasicStroke(10);7576bs = new BasicStroke(20);7778bs = new BasicStroke(100);7980bs = new BasicStroke();8182// Constructors with exceptions83boolean exceptions = false;84try {85bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, (float) 0.2);86} catch (IllegalArgumentException e) {87exceptions = true;88}89if (!exceptions)90throw new RuntimeException("Constructor did not throw IllegalArgumentException when expected");9192exceptions = false;93try {94bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, (float) 0.2);95} catch (IllegalArgumentException e) {96exceptions = true;97}98if (!exceptions)99throw new RuntimeException("Constructor did not throw IllegalArgumentException when expected");100101exceptions = false;102try {103bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, (float) 0.2);104} catch (IllegalArgumentException e) {105exceptions = true;106}107if (!exceptions)108throw new RuntimeException("Constructor did not throw IllegalArgumentException when expected");109110exceptions = false;111try {112bs = new BasicStroke(1, 5678, 92039, 3);113} catch (IllegalArgumentException e) {114exceptions = true;115}116if (!exceptions)117throw new RuntimeException("Constructor did not throw IllegalArgumentException when expected");118119exceptions = false;120try {121bs = new BasicStroke(1, 5678, 92039);122} catch (IllegalArgumentException e) {123exceptions = true;124}125if (!exceptions)126throw new RuntimeException("Constructor did not throw IllegalArgumentException when expected");127128exceptions = false;129try {130bs = new BasicStroke((float) -0.9);131} catch (IllegalArgumentException e) {132exceptions = true;133}134if (!exceptions)135throw new RuntimeException("Constructor did not throw IllegalArgumentException when expected");136137// Create stroke shape138bs = new BasicStroke(20);139bs.createStrokedShape(new Rectangle(10, 10, 10, 10));140141// Get-methods142bs = new BasicStroke(100);143bs.getLineWidth();144bs.getEndCap();145bs.getLineJoin();146bs.getMiterLimit();147bs.getDashArray();148bs.getDashPhase();149}150}151152153