Skip to content

Commit

Permalink
#383 - change the implicit converter ordering
Browse files Browse the repository at this point in the history
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
  • Loading branch information
Emily-Jiang committed Jan 16, 2020
1 parent c520c7d commit ba67ffc
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 4 deletions.
Expand Up @@ -91,8 +91,8 @@
* <ul>
* <li>the target type {@code T} has a {@code public static T of(String)} method, or</li>
* <li>the target type {@code T} has a {@code public static T valueOf(String)} method, or</li>
* <li>the target type {@code T} has a public Constructor with a String parameter, or</li>
* <li>the target type {@code T} has a {@code public static T parse(CharSequence)} method</li>
* <li>the target type {@code T} has a {@code public static T parse(CharSequence)} method, or</li>
* <li>the target type {@code T} has a public Constructor with a String parameter.</li>
* </ul>
* @author <a href="mailto:rsmeral@apache.org">Ron Smeral</a>
Expand Down
4 changes: 2 additions & 2 deletions spec/src/main/asciidoc/converters.asciidoc
Expand Up @@ -97,8 +97,8 @@ If no built-in nor custom `Converter` exists for a requested Type `T`, an implic

* The target type `T` has a `public static T of(String)` method, or
* The target type `T` has a `public static T valueOf(String)` method, or
* The target type `T` has a public Constructor with a `String` parameter, or
* The target type `T` has a `public static T parse(CharSequence)` method
* The target type `T` has a `public static T parse(CharSequence)` method, or
* The target type `T` has a public Constructor with a `String` parameter

=== Cleaning up a Converter

Expand Down
Expand Up @@ -26,6 +26,9 @@
import javax.inject.Inject;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.tck.converters.implicit.ConvTestSequenceOfBeforeValueOf;
import org.eclipse.microprofile.config.tck.converters.implicit.ConvTestSequenceParseBeforeConstructor;
import org.eclipse.microprofile.config.tck.converters.implicit.ConvTestSequenceValueOfBeforeParse;
import org.eclipse.microprofile.config.tck.converters.implicit.ConvTestTypeWCharSequenceParse;
import org.eclipse.microprofile.config.tck.converters.implicit.ConvTestTypeWStringCt;
import org.eclipse.microprofile.config.tck.converters.implicit.ConvTestTypeWStringOf;
Expand Down Expand Up @@ -124,4 +127,32 @@ public void testImplicitConverterEnumValueOf() {
Assert.assertEquals(value, SomeEnumToConvert.BAZ);
Assert.assertEquals(value.name(), "BAZ");
}

@Test
public void testImplicitConverterSquenceOfBeforeValueOf() {
ConvTestSequenceOfBeforeValueOf value = config.getValue
("tck.config.test.javaconfig.converter.implicit.sequence.ofBeforevalueOf",
ConvTestSequenceOfBeforeValueOf.class);
Assert.assertNotNull(value);
Assert.assertEquals(value.getVal(), "ofBeforeValueOf");
}

@Test
public void testImplicitConverterSquenceValueOfBeforeParse() {
ConvTestSequenceValueOfBeforeParse value = config.getValue
("tck.config.test.javaconfig.converter.implicit.sequence.valueOfBeforeParse",
ConvTestSequenceValueOfBeforeParse.class);
Assert.assertNotNull(value);
Assert.assertEquals(value.getVal(), "valueOfBeforeParse");
}
@Test
public void testImplicitConverterSquenceParseBeforeConstructor() {
ConvTestSequenceParseBeforeConstructor value = config.getValue
("tck.config.test.javaconfig.converter.implicit.sequence.parseBeforeConstructor",
ConvTestSequenceParseBeforeConstructor.class);
Assert.assertNotNull(value);
Assert.assertEquals(value.getVal(), "parseBeforeConstructor");
}


}
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.microprofile.config.tck.converters.implicit;

/**
* Part of the implicit Converter test.
*
* Sample class which has a of(String) and valueOf(String) method.
* The method of() should be used instead of valueOf().
*
* @author <a href="mailto:emijiang@uk.ibm.com">Emily Jiang</a>
*/
public class ConvTestSequenceOfBeforeValueOf {
private String val;

public static ConvTestSequenceOfBeforeValueOf of(String val) {
ConvTestSequenceOfBeforeValueOf o = new ConvTestSequenceOfBeforeValueOf();
o.val = val.toString();
return o;
}

public static ConvTestSequenceOfBeforeValueOf valueOf(String val) {
ConvTestSequenceOfBeforeValueOf o = new ConvTestSequenceOfBeforeValueOf();
o.val = "valueOf";
return o;
}

public String getVal() {
return val;
}
}
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.microprofile.config.tck.converters.implicit;

/**
* Part of the implicit Converter test.
*
* Sample class which has a parse(CharSequence) and Constructor(String) method.
* The method parse(CharSequence) should be used instead of constructor(String).
*
* @author <a href="mailto:emijiang@uk.ibm.com">Emily Jiang</a>
*/
public class ConvTestSequenceParseBeforeConstructor {
private String val;

public static ConvTestSequenceParseBeforeConstructor parse(CharSequence val) {
ConvTestSequenceParseBeforeConstructor o = new ConvTestSequenceParseBeforeConstructor();
o.val = val.toString();
return o;
}

ConvTestSequenceParseBeforeConstructor() {
}

public ConvTestSequenceParseBeforeConstructor(String val) {
this.val = "constructor";
}

public String getVal() {
return val;
}
}
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.microprofile.config.tck.converters.implicit;

/**
* Part of the implicit Converter test.
*
* Sample class which has a parse(CharSequence) and valueOf(String) method.
* The method valueOf(String) should be used instead of the parse(Charsequence) method.
*
* @author <a href="mailto:emijiang@uk.ibm.com">Emily Jiang</a>
*/
public class ConvTestSequenceValueOfBeforeParse {
private String val;

public static ConvTestSequenceValueOfBeforeParse parse(CharSequence val) {
ConvTestSequenceValueOfBeforeParse o = new ConvTestSequenceValueOfBeforeParse();
o.val = "parse";
return o;
}

public static ConvTestSequenceValueOfBeforeParse valueOf(String val) {
ConvTestSequenceValueOfBeforeParse o = new ConvTestSequenceValueOfBeforeParse();
o.val = val;
return o;
}

public String getVal() {
return val;
}
}
Expand Up @@ -134,6 +134,10 @@ tck.config.test.javaconfig.converter.implicit.stringOf=stringOf
tck.config.test.javaconfig.converter.implicit.charSequenceParse.yearmonth=2017-12
tck.config.test.javaconfig.converter.implicit.enumValueOf=BAZ

tck.config.test.javaconfig.converter.implicit.sequence.ofBeforevalueOf=ofBeforevalueOf
tck.config.test.javaconfig.converter.implicit.sequence.valueOfBeforeParse=valueOfBeforeParse
tck.config.test.javaconfig.converter.implicit.sequence.parseBeforeConstructor=parseBeforeConstructor


#array converter tests

Expand Down

0 comments on commit ba67ffc

Please sign in to comment.