You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2007/09/07 15:25:42 UTC
svn commit: r573573 -
/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java
Author: twgoetz
Date: Fri Sep 7 06:25:42 2007
New Revision: 573573
URL: http://svn.apache.org/viewvc?rev=573573&view=rev
Log:
No Jira: fix formatting.
Modified:
incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java?rev=573573&r1=573572&r2=573573&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java Fri Sep 7 06:25:42 2007
@@ -34,144 +34,144 @@
*/
public class StringArrayTest extends TestCase {
- private CAS cas;
+ private CAS cas;
- private TypeSystem ts;
+ private TypeSystem ts;
- /**
+ /**
* Constructor for ArrayFSTest.
*
* @param arg0
*/
- public StringArrayTest(String arg0) {
- super(arg0);
- }
-
- public void setUp() {
- try {
- this.cas = CASInitializer.initCas(new CASTestSetup());
- this.ts = this.cas.getTypeSystem();
- } catch (Exception e) {
- assertTrue(false);
- }
- }
-
- public void tearDown() {
- this.cas = null;
- this.ts = null;
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(StringArrayTest.class);
- }
-
- public void testSet() {
- StringArrayFS array = this.cas.createStringArrayFS(0);
- assertTrue(array != null);
- assertTrue(array.size() == 0);
- boolean exceptionCaught = false;
- try {
- array.get(0);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- array = this.cas.createStringArrayFS(3);
- try {
- array.set(0, "1");
- array.set(1, "2");
- array.set(2, "3");
- } catch (ArrayIndexOutOfBoundsException e) {
- assertTrue(false);
- }
- exceptionCaught = false;
- try {
- array.set(-1, "1");
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- exceptionCaught = false;
- try {
- array.set(4, "1");
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- assertTrue(array.get(0).equals("1"));
- assertTrue(array.get(1).equals("2"));
- assertTrue(array.get(2).equals("3"));
- exceptionCaught = false;
- try {
- array.get(-1);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- exceptionCaught = false;
- try {
- array.get(4);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- // Check that we can't create arrays smaller than 0.
- exceptionCaught = false;
- try {
- array = this.cas.createStringArrayFS(-1);
- } catch (CASRuntimeException e) {
- exceptionCaught = true;
- assertTrue(e.getMessageKey().equals(CASRuntimeException.ILLEGAL_ARRAY_SIZE));
- }
- assertTrue(exceptionCaught);
- }
-
- public void testToArray() {
- // From CAS array to Java array.
- StringArrayFS array = this.cas.createStringArrayFS(3);
- String[] fsArray = array.toArray();
- for (int i = 0; i < 3; i++) {
- assertTrue(fsArray[i] == null);
- }
- array.set(0, "1");
- array.set(1, "2");
- array.set(2, "3");
- fsArray = array.toArray();
- assertTrue(fsArray.length == 3);
- assertTrue(fsArray[0].equals("1"));
- assertTrue(fsArray[1].equals("2"));
- assertTrue(fsArray[2].equals("3"));
-
- // From Java array to CAS array.
- array = this.cas.createStringArrayFS(3);
- assertTrue(array.get(0) == null);
- assertTrue(array.get(1) == null);
- assertTrue(array.get(2) == null);
- for (int i = 0; i < 3; i++) {
- array.set(i, fsArray[i]);
- }
- assertTrue(array.get(0).equals("1"));
- assertTrue(array.get(1).equals("2"));
- assertTrue(array.get(2).equals("3"));
- array.set(0, null);
- assertTrue(array.get(0) == null);
- }
-
- public void testStringArrayValue() {
- String lemmaListName = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR
- + CASTestSetup.LEMMA_LIST_FEAT;
- final Feature lemmaList = this.ts.getFeatureByFullName(lemmaListName);
- assertTrue(lemmaList != null);
- String[] javaArray = { "1", "2", "3" };
- StringArrayFS casArray = this.cas.createStringArrayFS(3);
- casArray.copyFromArray(javaArray, 0, 0, 3);
- FeatureStructure token = this.cas.createFS(this.ts.getType(CASTestSetup.TOKEN_TYPE));
- assertTrue(token.getFeatureValue(lemmaList) == null);
- token.setFeatureValue(lemmaList, casArray);
- assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == "1");
- String hello = "Hello.";
- casArray.set(0, hello);
- assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == hello);
- }
+ public StringArrayTest(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() {
+ try {
+ this.cas = CASInitializer.initCas(new CASTestSetup());
+ this.ts = this.cas.getTypeSystem();
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ }
+
+ public void tearDown() {
+ this.cas = null;
+ this.ts = null;
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(StringArrayTest.class);
+ }
+
+ public void testSet() {
+ StringArrayFS array = this.cas.createStringArrayFS(0);
+ assertTrue(array != null);
+ assertTrue(array.size() == 0);
+ boolean exceptionCaught = false;
+ try {
+ array.get(0);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ array = this.cas.createStringArrayFS(3);
+ try {
+ array.set(0, "1");
+ array.set(1, "2");
+ array.set(2, "3");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ assertTrue(false);
+ }
+ exceptionCaught = false;
+ try {
+ array.set(-1, "1");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ exceptionCaught = false;
+ try {
+ array.set(4, "1");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ assertTrue(array.get(0).equals("1"));
+ assertTrue(array.get(1).equals("2"));
+ assertTrue(array.get(2).equals("3"));
+ exceptionCaught = false;
+ try {
+ array.get(-1);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ exceptionCaught = false;
+ try {
+ array.get(4);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ // Check that we can't create arrays smaller than 0.
+ exceptionCaught = false;
+ try {
+ array = this.cas.createStringArrayFS(-1);
+ } catch (CASRuntimeException e) {
+ exceptionCaught = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.ILLEGAL_ARRAY_SIZE));
+ }
+ assertTrue(exceptionCaught);
+ }
+
+ public void testToArray() {
+ // From CAS array to Java array.
+ StringArrayFS array = this.cas.createStringArrayFS(3);
+ String[] fsArray = array.toArray();
+ for (int i = 0; i < 3; i++) {
+ assertTrue(fsArray[i] == null);
+ }
+ array.set(0, "1");
+ array.set(1, "2");
+ array.set(2, "3");
+ fsArray = array.toArray();
+ assertTrue(fsArray.length == 3);
+ assertTrue(fsArray[0].equals("1"));
+ assertTrue(fsArray[1].equals("2"));
+ assertTrue(fsArray[2].equals("3"));
+
+ // From Java array to CAS array.
+ array = this.cas.createStringArrayFS(3);
+ assertTrue(array.get(0) == null);
+ assertTrue(array.get(1) == null);
+ assertTrue(array.get(2) == null);
+ for (int i = 0; i < 3; i++) {
+ array.set(i, fsArray[i]);
+ }
+ assertTrue(array.get(0).equals("1"));
+ assertTrue(array.get(1).equals("2"));
+ assertTrue(array.get(2).equals("3"));
+ array.set(0, null);
+ assertTrue(array.get(0) == null);
+ }
+
+ public void testStringArrayValue() {
+ String lemmaListName = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR
+ + CASTestSetup.LEMMA_LIST_FEAT;
+ final Feature lemmaList = this.ts.getFeatureByFullName(lemmaListName);
+ assertTrue(lemmaList != null);
+ String[] javaArray = { "1", "2", "3" };
+ StringArrayFS casArray = this.cas.createStringArrayFS(3);
+ casArray.copyFromArray(javaArray, 0, 0, 3);
+ FeatureStructure token = this.cas.createFS(this.ts.getType(CASTestSetup.TOKEN_TYPE));
+ assertTrue(token.getFeatureValue(lemmaList) == null);
+ token.setFeatureValue(lemmaList, casArray);
+ assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == "1");
+ String hello = "Hello.";
+ casArray.set(0, hello);
+ assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == hello);
+ }
}