Path: blob/master/test/langtools/jdk/jshell/ExpectedDiagnostic.java
40930 views
/*1* Copyright (c) 2014, 2015, 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 javax.tools.Diagnostic;2425import jdk.jshell.Diag;26import static org.testng.Assert.assertEquals;2728public class ExpectedDiagnostic {2930private final String code;31private final long startPosition;32private final long endPosition;33private final long position;34private final long lineNumber;35private final long columnNumber;36private final Diagnostic.Kind kind;3738public ExpectedDiagnostic(39String code, long startPosition, long endPosition,40long position, long lineNumber, long columnNumber,41Diagnostic.Kind kind) {42this.code = code;43this.startPosition = startPosition;44this.endPosition = endPosition;45this.position = position;46this.lineNumber = lineNumber;47this.columnNumber = columnNumber;48this.kind = kind;49}5051public long getStartPosition() {52return startPosition;53}5455public String getCode() {56return code;57}5859public long getEndPosition() {60return endPosition;61}6263public long getPosition() {64return position;65}6667public long getLineNumber() {68return lineNumber;69}7071public long getColumnNumber() {72return columnNumber;73}7475public Diagnostic.Kind getKind() {76return kind;77}7879public void assertDiagnostic(Diag diagnostic) {80String code = diagnostic.getCode();81assertEquals(code, this.code, "Expected error: " + this.code + ", got: " + code);82assertEquals(diagnostic.isError(), kind == Diagnostic.Kind.ERROR);83if (startPosition != -1) {84assertEquals(diagnostic.getStartPosition(), startPosition, "Start position");85}86if (endPosition != -1) {87assertEquals(diagnostic.getEndPosition(), endPosition, "End position");88}89if (position != -1) {90assertEquals(diagnostic.getPosition(), position, "Position");91}92}93}949596