Skip to content

Commit

Permalink
Added tests for artifacts generated by the I18N annotation processor
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Holmstrom committed May 8, 2012
1 parent 35e7695 commit f368dc0
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2012 Petter Holmström
*
* 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 net.pkhsolutions.ceres.i18n.tests.pkga;

import net.pkhsolutions.ceres.i18n.annotations.Message;

/**
* Example class using the {@link Message} annotation.
*
* @author Petter Holmström
* @since 1.0
*/
@Message(key = "ExampleLocalizedClass.key", defaultValue = "Hello world ExampleLocalizedClass")
public class ExampleLocalizedClass {

@Message(key = "ExampleLocalizedClass.aField.key", defaultValue = "Hello world ExampleLocalizedClass.aField\nAnd a new line")
protected String aField;

@Message(key = "ExampleLocalizedClass.aMethod.key", defaultValue = "Hello world ExampleLocalizedClass.aMethod")
public void aMethod() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2012 Petter Holmström
*
* 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 net.pkhsolutions.ceres.i18n.tests.pkga;

import net.pkhsolutions.ceres.i18n.annotations.Message;
import net.pkhsolutions.ceres.i18n.annotations.Messages;

/**
* Example class using the {@link Messages} annotation.
*
* @author Petter Holmström
* @since 1.0
*/
@Messages({
@Message(key = "ExampleLocalizedClass2.key1", defaultValue = "Hello world ExampleLocalizedClass2.1"),
@Message(key = "ExampleLocalizedClass2.key2", defaultValue = "Hello world ExampleLocalizedClass2.2")
})
public class ExampleLocalizedClass2 {

@Messages({
@Message(key = "ExampleLocalizedClass2.aField.key1", defaultValue = "Hello world ExampleLocalizedClass2.aField1"),
@Message(key = "ExampleLocalizedClass2.aField.key2", defaultValue = "Hello world ExampleLocalizedClass2.aField2")
})
protected String aField;

@Messages({
@Message(key = "ExampleLocalizedClass2.aMethod.key1", defaultValue = "Hello world ExampleLocalizedClass2.aMethod1"),
@Message(key = "ExampleLocalizedClass2.aMethod.key2", defaultValue = "Hello world ExampleLocalizedClass2.aMethod2")
})
public void aMethod() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2012 Petter Holmström
*
* 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 net.pkhsolutions.ceres.i18n.tests.pkga;

import java.util.Arrays;
import java.util.Locale;
import net.pkhsolutions.ceres.common.holder.GlobalHolderStrategy;
import net.pkhsolutions.ceres.i18n.DefaultI18N;
import net.pkhsolutions.ceres.i18n.I18N;
import net.pkhsolutions.ceres.i18n.I18NHolder;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;

/**
* This test checks that the auto-generated artifacts in the {@code pkga}
* package are working as they should.
*
* @author Petter Holmström
* @since 1.0
*/
public class PkgaTest {

@Before
public void setUp() {
I18N i18n = new DefaultI18N(Arrays.asList(Locale.ENGLISH));
I18NHolder.setStrategy(I18NHolder.class, new GlobalHolderStrategy<I18N>());
I18NHolder.set(i18n);
}

@Test
public void messages_Class1() {
assertEquals("Hello world ExampleLocalizedClass", Bundle.ExampleLocalizedClass_key());
assertEquals("Hello world ExampleLocalizedClass.aField\nAnd a new line", Bundle.ExampleLocalizedClass_aField_key());
assertEquals("Hello world ExampleLocalizedClass.aMethod", Bundle.ExampleLocalizedClass_aMethod_key());
}

@Test
public void messages_Class2() {
assertEquals("Hello world ExampleLocalizedClass2.1", Bundle.ExampleLocalizedClass2_key1());
assertEquals("Hello world ExampleLocalizedClass2.2", Bundle.ExampleLocalizedClass2_key2());
assertEquals("Hello world ExampleLocalizedClass2.aField1", Bundle.ExampleLocalizedClass2_aField_key1());
assertEquals("Hello world ExampleLocalizedClass2.aField2", Bundle.ExampleLocalizedClass2_aField_key2());
assertEquals("Hello world ExampleLocalizedClass2.aMethod1", Bundle.ExampleLocalizedClass2_aMethod_key1());
assertEquals("Hello world ExampleLocalizedClass2.aMethod2", Bundle.ExampleLocalizedClass2_aMethod_key2());
}
}

0 comments on commit f368dc0

Please sign in to comment.