Skip to content

Commit

Permalink
Move static nested CDI beans out into their own classes
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Evans <tevans@uk.ibm.com>
  • Loading branch information
tevans78 committed Jan 23, 2018
1 parent 7b251fd commit 507836e
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2016-2018 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;

import java.util.List;
import java.util.Set;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;

@Dependent
public class ClassConverterBean {
@Inject
@ConfigProperty(name = "tck.config.test.javaconfig.converter.class")
private Class testClass;

@Inject
@ConfigProperty(name = "tck.config.test.javaconfig.converter.class.array")
private Class[] testClasses;

@Inject
@ConfigProperty(name = "tck.config.test.javaconfig.converter.class.array")
private Set<Class> testClassSet;

@Inject
@ConfigProperty(name = "tck.config.test.javaconfig.converter.class.array")
private List<Class> testClassList;

public Class getTestClass(){
return testClass;
}

public Class[] getTestClasses(){
return testClasses;
}

public Set<Class> getTestClassSet(){
return testClassSet;
}

public List<Class> getTestClassList(){
return testClassList;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2017 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -24,14 +24,10 @@

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand Down Expand Up @@ -81,31 +77,12 @@ public void testClassConverterWithLookup() {

@Test
public void testConverterForClassLoadedInBean() {
assertEquals(classConverterBean.testClass, ClassConverterTest.class);
assertEquals(classConverterBean.testClasses.length, 2);
assertEquals(classConverterBean.testClasses, new Class[]{ClassConverterTest.class, String.class});
assertEquals(classConverterBean.testClassSet.size(), 2);
assertEquals(classConverterBean.testClassSet, new LinkedHashSet<>(Arrays.asList(ClassConverterTest.class, String.class)));
assertEquals(classConverterBean.testClassList.size(), 2);
assertEquals(classConverterBean.testClassList, Arrays.asList(ClassConverterTest.class, String.class));
}

@Dependent
public static class ClassConverterBean {
@Inject
@ConfigProperty(name = "tck.config.test.javaconfig.converter.class")
private Class testClass;

@Inject
@ConfigProperty(name = "tck.config.test.javaconfig.converter.class.array")
private Class[] testClasses;

@Inject
@ConfigProperty(name = "tck.config.test.javaconfig.converter.class.array")
private Set<Class> testClassSet;

@Inject
@ConfigProperty(name = "tck.config.test.javaconfig.converter.class.array")
private List<Class> testClassList;
assertEquals(classConverterBean.getTestClass(), ClassConverterTest.class);
assertEquals(classConverterBean.getTestClasses().length, 2);
assertEquals(classConverterBean.getTestClasses(), new Class[]{ClassConverterTest.class, String.class});
assertEquals(classConverterBean.getTestClassSet().size(), 2);
assertEquals(classConverterBean.getTestClassSet(), new LinkedHashSet<>(Arrays.asList(ClassConverterTest.class, String.class)));
assertEquals(classConverterBean.getTestClassList().size(), 2);
assertEquals(classConverterBean.getTestClassList(), Arrays.asList(ClassConverterTest.class, String.class));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2017 Contributors to the Eclipse Foundation
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -23,11 +23,9 @@

import java.time.YearMonth;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;
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.ConvTestTypeWStringValueOf;
Expand Down Expand Up @@ -106,8 +104,8 @@ public void testImplicitConverterCharSequenceParseJavaTime() {

@Test
public void testImplicitConverterCharSequenceParseJavaTimeInjection() {
Assert.assertNotNull(parserConverterInjection.yearMonth);
Assert.assertEquals(parserConverterInjection.yearMonth, YearMonth.parse("2017-12"));
Assert.assertNotNull(parserConverterInjection.getYearMonth());
Assert.assertEquals(parserConverterInjection.getYearMonth(), YearMonth.parse("2017-12"));
}

@Test
Expand All @@ -118,11 +116,4 @@ public void testImplicitConverterEnumValueOf() {
Assert.assertEquals(value, SomeEnumToConvert.BAZ);
Assert.assertEquals(value.name(), "BAZ");
}

@Dependent
public static class ParseConverterInjection {
private @Inject @ConfigProperty(name = "tck.config.test.javaconfig.converter.implicit.charSequenceParse.yearmonth") YearMonth yearMonth;

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2016-2018 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;

import java.time.YearMonth;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;

@Dependent
public class ParseConverterInjection {
private @Inject @ConfigProperty(name = "tck.config.test.javaconfig.converter.implicit.charSequenceParse.yearmonth") YearMonth yearMonth;

public YearMonth getYearMonth(){
return yearMonth;
}
}


0 comments on commit 507836e

Please sign in to comment.