Skip to content
Permalink
Browse files

8183266: [TESTBUG]Add test to cover XPathEvaluationResult.XPathResult…

…Type.getQNameType method

Reviewed-by: joehw
  • Loading branch information
fguallini authored and JoeWang-Java committed May 5, 2020
1 parent a899004 commit 80d280263a4afe9130029c8032ce6cbe2c69e81e
Showing with 18 additions and 5 deletions.
  1. +18 −5 src/java.xml/share/classes/javax/xml/xpath/XPathEvaluationResult.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -85,25 +85,38 @@
/**
* Compares this type to the specified class type.
* @param clsType class type
* @return true if the argument is not null and is a class type that
* @return true if the argument is not null and is a class type or accepted subtype that
* matches that this type represents, false otherwise.
*/
private boolean equalsClassType(Class<?> clsType) {
Objects.nonNull(clsType);
if (clsType.isAssignableFrom(this.clsType)) {
if (Objects.nonNull(clsType) && this.clsType.isAssignableFrom(clsType)) {
if (this.clsType == Number.class) {
return isAcceptedNumberSubType(clsType);
}
return true;
}
return false;
}

/**
* Compares the specified class type to accepted subtypes of number.
* @param clsType class type
* @return true if class type is an accepted subtype of Number, false otherwise
*/
private boolean isAcceptedNumberSubType(Class<?> clsType) {
return clsType.isAssignableFrom(Double.class) ||
clsType.isAssignableFrom(Integer.class) ||
clsType.isAssignableFrom(Long.class);
}

/**
* Returns the QName type as specified in {@link XPathConstants} that
* corresponds to the specified class type.
* @param clsType a class type that the enum type supports
* @return the QName type that matches with the specified class type,
* null if there is no match
*/
static public QName getQNameType(Class<?> clsType) {
static public QName getQNameType(Class<?> clsType) {
for (XPathResultType type : XPathResultType.values()) {
if (type.equalsClassType(clsType)) {
return type.qnameType;

0 comments on commit 80d2802

Please sign in to comment.