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

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git

commit 59ee2fe26fdd4b9d8b4657863bde2acc5c190321
Author: Andy Seaborne <[email protected]>
AuthorDate: Mon Aug 12 13:24:49 2024 +0100

    GH-2638: Silence warnings (works with maven surefire)
---
 .../jena/query/TestQueryCloningEssentials.java     |  42 ++-
 .../text/TestTextMultipleProplistNotWorking.java   | 338 ++++++++++-----------
 2 files changed, 181 insertions(+), 199 deletions(-)

diff --git 
a/jena-arq/src/test/java/org/apache/jena/query/TestQueryCloningEssentials.java 
b/jena-arq/src/test/java/org/apache/jena/query/TestQueryCloningEssentials.java
index 4c5345f2c3..cfa254d38b 100644
--- 
a/jena-arq/src/test/java/org/apache/jena/query/TestQueryCloningEssentials.java
+++ 
b/jena-arq/src/test/java/org/apache/jena/query/TestQueryCloningEssentials.java
@@ -21,14 +21,12 @@ import java.io.IOException;
 import java.nio.file.*;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.stream.Collectors;
 
 import org.apache.jena.sparql.expr.E_Function;
 import org.apache.jena.sparql.expr.NodeValue;
-import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -56,10 +54,10 @@ public class TestQueryCloningEssentials {
         Assert.assertEquals(query, actual);
         Assert.assertEquals(expected, actual);
 
-        // Check that the cloned query is OK. 
+        // Check that the cloned query is OK.
         Query again = slowClone(actual);
         Assert.assertEquals(query, again);
-        
+
         return actual;
     }
 
@@ -71,33 +69,28 @@ public class TestQueryCloningEssentials {
         this.query = query;
     }
 
-    private static boolean bVerboseWarnings;
-    private static boolean bWarnOnUnknownFunction;
-
-    //@BeforeClass -- call earlier
-    public static void beforeClass() {
-        bVerboseWarnings = NodeValue.VerboseWarnings;
-        bWarnOnUnknownFunction = E_Function.WarnOnUnknownFunction;
+    private static void silenceWarnings(Runnable action) {
+        boolean bVerboseWarnings = NodeValue.VerboseWarnings;
+        boolean bWarnOnUnknownFunction = E_Function.WarnOnUnknownFunction;
         NodeValue.VerboseWarnings = false;
         E_Function.WarnOnUnknownFunction = false;
+        try {
+            action.run();
+        } finally {
+            NodeValue.VerboseWarnings = bVerboseWarnings;
+            E_Function.WarnOnUnknownFunction = bWarnOnUnknownFunction;
+        }
     }
 
-    @AfterClass
-    public static void afterClass() {
-        NodeValue.VerboseWarnings = bVerboseWarnings;
-        E_Function.WarnOnUnknownFunction = bWarnOnUnknownFunction;
-    }
-    
     @Test
     public void runTest() {
-        checkedClone(query);
+        silenceWarnings(()->checkedClone(query));
     }
 
     @Parameters(name = "Query.clone {0}")
     public static Collection<Object[]> generateTestParams() throws Exception
     {
-        beforeClass();
-        List<String> exclusions = Arrays.asList(/* no exclusions as all test 
cases work */);
+        List<String> exclusions = List.of(/* no exclusions as all test cases 
work */);
 
         Path startPath = Path.of("./testing/ARQ").toAbsolutePath().normalize();
         PathMatcher pathMatcher = 
startPath.getFileSystem().getPathMatcher("glob:**/*.rq");
@@ -113,9 +106,10 @@ public class TestQueryCloningEssentials {
                     if(!isExcluded) {
                         String queryStr = 
Files.lines(file).collect(Collectors.joining("\n"));
                         try {
-                            Query query = QueryFactory.create(queryStr);
-
-                            testParams.add(new Object[] {file, query});
+                            silenceWarnings(()->{
+                                Query query = QueryFactory.create(queryStr);
+                                testParams.add(new Object[] {file, query});
+                            });
                         } catch(Exception e) {
                             // Silently ignore queries that fail to parse
                         }
@@ -127,6 +121,4 @@ public class TestQueryCloningEssentials {
 
         return testParams;
     }
-
-
 }
diff --git 
a/jena-text/src/test/java/org/apache/jena/query/text/TestTextMultipleProplistNotWorking.java
 
b/jena-text/src/test/java/org/apache/jena/query/text/TestTextMultipleProplistNotWorking.java
index 08d8292ab0..c092b6708c 100644
--- 
a/jena-text/src/test/java/org/apache/jena/query/text/TestTextMultipleProplistNotWorking.java
+++ 
b/jena-text/src/test/java/org/apache/jena/query/text/TestTextMultipleProplistNotWorking.java
@@ -27,7 +27,6 @@ import java.io.StringReader;
 import java.util.*;
 
 import org.apache.jena.assembler.Assembler;
-import org.apache.jena.atlas.lib.StrUtils;
 import org.apache.jena.query.*;
 import org.apache.jena.query.text.assembler.TextAssembler;
 import org.apache.jena.rdf.model.Literal;
@@ -41,116 +40,111 @@ import org.junit.Test;
 // GH-2094
 public class TestTextMultipleProplistNotWorking extends 
AbstractTestDatasetWithTextIndexBase {
 
-    private static final String RES_BASE = "http://example.org/resource#";;
-    private static final String SPEC_BASE = "http://example.org/spec#";;
-    private static final String SPEC_ROOT_LOCAL = "lucene_text_dataset";
-    private static final String SPEC_ROOT_URI = SPEC_BASE + SPEC_ROOT_LOCAL;
+    private static final String SPEC_ROOT_URI = 
"http://example.org/spec#lucene_text_dataset";;
     private static final String SPEC;
 
-    protected static final String TURTLE_PROLOG2 =
-            StrUtils.strjoinNL("@prefix rdfs: 
<http://www.w3.org/2000/01/rdf-schema#> .",
-            "@prefix mt: <http://id.example.test/vocab/#> .",
-            "@prefix mx: <http://id.example.test/mx/#> ."
-
-            );
-    protected static final String QUERY_PROLOG2 =
-            StrUtils.strjoinNL(
-                    "prefix res:  <" + RES_BASE + "> ",
-                    "prefix spec: <" + SPEC_BASE + "> ",
-                    "prefix mt: <http://id.example.test/vocab/#>",
-                    "prefix text: <http://jena.apache.org/text#> ",
-                    "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> ",
-                    "prefix skos: <http://www.w3.org/2004/02/skos/core#> "
-                    );
+    protected static final String TURTLE_PROLOG2 = """
+            @prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+            @prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+            @prefix mt: <http://id.example.test/vocab/#> .
+            @prefix mx: <http://id.example.test/mx/#> .
+            """;
+
+    protected static final String QUERY_PROLOG2 = """
+                    prefix res:  <http://example.org/resource#>
+                    prefix spec: <http://example.org/spec#>
+                    prefix mt: <http://id.example.test/vocab/#>
+                    prefix text: <http://jena.apache.org/text#>
+                    prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+                    prefix skos: <http://www.w3.org/2004/02/skos/core#>
+                    """;
     static {
-        SPEC = StrUtils.strjoinNL(
-                "@prefix :        <http://example.org/spec#> .",
-                "@prefix rdf:     
<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .",
-                "@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .",
-                "@prefix tdb2:    <http://jena.apache.org/2016/tdb#> .",
-                "@prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> 
.",
-                "@prefix text:    <http://jena.apache.org/text#> .",
-                "@prefix fuseki:  <http://jena.apache.org/fuseki#> .",
-                "@prefix mt:      <http://id.example.test/vocab/#> .",
-                "@prefix mx:      <http://id.example.test/mx/#> .",
-
-                "[] ja:loadClass       
\"org.apache.jena.query.text.TextQuery\" .",
-                "text:TextDataset      rdfs:subClassOf   ja:RDFDataset .",
-                "text:TextIndexLucene  rdfs:subClassOf   text:TextIndex .",
-
-                ":lucene_text_dataset",
-                "    a text:TextDataset ;",
-                "    text:dataset   <#dataset> ;",
-                "    text:index     <#indexLucene> ;",
-                "    .",
-
-                "# A TDB dataset used for RDF storage",
-                "<#dataset> ",
-                "    a tdb2:DatasetTDB2 ;",
-                "    tdb2:location  \"--mem--\" ;",
-                "    .",
-
-                "# Text index description",
-
-                "<#indexLucene> ",
-                "    a text:TextIndexLucene ;",
-                "    text:storeValues true ;",
-                "    text:directory \"mem\" ;",
-                "    text:defineAnalyzers (",
-                "      [ text:addLang \"en-01\" ;",
-                "        text:searchFor ( \"en-01\" \"en-02\" ) ;",
-                "        text:analyzer [ a text:StandardAnalyzer ]",
-                "      ]",
-                "     ",
-                "      [ text:addLang \"en-02\" ;",
-                "        text:searchFor ( \"en-01\" \"en-02\" ) ;",
-                "        text:analyzer [ a text:StandardAnalyzer ]",
-                "      ] ) ;",
-                "    text:entityMap <#entMap> ;",
-                "        text:propLists (",
-                "        [ text:propListProp mt:defQuery ;",
-                "          text:props ( ",
-                "             rdfs:label",
-                "             mt:altLabel",
-                "             mt:alt_label",
-                "             mx:alt_label",
-                "             ) ;",
-                "        ]",
-                "        [ text:propListProp mt:includeNotes ;",
-                "          text:props (",
-                "               rdfs:label",
-                "               mt:altLabel",
-                "               mt:alt_label",
-                "               mx:alt_label           ",
-                "               mt:note",
-                "             ) ;",
-                "        ]",
-                "    ) ;",
-                "     .",
-
-                "<#entMap> ",
-                "    a text:EntityMap ;",
-                "    text:defaultField     \"comment\" ;",
-                "    text:entityField      \"uri\" ;",
-                "    text:uidField         \"uid\" ;",
-                "    text:langField        \"lang\" ;",
-                "    text:graphField       \"graph\" ;",
-                "    text:map (",
-                "[ text:field \"comment\" ; text:predicate rdfs:comment ]",
-                "         [ text:field \"ftext\" ; text:predicate rdfs:label 
]",
-                "         [ text:field \"ftext\" ; text:predicate mt:altLabel 
]",
-                "         [ text:field \"ftext\" ; text:predicate mt:alt_label 
]",
-                "         [ text:field \"ftext\" ; text:predicate mx:alt_label 
]",
-                "         [ text:field \"note\" ; text:predicate mt:note ]",
-                "         ) ."
-
-                );
+        SPEC = """
+                @prefix :        <http://example.org/spec#> .
+                @prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
.
+                @prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+                @prefix tdb2:    <http://jena.apache.org/2016/tdb#> .
+                @prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .
+                @prefix text:    <http://jena.apache.org/text#> .
+                @prefix fuseki:  <http://jena.apache.org/fuseki#> .
+                @prefix mt:      <http://id.example.test/vocab/#> .
+                @prefix mx:      <http://id.example.test/mx/#> .
+
+                [] ja:loadClass       "org.apache.jena.query.text.TextQuery" .
+                text:TextDataset      rdfs:subClassOf   ja:RDFDataset .
+                text:TextIndexLucene  rdfs:subClassOf   text:TextIndex .
+
+                :lucene_text_dataset
+                    a text:TextDataset ;
+                    text:dataset   <#dataset> ;
+                    text:index     <#indexLucene> ;
+                    .
+
+                # A TDB dataset used for RDF storage
+                <#dataset>
+                    a tdb2:DatasetTDB2 ;
+                    tdb2:location  "--mem--" ;
+                    .
+
+                # Text index description
+
+                <#indexLucene>
+                    a text:TextIndexLucene ;
+                    text:storeValues true ;
+                    text:directory "mem" ;
+                    text:multilingualSupport true ;
+                    text:defineAnalyzers (
+                      [ text:addLang "en-01" ;
+                        text:searchFor ( "en-01" "en-02" ) ;
+                        text:analyzer [ a text:StandardAnalyzer ]
+                      ]
+
+                      [ text:addLang "en-02" ;
+                        text:searchFor ( "en-01" "en-02" ) ;
+                        text:analyzer [ a text:StandardAnalyzer ]
+                      ] ) ;
+                    text:entityMap <#entMap> ;
+                        text:propLists (
+                        [ text:propListProp mt:defQuery ;
+                          text:props (
+                             rdfs:label
+                             mt:altLabel
+                             mt:alt_label
+                             mx:alt_label
+                             ) ;
+                        ]
+                        [ text:propListProp mt:includeNotes ;
+                          text:props (
+                               rdfs:label
+                               mt:altLabel
+                               mt:alt_label
+                               mx:alt_label
+                               mt:note
+                             ) ;
+                        ]
+                    ) ;
+                     .
+
+                <#entMap>
+                    a text:EntityMap ;
+                    text:defaultField     "comment" ;
+                    text:entityField      "uri" ;
+                    text:uidField         "uid" ;
+                    text:langField        "lang" ;
+                    text:graphField       "graph" ;
+                    text:map (
+                [ text:field "comment" ; text:predicate rdfs:comment ]
+                         [ text:field "ftext" ; text:predicate rdfs:label ]
+                         [ text:field "ftext" ; text:predicate mt:altLabel ]
+                         [ text:field "ftext" ; text:predicate mt:alt_label ]
+                         [ text:field "ftext" ; text:predicate mx:alt_label ]
+                         [ text:field "note" ; text:predicate mt:note ]
+                         ) .
+                """;
     }
 
     @Before
     public void before() {
-
-
         Reader reader = new StringReader(SPEC);
         Model specModel = ModelFactory.createDefaultModel();
         specModel.read(reader, "", "TURTLE");
@@ -203,43 +197,41 @@ public class TestTextMultipleProplistNotWorking extends 
AbstractTestDatasetWithT
 
     @Test
     public void test01TextPropNotWorkingInSomeCases() {
-        final String turtleA = StrUtils.strjoinNL(
-                TURTLE_PROLOG2,
-                "<http://id.example.test/1>",
-                "  rdfs:label\"beer\"@en ;",
-                "  mt:altLabel\"pint\"@en ;",
-                "  mx:alt_label\"pivečko\"@cs ;",
-                "  mt:note\"Booze is a pleasure\"@en,\"Chlast je slast\"@cs .",
-
-                "<http://id.example.test/2>",
-                "  mt:alt_label\"ale\"@en,\"burgundy\"@en ;",
-                "  rdfs:label\"wine \"@en ;",
-                "  mt:altLabel\"champagne\"@en ;",
-                "  mx:alt_label\"víno\"@cs ;",
-                "  mt:note\"Red or white\"@en,\"Červené či bílé\"@cs .",
-
-                "<http://id.example.test/3>",
-                "  mt:alt_label\"Scotch\"@en ;",
-                "  rdfs:comment\"Johnnie Walker red label \"@en ."
-
-                );
+        final String turtleA = TURTLE_PROLOG2 +"""
+                <http://id.example.test/1>
+                  rdfs:label "beer"@en ;
+                  mt:altLabel "pint"@en ;
+                  mx:alt_label "pivečko"@cs ;
+                  mt:note "Booze is a pleasure"@en,"C hlast je slast"@cs .
+
+                <http://id.example.test/2>
+                  mt:alt_label "ale"@en,"burgundy"@en ;
+                  rdfs:label "wine "@en ;
+                  mt:altLabel "champagne"@en ;
+                  mx:alt_label "víno"@cs ;
+                  mt:note "Red or white"@en, "Červené či bílé"@cs .
+
+                <http://id.example.test/3>
+                  mt:alt_label"Scotch"@en ;
+                  rdfs:comment"Johnnie Walker red label "@en .
+                """;
+
         putTurtleInModel(turtleA, null) ;
-        String queryString = StrUtils.strjoinNL(
-                QUERY_PROLOG2,
-                "SELECT ?s ?lit",
-                "WHERE {",
-                "  (?s ?sc ?lit) text:query ( mt:includeNotes 'red booze' ) . 
",
-                "}"
-                );
-        String queryStringMtNote = StrUtils.strjoinNL(
-                QUERY_PROLOG2,
-                "SELECT ?s ?lit",
-                "WHERE {",
-                "  (?s ?sc ?lit)  text:query ( mt:note \"red booze\" ) . ",
-                "}"
-        );
+        String queryString = QUERY_PROLOG2+"""
+                SELECT ?s ?lit
+                WHERE {
+                  (?s ?sc ?lit) text:query ( mt:includeNotes 'red booze' ) .
+                }
+                """;
+        String queryStringMtNote = QUERY_PROLOG2 + """
+                SELECT ?s ?lit
+                WHERE {
+                  (?s ?sc ?lit)  text:query ( mt:note "red booze" ) .
+                }
+                """;
+
         Set<String> expectedURIs = new HashSet<>() ;
-        expectedURIs.addAll( 
Arrays.asList("http://id.example.test/1","http://id.example.test/2";)) ;
+        expectedURIs.addAll( Arrays.asList("http://id.example.test/1";, 
"http://id.example.test/2";)) ;
 
         Map<String, Literal> literals = doTestSearchWithLiterals(queryString, 
expectedURIs) ;
 
@@ -261,43 +253,41 @@ public class TestTextMultipleProplistNotWorking extends 
AbstractTestDatasetWithT
 
     @Test
     public void test02TextPropNotWorkingInSomeCases() {
-        final String turtleA = StrUtils.strjoinNL(
-                TURTLE_PROLOG2,
-                "<http://id.example.test/1>",
-                "  rdfs:label\"beer\"@en-01 ;",
-                "  mt:altLabel\"pint\"@en-01 ;",
-                "  mx:alt_label\"pivečko\"@cs ;",
-                "  mt:note\"Booze is a pleasure\"@en-01,\"Chlast je slast\"@cs 
.",
-
-                "<http://id.example.test/2>",
-                "  mt:alt_label\"ale\"@en-01 , \"burgundy\"@en-01 ;",
-                "  rdfs:label\"wine \"@en-01 ;",
-                "  mt:altLabel\"champagne\"@en-01 ;",
-                "  mx:alt_label\"víno\"@cs ;",
-                "  mt:note\"Red or white\"@en-01,\"Červené či bílé\"@cs .",
-
-                "<http://id.example.test/3>",
-                "  mt:alt_label\"Scotch\"@en-01 ;",
-                "  rdfs:comment\"Johnnie Walker red label \"@en-01 ."
-
-        );
+        final String turtleA = TURTLE_PROLOG2+"""
+                <http://id.example.test/1>
+                  rdfs:label "beer"@en-01 ;
+                  mt:altLabel "pint"@en-01 ;
+                  mx:alt_label "pivečko"@cs ;
+                  mt:note "Booze is a pleasure"@en-01, "Chlast je slast"@cs .
+
+                <http://id.example.test/2>
+                  mt:alt_label "ale"@en-01 , "burgundy"@en-01 ;
+                  rdfs:label "wine"@en-01 ;
+                  mt:altLabel "champagne"@en-01 ;
+                  mx:alt_label "víno"@cs ;
+                  mt:note  "Red or white"@en-01, "Červené či bílé"@cs .
+
+                <http://id.example.test/3>
+                  mt:alt_label "Scotch"@en-01 ;
+                  rdfs:comment "Johnnie Walker red label "@en-01 .
+               """;
+
         putTurtleInModel(turtleA, null) ;
-        String queryString = StrUtils.strjoinNL(
-                QUERY_PROLOG2,
-                "SELECT ?s ?lit",
-                "WHERE {",
-                "  (?s ?sc ?lit) text:query ( mt:includeNotes \"red 
booze\"@en-02 ) . ",
-                "}"
-        );
-        String queryStringMtNote = StrUtils.strjoinNL(
-                QUERY_PROLOG2,
-                "SELECT ?s ?lit",
-                "WHERE {",
-                "  (?s ?sc ?lit)  text:query ( mt:note \"red booze\"@en-02 ) . 
",
-                "}"
-        );
+        String queryString = QUERY_PROLOG2+"""
+                SELECT ?s ?lit
+                WHERE {
+                  (?s ?sc ?lit) text:query ( mt:includeNotes "red booze"@en-02 
) .
+                }
+                """;
+        String queryStringMtNote = QUERY_PROLOG2+"""
+                SELECT ?s ?lit
+                WHERE {
+                  (?s ?sc ?lit)  text:query ( mt:note "red booze"@en-02 ) .
+                }
+                """;
+
         Set<String> expectedURIs = new HashSet<>() ;
-        expectedURIs.addAll( 
Arrays.asList("http://id.example.test/1","http://id.example.test/2";)) ;
+        expectedURIs.addAll( Arrays.asList("http://id.example.test/1";, 
"http://id.example.test/2";)) ;
 
         Map<String, Literal> literals = doTestSearchWithLiterals(queryString, 
expectedURIs) ;
 

Reply via email to