You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2022/03/09 14:03:12 UTC

[uima-uimaj] branch bugfix/UIMA-6421-Can-inject-String-value-into-StringArray-slot updated: [UIMA-6421] Can inject String value into StringArray slot

This is an automated email from the ASF dual-hosted git repository.

rec pushed a commit to branch bugfix/UIMA-6421-Can-inject-String-value-into-StringArray-slot
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git


The following commit(s) were added to refs/heads/bugfix/UIMA-6421-Can-inject-String-value-into-StringArray-slot by this push:
     new b31a5f7  [UIMA-6421] Can inject String value into StringArray slot
b31a5f7 is described below

commit b31a5f7f7077cadc7d57e6dcac02b415590adc5f
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Wed Mar 9 15:03:05 2022 +0100

    [UIMA-6421] Can inject String value into StringArray slot
    
    - Add range check to setStringValue
    - Modernize unit test
    - Fix formatting rules
---
 .../uima/cas/impl/FeatureStructureImplC.java       |  46 +++++---
 .../org/apache/uima/cas/test/CASTestSetup.java     | 107 ++++++++++--------
 .../apache/uima/cas/test/FeatureStructureTest.java | 120 ++++++++++++++-------
 .../org/apache/uima/cas/test/StringArrayTest.java  | 115 ++++++++------------
 4 files changed, 218 insertions(+), 170 deletions(-)

diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java
index 033615e..904b884 100644
--- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java
+++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java
@@ -585,9 +585,7 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
 
   @Override
   public void setStringValue(Feature feat, String v) {
-    // if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) featureValidation(feat); // done by _setRefValueCJ
-    // if (IS_ENABLE_RUNTIME_FEATURE_VALUE_VALIDATION) featureValueValidation(feat, v); // verifies
-    // feat can take a string
+    checkFeatRange(feat, "String");
     subStringRangeCheck(feat, v);
     _setRefValueCJ((FeatureImpl) feat, v);
   }
@@ -618,10 +616,12 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
   @Override
   public void setFeatureValue(Feature feat, FeatureStructure v) {
     FeatureImpl fi = (FeatureImpl) feat;
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(feat);
-    if (IS_ENABLE_RUNTIME_FEATURE_VALUE_VALIDATION)
+    }
+    if (IS_ENABLE_RUNTIME_FEATURE_VALUE_VALIDATION) {
       featureValueValidation(feat, v);
+    }
     // no need to check for index corruption because fs refs can't be index keys
     _setRefValueCommon(fi, _maybeGetBaseForPearFs((TOP) v));
     _casView.maybeLogUpdate(this, fi);
@@ -710,8 +710,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
 
   @Override
   public void setFeatureValueFromString(Feature feat, String s) throws CASRuntimeException {
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(feat);
+    }
     CASImpl.setFeatureValueFromString(this, (FeatureImpl) feat, s);
   }
 
@@ -731,8 +732,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
               "boolean, byte, short, int, or float", fi.getRange().getName());
 
     }
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(fi);
+    }
     _casView.setWithCheckAndJournal((TOP) this, fi.getCode(), () -> _setIntValueCommon(fi, v));
 
   }
@@ -751,8 +753,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
       throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, fi.getName(),
               "long or double", fi.getRange().getName());
     }
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(fi);
+    }
     _casView.setLongValue(this, fi, v);
   }
 
@@ -787,8 +790,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
       throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, fi.getName(), "int",
               fi.getRange().getName());
     }
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(fi);
+    }
     _casView.setWithCheckAndJournal((TOP) this, fi.getCode(), () -> _setRefValueCommon(fi, v));
 
   }
@@ -818,8 +822,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
 //@formatter:on
   @Override
   public boolean getBooleanValue(Feature feat) {
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(feat);
+    }
     checkFeatRange(feat, "Boolean");
     return _getBooleanValueNc((FeatureImpl) feat);
   }
@@ -863,8 +868,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
 
   @Override
   public int getIntValue(Feature feat) {
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(feat);
+    }
     checkFeatRange(feat, "Integer");
     return _getIntValueCommon((FeatureImpl) feat);
   }
@@ -879,8 +885,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
 
   @Override
   public long getLongValue(Feature feat) {
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(feat);
+    }
     checkFeatRange(feat, "Long");
     return _getLongValueNc((FeatureImpl) feat);
   }
@@ -901,8 +908,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
 
   @Override
   public float getFloatValue(Feature feat) {
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(feat);
+    }
     checkFeatRange(feat, "Float");
     return _getFloatValueNc(((FeatureImpl) feat).getAdjustedOffset());
   }
@@ -917,8 +925,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
 
   @Override
   public double getDoubleValue(Feature feat) {
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(feat);
+    }
     checkFeatRange(feat, "Double");
     return _getDoubleValueNc((FeatureImpl) feat);
   }
@@ -933,8 +942,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
 
   @Override
   public String getStringValue(Feature feat) {
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(feat);
+    }
     // checkFeatRange(feat, "String");
     return _getStringValueNc((FeatureImpl) feat);
   }
@@ -949,8 +959,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
 
   @Override
   public TOP getFeatureValue(Feature feat) {
-    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION)
+    if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) {
       _Check_feature_defined_for_this_type(feat);
+    }
     _check_feature_range_is_FeatureStructure(feat, this);
     return _getFeatureValueNc((FeatureImpl) feat);
   }
@@ -1049,8 +1060,9 @@ public class FeatureStructureImplC implements FeatureStructureImpl {
     if (obj instanceof FeatureStructureImplC) {
       FeatureStructureImplC c2 = (FeatureStructureImplC) obj;
 
-      if (c2._id != this._id)
+      if (c2._id != this._id) {
         return false;
+      }
 
       return (_casView == null && c2._casView == null) || (_casView != null && c2._casView != null
               && (_casView == c2._casView || _casView.getBaseCAS() == c2._casView.getBaseCAS()));
diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTestSetup.java b/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTestSetup.java
index bfea2a8..8d0b7ec 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTestSetup.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTestSetup.java
@@ -19,9 +19,25 @@
 
 package org.apache.uima.cas.test;
 
+import static org.apache.uima.cas.CAS.FEATURE_BASE_NAME_BEGIN;
+import static org.apache.uima.cas.CAS.FEATURE_BASE_NAME_END;
+import static org.apache.uima.cas.CAS.TYPE_NAME_ANNOTATION;
+import static org.apache.uima.cas.CAS.TYPE_NAME_DOUBLE;
+import static org.apache.uima.cas.CAS.TYPE_NAME_FLOAT;
+import static org.apache.uima.cas.CAS.TYPE_NAME_INTEGER_ARRAY;
+import static org.apache.uima.cas.CAS.TYPE_NAME_LONG;
+import static org.apache.uima.cas.CAS.TYPE_NAME_STRING;
+import static org.apache.uima.cas.CAS.TYPE_NAME_STRING_ARRAY;
+import static org.apache.uima.cas.FSIndex.BAG_INDEX;
+import static org.apache.uima.cas.FSIndex.SET_INDEX;
+import static org.apache.uima.cas.FSIndex.SORTED_INDEX;
+import static org.apache.uima.cas.TypeSystem.FEATURE_SEPARATOR;
+import static org.apache.uima.cas.admin.FSIndexComparator.REVERSE_STANDARD_COMPARE;
+import static org.apache.uima.cas.admin.FSIndexComparator.STANDARD_COMPARE;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
-import org.apache.uima.cas.FSIndex;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.TypeSystem;
 import org.apache.uima.cas.admin.CASAdminException;
@@ -66,12 +82,11 @@ public class CASTestSetup implements AnnotatorInitializer {
 
   public static final String LEMMA_FEAT = "lemma";
 
-  public static final String LEMMA_FEAT_Q = TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR + LEMMA_FEAT;
+  public static final String LEMMA_FEAT_Q = TOKEN_TYPE + FEATURE_SEPARATOR + LEMMA_FEAT;
 
   public static final String SENT_LEN_FEAT = "sentenceLength";
 
-  public static final String SENT_LEN_FEAT_Q = SENT_TYPE + TypeSystem.FEATURE_SEPARATOR
-          + SENT_LEN_FEAT;
+  public static final String SENT_LEN_FEAT_Q = SENT_TYPE + FEATURE_SEPARATOR + SENT_LEN_FEAT;
 
   public static final String TOKEN_FLOAT_FEAT = "tokenFloatFeat";
   public static final String TOKEN_DOUBLE_FEAT = "tokenDoubleFeat";
@@ -86,8 +101,7 @@ public class CASTestSetup implements AnnotatorInitializer {
 
   public static final String LEMMA_LIST_FEAT = "lemmaList";
 
-  public static final String LEMMA_LIST_FEAT_Q = TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR
-          + LEMMA_LIST_FEAT;
+  public static final String LEMMA_LIST_FEAT_Q = TOKEN_TYPE + FEATURE_SEPARATOR + LEMMA_LIST_FEAT;
 
   public static final String LANG_PAIR = "org.apache.lang.LanguagePair";
 
@@ -148,70 +162,69 @@ public class CASTestSetup implements AnnotatorInitializer {
   @Override
   public void initTypeSystem(TypeSystemMgr tsm) {
     // Add new types and features.
-    Type stringType = tsm.getType(CAS.TYPE_NAME_STRING);
+    Type stringType = tsm.getType(TYPE_NAME_STRING);
 
     Type topType = tsm.getTopType();
-    Type annotType = tsm.getType(CAS.TYPE_NAME_ANNOTATION);
+    Type annotType = tsm.getType(TYPE_NAME_ANNOTATION);
     // assert(annotType != null);
-    Type sentenceType = tsm.addType(SENT_TYPE, annotType);
-    tsm.addType(PHRASE_TYPE, sentenceType);
-    Type tokenType = tsm.addType(TOKEN_TYPE, annotType);
+
+    Type sentType = tsm.addType(SENT_TYPE, annotType);
+    tsm.addFeature(SENT_LEN_FEAT, sentType, tsm.getType(CAS.TYPE_NAME_INTEGER));
+
+    tsm.addType(PHRASE_TYPE, sentType);
+
     Type tokenTypeType = tsm.addType(TOKEN_TYPE_TYPE, topType);
+
+    Type tokenType = tsm.addType(TOKEN_TYPE, annotType);
+    tsm.addFeature(TOKEN_TYPE_FEAT, tokenType, tokenTypeType);
+    tsm.addFeature(TOKEN_FLOAT_FEAT, tokenType, tsm.getType(TYPE_NAME_FLOAT));
+    tsm.addFeature(TOKEN_DOUBLE_FEAT, tokenType, tsm.getType(TYPE_NAME_DOUBLE));
+    tsm.addFeature(TOKEN_LONG_FEAT, tokenType, tsm.getType(TYPE_NAME_LONG));
+    tsm.addFeature(LEMMA_FEAT, tokenType, stringType);
+    tsm.addFeature(LEMMA_LIST_FEAT, tokenType, tsm.getType(TYPE_NAME_STRING_ARRAY));
+
     tsm.addType(WORD_TYPE, tokenTypeType);
     Type arrayFsWithSubtypeType = tsm.addType(ARRAYFSWITHSUBTYPE_TYPE, topType);
-    Type arrayOfAnnot = tsm.getArrayType(annotType);
-    tsm.addFeature(ARRAYFSWITHSUBTYPE_TYPE_FEAT, arrayFsWithSubtypeType, arrayOfAnnot);
+    tsm.addFeature(ARRAYFSWITHSUBTYPE_TYPE_FEAT, arrayFsWithSubtypeType,
+            tsm.getArrayType(annotType));
+
     tsm.addType(SEP_TYPE, tokenTypeType);
+
     tsm.addType(EOS_TYPE, tokenTypeType);
-    tsm.addFeature(TOKEN_TYPE_FEAT, tokenType, tokenTypeType);
-    tsm.addFeature(TOKEN_FLOAT_FEAT, tokenType, tsm.getType(CAS.TYPE_NAME_FLOAT));
-    tsm.addFeature(TOKEN_DOUBLE_FEAT, tokenType, tsm.getType(CAS.TYPE_NAME_DOUBLE));
-    tsm.addFeature(TOKEN_LONG_FEAT, tokenType, tsm.getType(CAS.TYPE_NAME_LONG));
     // Add a type that inherits from IntArray.
     // tsm.addType(INT_ARRAY_SUB, tsm.getType(CAS.TYPE_NAME_INTEGER_ARRAY));
     // tsm.addFeature(
     // INT_SUB_NAME,
     // tsm.getType(INT_ARRAY_SUB),
     // tsm.getType(CAS.TYPE_NAME_STRING));
-    tsm.addFeature(LEMMA_FEAT, tokenType, stringType);
-    tsm.addFeature(SENT_LEN_FEAT, tsm.getType(SENT_TYPE), tsm.getType(CAS.TYPE_NAME_INTEGER));
-    tsm.addFeature(LEMMA_LIST_FEAT, tsm.getType(TOKEN_TYPE),
-            tsm.getType(CAS.TYPE_NAME_STRING_ARRAY));
     Type group1 = tsm.addStringSubtype(GROUP_1, GROUP_1_LANGUAGES);
     Type group2 = tsm.addStringSubtype(GROUP_2, GROUP_2_LANGUAGES);
     Type langPair = tsm.addType(LANG_PAIR, topType);
     tsm.addFeature(LANG1, langPair, group1);
     tsm.addFeature(LANG2, langPair, group2);
     tsm.addFeature(DESCR_FEAT, langPair, stringType);
-    boolean exc = false;
-    try {
-      tsm.addType("some.new.Name", group1);
-    } catch (CASAdminException e) {
-      TestCase.assertTrue(e.getMessageKey() == CASAdminException.TYPE_IS_INH_FINAL);
-      exc = true;
-    }
-    TestCase.assertTrue(exc);
-    exc = false;
-    try {
-      tsm.addFeature("some.new.Name", group1, stringType);
-    } catch (CASAdminException e) {
-      TestCase.assertTrue(e.getMessageKey() == CASAdminException.TYPE_IS_FEATURE_FINAL);
-      exc = true;
-    }
-    TestCase.assertTrue(exc);
+
+    assertThatExceptionOfType(CASAdminException.class) //
+            .isThrownBy(() -> tsm.addType("some.new.Name", group1)) //
+            .extracting(CASAdminException::getMessageKey) //
+            .isEqualTo(CASAdminException.TYPE_IS_INH_FINAL);
+
+    assertThatExceptionOfType(CASAdminException.class) //
+            .isThrownBy(() -> tsm.addFeature("some.new.Name", group1, stringType)) //
+            .extracting(CASAdminException::getMessageKey) //
+            .isEqualTo(CASAdminException.TYPE_IS_FEATURE_FINAL);
+
     // add IntegerArray[] type before commit for testArrayTypes in TypeSystemTest
-    Type intArrayType = tsm.getType(CAS.TYPE_NAME_INTEGER_ARRAY);
+    Type intArrayType = tsm.getType(TYPE_NAME_INTEGER_ARRAY);
     Type arrayOfIntArray = tsm.getArrayType(intArrayType);
   }
 
   private FSIndexComparator makeComp(FSIndexRepositoryMgr irm, TypeSystem ts) {
     FSIndexComparator comp = irm.createComparator();
-    Type annotation = ts.getType(CAS.TYPE_NAME_ANNOTATION);
+    Type annotation = ts.getType(TYPE_NAME_ANNOTATION);
     comp.setType(annotation);
-    comp.addKey(annotation.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_BEGIN),
-            FSIndexComparator.STANDARD_COMPARE);
-    comp.addKey(annotation.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_END),
-            FSIndexComparator.REVERSE_STANDARD_COMPARE);
+    comp.addKey(annotation.getFeatureByBaseName(FEATURE_BASE_NAME_BEGIN), STANDARD_COMPARE);
+    comp.addKey(annotation.getFeatureByBaseName(FEATURE_BASE_NAME_END), REVERSE_STANDARD_COMPARE);
     return comp;
   }
 
@@ -226,9 +239,9 @@ public class CASTestSetup implements AnnotatorInitializer {
     } catch (CASException e) {
       TestCase.assertTrue(false);
     }
-    irm.createIndex(comp, ANNOT_BAG_INDEX, FSIndex.BAG_INDEX);
-    irm.createIndex(comp, ANNOT_SET_INDEX, FSIndex.SET_INDEX);
-    irm.createIndex(comp, ANNOT_SORT_INDEX, FSIndex.SORTED_INDEX);
-    irm.createIndex(compNoTypeOrder, ANNOT_SET_INDEX_NO_TYPEORDER, FSIndex.SET_INDEX);
+    irm.createIndex(comp, ANNOT_BAG_INDEX, BAG_INDEX);
+    irm.createIndex(comp, ANNOT_SET_INDEX, SET_INDEX);
+    irm.createIndex(comp, ANNOT_SORT_INDEX, SORTED_INDEX);
+    irm.createIndex(compNoTypeOrder, ANNOT_SET_INDEX_NO_TYPEORDER, SET_INDEX);
   }
 }
diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/test/FeatureStructureTest.java b/uimaj-core/src/test/java/org/apache/uima/cas/test/FeatureStructureTest.java
index 14be9a7..6d1c5b1 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/test/FeatureStructureTest.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/test/FeatureStructureTest.java
@@ -18,11 +18,35 @@
  */
 package org.apache.uima.cas.test;
 
+import static org.apache.uima.cas.CAS.FEATURE_BASE_NAME_HEAD;
+import static org.apache.uima.cas.CAS.FEATURE_BASE_NAME_TAIL;
+import static org.apache.uima.cas.CAS.FEATURE_FULL_NAME_BEGIN;
+import static org.apache.uima.cas.CAS.TYPE_NAME_INTEGER;
+import static org.apache.uima.cas.CAS.TYPE_NAME_NON_EMPTY_FS_LIST;
+import static org.apache.uima.cas.CAS.TYPE_NAME_STRING;
+import static org.apache.uima.cas.CAS.TYPE_NAME_TOP;
+import static org.apache.uima.cas.test.CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE;
+import static org.apache.uima.cas.test.CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE_FEAT_Q;
+import static org.apache.uima.cas.test.CASTestSetup.DESCR_FEAT;
+import static org.apache.uima.cas.test.CASTestSetup.GROUP_1;
 import static org.apache.uima.cas.test.CASTestSetup.GROUP_1_LANGUAGES;
+import static org.apache.uima.cas.test.CASTestSetup.GROUP_2;
 import static org.apache.uima.cas.test.CASTestSetup.GROUP_2_LANGUAGES;
+import static org.apache.uima.cas.test.CASTestSetup.LANG1;
+import static org.apache.uima.cas.test.CASTestSetup.LANG2;
+import static org.apache.uima.cas.test.CASTestSetup.LANG_PAIR;
+import static org.apache.uima.cas.test.CASTestSetup.LEMMA_FEAT_Q;
+import static org.apache.uima.cas.test.CASTestSetup.LEMMA_LIST_FEAT_Q;
+import static org.apache.uima.cas.test.CASTestSetup.SENT_LEN_FEAT_Q;
+import static org.apache.uima.cas.test.CASTestSetup.TOKEN_DOUBLE_FEAT_Q;
+import static org.apache.uima.cas.test.CASTestSetup.TOKEN_FLOAT_FEAT_Q;
+import static org.apache.uima.cas.test.CASTestSetup.TOKEN_LONG_FEAT_Q;
 import static org.apache.uima.cas.test.CASTestSetup.TOKEN_TYPE;
 import static org.apache.uima.cas.test.CASTestSetup.TOKEN_TYPE_FEAT;
+import static org.apache.uima.cas.test.CASTestSetup.TOKEN_TYPE_FEAT_Q;
+import static org.apache.uima.cas.test.CASTestSetup.TOKEN_TYPE_TYPE;
 import static org.apache.uima.cas.test.CASTestSetup.WORD_TYPE;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 import static org.assertj.core.api.Assertions.assertThatNoException;
 import static org.junit.Assert.assertEquals;
@@ -76,6 +100,7 @@ public class FeatureStructureTest {
   private Feature descr;
   private Feature tokenTypeFeat;
   private Feature lemmaFeat;
+  private Feature lemmaListFeat;
   private Feature sentLenFeat;
   private Feature tokenFloatFeat;
   private Feature tokenLongFeat;
@@ -92,76 +117,78 @@ public class FeatureStructureTest {
     ts = (TypeSystemImpl) cas.getTypeSystem();
     assertTrue(ts != null);
 
-    topType = ts.getType(CAS.TYPE_NAME_TOP);
+    topType = ts.getType(TYPE_NAME_TOP);
     assertTrue(topType != null);
 
-    stringType = ts.getType(CAS.TYPE_NAME_STRING);
+    stringType = ts.getType(TYPE_NAME_STRING);
     assertTrue(stringType != null);
 
-    tokenType = ts.getType(CASTestSetup.TOKEN_TYPE);
+    tokenType = ts.getType(TOKEN_TYPE);
     assertTrue(stringType != null);
 
-    intType = ts.getType(CAS.TYPE_NAME_INTEGER);
+    intType = ts.getType(TYPE_NAME_INTEGER);
     assertTrue(intType != null);
 
-    tokenTypeType = ts.getType(CASTestSetup.TOKEN_TYPE_TYPE);
+    tokenTypeType = ts.getType(TOKEN_TYPE_TYPE);
     assertTrue(tokenTypeType != null);
 
-    wordType = ts.getType(CASTestSetup.WORD_TYPE);
+    wordType = ts.getType(WORD_TYPE);
     assertTrue(wordType != null);
 
-    arrayFsWithSubtypeType = ts.getType(CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE);
+    arrayFsWithSubtypeType = ts.getType(ARRAYFSWITHSUBTYPE_TYPE);
     assertTrue(arrayFsWithSubtypeType != null);
 
-    arrayFsWithSubtypeTypeFeat = ts
-            .getFeatureByFullName(CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE_FEAT_Q);
+    arrayFsWithSubtypeTypeFeat = ts.getFeatureByFullName(ARRAYFSWITHSUBTYPE_TYPE_FEAT_Q);
 
-    group1Type = ts.getType(CASTestSetup.GROUP_1);
+    group1Type = ts.getType(GROUP_1);
     assertTrue(group1Type != null);
 
-    group2Type = ts.getType(CASTestSetup.GROUP_2);
+    group2Type = ts.getType(GROUP_2);
     assertTrue(group2Type != null);
 
-    tokenTypeFeat = ts.getFeatureByFullName(CASTestSetup.TOKEN_TYPE_FEAT_Q);
+    tokenTypeFeat = ts.getFeatureByFullName(TOKEN_TYPE_FEAT_Q);
     assertTrue(tokenTypeFeat != null);
 
-    lemmaFeat = ts.getFeatureByFullName(CASTestSetup.LEMMA_FEAT_Q);
+    lemmaFeat = ts.getFeatureByFullName(LEMMA_FEAT_Q);
     assertTrue(lemmaFeat != null);
 
-    sentLenFeat = ts.getFeatureByFullName(CASTestSetup.SENT_LEN_FEAT_Q);
+    lemmaListFeat = ts.getFeatureByFullName(LEMMA_LIST_FEAT_Q);
+    assertTrue(lemmaListFeat != null);
+
+    sentLenFeat = ts.getFeatureByFullName(SENT_LEN_FEAT_Q);
     assertTrue(sentLenFeat != null);
 
-    tokenFloatFeat = ts.getFeatureByFullName(CASTestSetup.TOKEN_FLOAT_FEAT_Q);
+    tokenFloatFeat = ts.getFeatureByFullName(TOKEN_FLOAT_FEAT_Q);
     assertTrue(tokenFloatFeat != null);
 
-    tokenDoubleFeat = ts.getFeatureByFullName(CASTestSetup.TOKEN_DOUBLE_FEAT_Q);
+    tokenDoubleFeat = ts.getFeatureByFullName(TOKEN_DOUBLE_FEAT_Q);
     assertTrue(tokenDoubleFeat != null);
 
-    tokenLongFeat = ts.getFeatureByFullName(CASTestSetup.TOKEN_LONG_FEAT_Q);
+    tokenLongFeat = ts.getFeatureByFullName(TOKEN_LONG_FEAT_Q);
     assertTrue(tokenLongFeat != null);
 
-    startFeature = ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_BEGIN);
+    startFeature = ts.getFeatureByFullName(FEATURE_FULL_NAME_BEGIN);
     assertTrue(startFeature != null);
 
-    langPairType = ts.getType(CASTestSetup.LANG_PAIR);
+    langPairType = ts.getType(LANG_PAIR);
     assertTrue(langPairType != null);
 
-    lang1 = langPairType.getFeatureByBaseName(CASTestSetup.LANG1);
+    lang1 = langPairType.getFeatureByBaseName(LANG1);
     assertTrue(lang1 != null);
 
-    lang2 = langPairType.getFeatureByBaseName(CASTestSetup.LANG2);
+    lang2 = langPairType.getFeatureByBaseName(LANG2);
     assertTrue(lang2 != null);
 
-    descr = langPairType.getFeatureByBaseName(CASTestSetup.DESCR_FEAT);
+    descr = langPairType.getFeatureByBaseName(DESCR_FEAT);
     assertTrue(descr != null);
 
-    neListType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
+    neListType = ts.getType(TYPE_NAME_NON_EMPTY_FS_LIST);
     assertTrue(neListType != null);
 
-    tlFeature = neListType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);
+    tlFeature = neListType.getFeatureByBaseName(FEATURE_BASE_NAME_TAIL);
     assertTrue(tlFeature != null);
 
-    hdFeature = neListType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
+    hdFeature = neListType.getFeatureByBaseName(FEATURE_BASE_NAME_HEAD);
     assertTrue(hdFeature != null);
   }
 
@@ -207,8 +234,10 @@ public class FeatureStructureTest {
   public void testGetType() {
     Type tokenType1 = ts.getType(TOKEN_TYPE);
     Type wordType1 = ts.getType(WORD_TYPE);
+
     FeatureStructure word = cas.createFS(wordType1);
     FeatureStructure token = cas.createFS(tokenType1);
+
     assertTrue(word.getType().equals(wordType1));
     assertTrue(token.getType().equals(tokenType1));
   }
@@ -272,7 +301,7 @@ public class FeatureStructureTest {
     assertEquals(fs.getBegin(), 3);
     assertEquals(fs.getEnd(), 5);
     assertEquals(sofa, fs.getSofa());
-    Assertions.assertThat(token.getFloatValue(tokenFloatFeat)).isEqualTo(1.1f);
+    assertThat(token.getFloatValue(tokenFloatFeat)).isEqualTo(1.1f);
     assertEquals(ttfv, token.getFeatureValue(tokenTypeFeat));
     assertTrue(fsa.get(0) == token);
     assertTrue(fsl.getHead() == token);
@@ -296,7 +325,7 @@ public class FeatureStructureTest {
     assertEquals(token.getBegin(), 0);
     assertEquals(token.getEnd(), 0);
     assertEquals(sofa, token.getSofa());
-    Assertions.assertThat(token.getFloatValue(tokenFloatFeat)).isEqualTo(0.0f);
+    assertThat(token.getFloatValue(tokenFloatFeat)).isEqualTo(0.0f);
     assertEquals(null, token.getFeatureValue(tokenTypeFeat));
     assertTrue(fsa.get(0) == token);
     assertTrue(fsl.getHead() == token);
@@ -305,12 +334,18 @@ public class FeatureStructureTest {
   @Test
   public void testSetArrayValuedFeature() {
     FeatureStructure testFS = cas.createFS(arrayFsWithSubtypeType);
-    assertTrue(testFS.getFeatureValue(arrayFsWithSubtypeTypeFeat) == null);
+
+    assertThat(testFS.getFeatureValue(arrayFsWithSubtypeTypeFeat)) //
+            .as("Initial value is null") //
+            .isNull();
+
     ArrayFS arrayFS = cas.createArrayFS(1);
     testFS.setFeatureValue(arrayFsWithSubtypeTypeFeat, arrayFS);
-    assertTrue(true);
+    assertThat(testFS.getFeatureValue(arrayFsWithSubtypeTypeFeat)) //
+            .isSameAs(arrayFS);
 
     assertThatExceptionOfType(CASRuntimeException.class) //
+            .as("Array-valued feature cannot be set with non-array value") //
             .isThrownBy(() -> testFS.setFeatureValue(arrayFsWithSubtypeTypeFeat, testFS));
   }
 
@@ -349,19 +384,32 @@ public class FeatureStructureTest {
             .extracting(CASRuntimeException::getMessageKey) //
             .isEqualTo(CASRuntimeException.INAPPROP_RANGE_NOT_FS);
 
-    assertTrue(token.getStringValue(lemmaFeat) == null);
-    String testString = "test";
-    token.setStringValue(lemmaFeat, testString);
-    assertTrue(token.getStringValue(lemmaFeat).equals(testString));
-    testString = "";
-    token.setStringValue(lemmaFeat, testString);
-    assertTrue(token.getStringValue(lemmaFeat).equals(testString));
+    assertThat(token.getStringValue(lemmaFeat)) //
+            .as("String feature value is initially null") //
+            .isNull();
+
+    token.setStringValue(lemmaFeat, "test");
+    assertThat(token.getStringValue(lemmaFeat)) //
+            .isEqualTo("test");
+
+    token.setStringValue(lemmaFeat, "");
+    assertThat(token.getStringValue(lemmaFeat)) //
+            .isEqualTo("");
+
+    assertThatExceptionOfType(CASRuntimeException.class) //
+            .as("Cannot set boolean value on string array feature") //
+            .isThrownBy(() -> token.setBooleanValue(lemmaListFeat, true));
+
+    assertThatExceptionOfType(CASRuntimeException.class) //
+            .as("Cannot set string value on string array feature") //
+            .isThrownBy(() -> token.setStringValue(lemmaListFeat, "test"));
 
     // test low level
     token.setFeatureValue(tokenTypeFeat, word);
     int fsRef = token._id();
     int fc = ((FeatureImpl) tokenTypeFeat).getCode();
     assertEquals(llcas.ll_getIntValue(fsRef, fc), word._id());
+
     int word2_id = llcas.ll_createFS(((TypeImpl) wordType).getCode());
     TOP word2 = llcas.ll_getFSForRef(word2_id);
     // TOP word2 = cas.createFS(wordType);
diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java b/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java
index fdea0ba..0561c89 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java
@@ -19,6 +19,10 @@
 
 package org.apache.uima.cas.test;
 
+import static org.apache.uima.cas.TypeSystem.FEATURE_SEPARATOR;
+import static org.apache.uima.cas.test.CASTestSetup.LEMMA_LIST_FEAT;
+import static org.apache.uima.cas.test.CASTestSetup.TOKEN_TYPE;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.uima.cas.CAS;
@@ -44,13 +48,9 @@ public class StringArrayTest {
   private TypeSystem ts;
 
   @BeforeEach
-  public void setUp() {
-    try {
-      this.cas = CASInitializer.initCas(new CASTestSetup(), null);
-      this.ts = this.cas.getTypeSystem();
-    } catch (Exception e) {
-      assertTrue(false);
-    }
+  public void setUp() throws Exception {
+    this.cas = CASInitializer.initCas(new CASTestSetup(), null);
+    this.ts = this.cas.getTypeSystem();
   }
 
   @AfterEach
@@ -64,66 +64,44 @@ public class StringArrayTest {
     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);
-    }
-    String[] stringArray = array.toStringArray();
-    assertTrue(array.size() == stringArray.length);
+    assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class) //
+            .isThrownBy(() -> array.get(0));
+
+    StringArrayFS array2 = this.cas.createStringArrayFS(3);
+    array2.set(0, "1");
+    array2.set(1, "2");
+    array2.set(2, "3");
+
+    String[] stringArray = array2.toStringArray();
+    assertTrue(array2.size() == stringArray.length);
     for (int i = 0; i < stringArray.length; i++) {
-      assertTrue(stringArray[i].equals(array.get(i)));
-    }
-    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(stringArray[i].equals(array2.get(i)));
     }
-    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);
+
+    assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class) //
+            .as("Cannot set value at index < 0") //
+            .isThrownBy(() -> array2.set(-1, "1"));
+    assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class) //
+            .as("Cannot set value at index beyond end of the array") //
+            .isThrownBy(() -> array2.set(4, "1"));
+
+    assertTrue(array2.get(0).equals("1"));
+    assertTrue(array2.get(1).equals("2"));
+    assertTrue(array2.get(2).equals("3"));
+
+    assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class) //
+            .as("Cannot get value at index < 0") //
+            .isThrownBy(() -> array2.get(-1));
+
+    assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class) //
+            .as("Cannot get value at index beyond end of the array") //
+            .isThrownBy(() -> array2.get(4));
+
+    assertThatExceptionOfType(CASRuntimeException.class) //
+            .as("We can't create arrays smaller than 0")
+            .isThrownBy(() -> this.cas.createStringArrayFS(-1)) //
+            .extracting(CASRuntimeException::getMessageKey) //
+            .isEqualTo(CASRuntimeException.ILLEGAL_ARRAY_SIZE);
   }
 
   @Test
@@ -160,8 +138,7 @@ public class StringArrayTest {
 
   @Test
   public void testStringArrayValue() {
-    String lemmaListName = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR
-            + CASTestSetup.LEMMA_LIST_FEAT;
+    String lemmaListName = TOKEN_TYPE + FEATURE_SEPARATOR + LEMMA_LIST_FEAT;
     final Feature lemmaList = this.ts.getFeatureByFullName(lemmaListName);
     assertTrue(lemmaList != null);
     String[] javaArray = { "1", "2", "3" };
@@ -178,8 +155,7 @@ public class StringArrayTest {
 
   @Test
   public void testStringArrayNullValue() throws Exception {
-    String lemmaListName = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR
-            + CASTestSetup.LEMMA_LIST_FEAT;
+    String lemmaListName = TOKEN_TYPE + FEATURE_SEPARATOR + LEMMA_LIST_FEAT;
     final Feature lemmaList = this.ts.getFeatureByFullName(lemmaListName);
     assertTrue(lemmaList != null);
     StringArrayFS casArray = this.cas.createStringArrayFS(3);
@@ -196,5 +172,4 @@ public class StringArrayTest {
     LowLevelCAS llc = casArray.getCAS().getLowLevelCAS();
     assertTrue(llc.ll_getStringArrayValue(llc.ll_getFSRef(casArray), 1) == null);
   }
-
 }