Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2016-02-19 06:42:34 +0000
committerAlexander Kurtakov2016-02-19 06:42:34 +0000
commit7bb252ce081ff886475ba1eb8acc4eeda99f6267 (patch)
treeb97bdad0eb5c1518e57c737b8cf96922635f67c1 /org.eclipse.ua.tests/help
parent406539b07bfefe96f008098522f257fc91183415 (diff)
downloadeclipse.platform.ua-7bb252ce081ff886475ba1eb8acc4eeda99f6267.tar.gz
eclipse.platform.ua-7bb252ce081ff886475ba1eb8acc4eeda99f6267.tar.xz
eclipse.platform.ua-7bb252ce081ff886475ba1eb8acc4eeda99f6267.zip
Bug 488072 - Move o.e.ua.tests to Java 8
Fix all the new warnings: * try-with-resources * useless type definitions Change-Id: Ib03065e19467d1ce094fe2345ee391f2a987b781 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'org.eclipse.ua.tests/help')
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseCriteriaDefinition.java2
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java8
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/SampleCriteriaProvider.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/DynamicXHTMLProcessorTest.java24
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java8
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java6
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/DocumentReaderTest.java9
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/EntityResolutionTest.java11
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserContext.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriteriaDefinition.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriterionDefinition.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndex.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexEntry.java8
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexSee.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc2.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic2.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/IndexAssemblePerformanceTest.java10
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/TocAssemblePerformanceTest.java10
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/preferences/HelpDataTest.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContextServletTest.java32
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/IndexServletTest.java20
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadIndexUsingRemoteHelp.java2
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockSearchServlet.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ParallelSearchServletTest.java33
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java26
-rwxr-xr-xorg.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/SearchServletTest.java33
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java2
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java20
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java6
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/InfocenterWorkingSetManagerTest.java12
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipant.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipantXML.java6
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java15
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchTestUtils.java12
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/WorkingSetManagerTest.java2
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/EnabledTopicTest.java8
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java8
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/LoadServletUtil.java53
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ProducerSerializerTest.java10
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/TocModelSerializerTest.java2
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java18
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java25
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletRequest.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletResponse.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java33
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java20
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java21
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java20
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java16
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexServiceTest.java18
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java22
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocServiceTest.java18
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webextension/TitleSearchData.java22
56 files changed, 337 insertions, 358 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseCriteriaDefinition.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseCriteriaDefinition.java
index 0d4227997..f36037681 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseCriteriaDefinition.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseCriteriaDefinition.java
@@ -35,7 +35,7 @@ public class ParseCriteriaDefinition {
CriteriaDefinitionContribution result_a_b = parser.parse(new CriteriaDefinitionFile(UserAssistanceTestPlugin.getPluginId(), "data/help/criteria/criteria_definition/result_a_b.xml", "en"));
CriteriaDefinitionAssembler assembler = new CriteriaDefinitionAssembler();
- List<CriteriaDefinitionContribution> contributions = new ArrayList<CriteriaDefinitionContribution>(Arrays.asList(a, b));
+ List<CriteriaDefinitionContribution> contributions = new ArrayList<>(Arrays.asList(a, b));
CriteriaDefinition assembled = assembler.assemble(contributions);
String expected = serialize((UAElement)result_a_b.getCriteriaDefinition());
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java
index 834ec90c6..ad76b4b7a 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java
@@ -58,7 +58,7 @@ public class ParseTocWithCriteria {
@Test
public void testTocWithCriteria() throws Exception {
IToc2 toc = parseToc("data/help/criteria/c1.xml");
- Map<String, Set<String>> criteria = new HashMap<String, Set<String>>();
+ Map<String, Set<String>> criteria = new HashMap<>();
CriteriaUtilities.addCriteriaToMap(criteria, toc.getCriteria());
assertEquals(2, criteria.size());
Set<String> versions = criteria.get("version");
@@ -78,7 +78,7 @@ public class ParseTocWithCriteria {
public void testCopyTocWithCriteria() throws Exception {
IToc toc0 = parseToc("data/help/criteria/c1.xml");
Toc toc = new Toc(toc0);
- Map<String, Set<String>> criteria = new HashMap<String, Set<String>>();
+ Map<String, Set<String>> criteria = new HashMap<>();
CriteriaUtilities.addCriteriaToMap(criteria, toc.getCriteria());
assertEquals(2, criteria.size());
Set<String> versions = criteria.get("version");
@@ -100,7 +100,7 @@ public class ParseTocWithCriteria {
ITopic[] topics = toc.getTopics();
assertEquals(topics.length, 2);
// First topic
- Map<String, Set<String>> criteria = new HashMap<String, Set<String>>();
+ Map<String, Set<String>> criteria = new HashMap<>();
assertTrue(topics[0] instanceof ITopic2);
CriteriaUtilities.addCriteriaToMap(criteria, ((ITopic2)topics[0]).getCriteria());
assertEquals(2, criteria.size());
@@ -112,7 +112,7 @@ public class ParseTocWithCriteria {
// Second topic
- criteria = new HashMap<String, Set<String>>();
+ criteria = new HashMap<>();
assertTrue(topics[1] instanceof ITopic2);
CriteriaUtilities.addCriteriaToMap(criteria, ((ITopic2)topics[1]).getCriteria());
versions = criteria.get("version");
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/SampleCriteriaProvider.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/SampleCriteriaProvider.java
index a902c086a..2b26dc15d 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/SampleCriteriaProvider.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/SampleCriteriaProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation and others.
+ * Copyright (c) 2010, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -34,7 +34,7 @@ public class SampleCriteriaProvider extends AbstractCriteriaProvider {
}
private UserCriteria[] getCriteriaFromLabel(String label) {
- List<UserCriteria> criteria = new ArrayList<UserCriteria>();
+ List<UserCriteria> criteria = new ArrayList<>();
if (label == null) {
return new UserCriteria[0];
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/DynamicXHTMLProcessorTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/DynamicXHTMLProcessorTest.java
index 20a318b7b..96ad6cbe8 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/DynamicXHTMLProcessorTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/DynamicXHTMLProcessorTest.java
@@ -52,18 +52,18 @@ public class DynamicXHTMLProcessorTest {
}
private String readStream(InputStream is) throws Exception {
- InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8");
- StringBuffer buffer = new StringBuffer();
- char[] cbuf = new char[256];
- int len;
- do {
- len = inputStreamReader.read(cbuf);
- if (len > 0) {
- buffer.append(cbuf, 0, len);
- }
- } while (len >= 0);
- inputStreamReader.close();
- return buffer.toString();
+ try (InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8")) {
+ StringBuffer buffer = new StringBuffer();
+ char[] cbuf = new char[256];
+ int len;
+ do {
+ len = inputStreamReader.read(cbuf);
+ if (len > 0) {
+ buffer.append(cbuf, 0, len);
+ }
+ } while (len >= 0);
+ return buffer.toString();
+ }
}
@Test
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java
index 8535f43bb..c146999c1 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java
@@ -45,9 +45,11 @@ public class XMLProcessorTest {
};
XMLProcessor processor = new XMLProcessor(handlers);
Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle();
- InputStream in = bundle.getEntry(FileUtil.getResultFile(path)).openStream();
- InputStream in2 = processor.process(bundle.getEntry(path).openStream(), '/' + bundle.getSymbolicName() + '/' + path, "UTF-8");
- XMLUtil.assertXMLEquals("XML content was not processed correctly: " + path, in, in2);
+ try (InputStream in = bundle.getEntry(FileUtil.getResultFile(path)).openStream();
+ InputStream in2 = processor.process(bundle.getEntry(path).openStream(),
+ '/' + bundle.getSymbolicName() + '/' + path, "UTF-8")) {
+ XMLUtil.assertXMLEquals("XML content was not processed correctly: " + path, in, in2);
+ }
}
@Test
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java
index 3021a074a..41f79d57d 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java
@@ -46,7 +46,7 @@ public class IndexAssemblerTest {
IndexContribution result_a_b_c = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/result_a_b_c.xml", "en"));
IndexAssembler assembler = new IndexAssembler();
- List<IndexContribution> contributions = new ArrayList<IndexContribution>(Arrays.asList(a, b, c));
+ List<IndexContribution> contributions = new ArrayList<>(Arrays.asList(a, b, c));
Index assembled = assembler.assemble(contributions, Platform.getNL());
String expected = serialize((UAElement)result_a_b_c.getIndex());
@@ -59,7 +59,7 @@ public class IndexAssemblerTest {
IndexFileParser parser = new IndexFileParser();
IndexContribution contrib = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/d.xml", "en"));
IndexAssembler assembler = new IndexAssembler();
- List<IndexContribution> contributions = new ArrayList<IndexContribution>(Arrays.asList(contrib));
+ List<IndexContribution> contributions = new ArrayList<>(Arrays.asList(contrib));
Index index = assembler.assemble(contributions, Platform.getNL());
IIndexEntry[] children = index.getEntries();
assertEquals(2,children.length);
@@ -87,7 +87,7 @@ public class IndexAssemblerTest {
IndexFileParser parser = new IndexFileParser();
IndexContribution contrib = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/hasTitle.xml", "en"));
IndexAssembler assembler = new IndexAssembler();
- List<IndexContribution> contributions = new ArrayList<IndexContribution>(Arrays.asList(contrib));
+ List<IndexContribution> contributions = new ArrayList<>(Arrays.asList(contrib));
Index index = assembler.assemble(contributions, Platform.getNL());
IIndexEntry[] children = index.getEntries();
assertEquals(1,children.length);
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/DocumentReaderTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/DocumentReaderTest.java
index 6e4b32ead..a6f817b15 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/DocumentReaderTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/DocumentReaderTest.java
@@ -30,10 +30,11 @@ public class DocumentReaderTest {
private final static int FAILURE = 2;
private void readFile(DocumentReader docReader, String file) throws IOException, SAXException, ParserConfigurationException {
- String pluginId = UserAssistanceTestPlugin.getPluginId();
- String locale = "en";
- InputStream in = ResourceLocator.openFromPlugin(pluginId, file, locale);
- docReader.read(in);
+ String pluginId = UserAssistanceTestPlugin.getPluginId();
+ String locale = "en";
+ try (InputStream in = ResourceLocator.openFromPlugin(pluginId, file, locale)) {
+ docReader.read(in);
+ }
}
@Test
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/EntityResolutionTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/EntityResolutionTest.java
index 61bedb555..cf0145cc1 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/EntityResolutionTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/EntityResolutionTest.java
@@ -24,10 +24,9 @@ public class EntityResolutionTest {
public void resolve(String systemId, boolean isSupportedDtd) throws Exception {
- LocalEntityResolver resolver = new LocalEntityResolver();
- InputSource is = resolver.resolveEntity("publicId", systemId);
- Reader reader = is.getCharacterStream();
- InputStream stream = is.getByteStream();
+ LocalEntityResolver resolver = new LocalEntityResolver();
+ InputSource is = resolver.resolveEntity("publicId", systemId);
+ try (Reader reader = is.getCharacterStream(); InputStream stream = is.getByteStream()) {
int read;
if (reader != null) {
char[] cbuf = new char[5];
@@ -42,9 +41,7 @@ public class EntityResolutionTest {
} else {
assertTrue("Unsupported Entity did not return empty stream", read == -1);
}
- if (stream != null) {
- stream.close();
- }
+ }
}
@Test
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserContext.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserContext.java
index 059e8509e..bb1e04cc0 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserContext.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -27,7 +27,7 @@ public class UserContext implements IContext3 {
private String title;
private String text;
- private List<ITopic> children = new ArrayList<ITopic>();
+ private List<ITopic> children = new ArrayList<>();
public UserContext(String title, String text) {
this.title = title;
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriteriaDefinition.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriteriaDefinition.java
index ea55b9b0f..225081e75 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriteriaDefinition.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriteriaDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation and others.
+ * Copyright (c) 2010, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,7 +21,7 @@ import org.eclipse.help.IUAElement;
public class UserCriteriaDefinition implements ICriteriaDefinition {
- private List<ICriterionDefinition> children = new ArrayList<ICriterionDefinition>();
+ private List<ICriterionDefinition> children = new ArrayList<>();
@Override
public boolean isEnabled(IEvaluationContext context) {
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriterionDefinition.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriterionDefinition.java
index 05e7dc133..7c5c93bb8 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriterionDefinition.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriterionDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation and others.
+ * Copyright (c) 2010, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,7 +23,7 @@ public class UserCriterionDefinition implements ICriterionDefinition {
private String id;
private String name;
- private List<ICriterionValueDefinition> children = new ArrayList<ICriterionValueDefinition>();
+ private List<ICriterionValueDefinition> children = new ArrayList<>();
public UserCriterionDefinition(String id, String name) {
this.id = id;
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndex.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndex.java
index c60c161c4..9e7f67fff 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndex.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndex.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -25,7 +25,7 @@ import org.eclipse.help.IUAElement;
public class UserIndex implements IIndex {
- private List<IIndexEntry> entries = new ArrayList<IIndexEntry>();
+ private List<IIndexEntry> entries = new ArrayList<>();
private boolean enabled;
public UserIndex(boolean enabled) {
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexEntry.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexEntry.java
index f29bf680d..29cc28404 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexEntry.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexEntry.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -27,9 +27,9 @@ import org.eclipse.help.IUAElement;
public class UserIndexEntry implements IIndexEntry2 {
- private List<IIndexEntry> subentries = new ArrayList<IIndexEntry>();
- private List<IIndexSee> sees = new ArrayList<IIndexSee>();
- private List<ITopic> topics = new ArrayList<ITopic>();
+ private List<IIndexEntry> subentries = new ArrayList<>();
+ private List<IIndexSee> sees = new ArrayList<>();
+ private List<ITopic> topics = new ArrayList<>();
private boolean isEnabled;
private String keyword;
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexSee.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexSee.java
index 7c5d226bc..1d69c0228 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexSee.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserIndexSee.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,7 +21,7 @@ import org.eclipse.help.IUAElement;
public class UserIndexSee implements IIndexSee {
- private List<IIndexSubpath> children = new ArrayList<IIndexSubpath>();
+ private List<IIndexSubpath> children = new ArrayList<>();
private boolean isEnabled;
private String keyword;
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc.java
index 1c3d55dc4..f75bb3201 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 IBM Corporation and others.
+ * Copyright (c) 2005, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,7 +20,7 @@ import org.eclipse.help.IUAElement;
public class UserToc implements IToc {
- private List<ITopic> children = new ArrayList<ITopic>();
+ private List<ITopic> children = new ArrayList<>();
private boolean isEnabled;
private String href;
private String label;
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc2.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc2.java
index de9c54ce5..cd73ff616 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc2.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc2.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation and others.
+ * Copyright (c) 2010, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,7 +24,7 @@ public class UserToc2 extends UserToc implements IToc2 {
super(label, href, isEnabled);
}
- private List<ICriteria> criteria = new ArrayList<ICriteria>();
+ private List<ICriteria> criteria = new ArrayList<>();
@Override
public IUAElement[] getChildren() {
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic.java
index ef404f393..e1e96c841 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 IBM Corporation and others.
+ * Copyright (c) 2007, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,7 +24,7 @@ import org.eclipse.help.IUAElement;
public class UserTopic implements ITopic {
- private List<ITopic> children = new ArrayList<ITopic>();
+ private List<ITopic> children = new ArrayList<>();
private boolean isEnabled;
private String href;
private String label;
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic2.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic2.java
index 629a7be69..a1a0c348e 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic2.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic2.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation and others.
+ * Copyright (c) 2010, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,7 +20,7 @@ import org.eclipse.help.IUAElement;
public class UserTopic2 extends UserTopic implements ITopic2 {
- private List<ICriteria> criteria = new ArrayList<ICriteria>();
+ private List<ICriteria> criteria = new ArrayList<>();
@Override
public IUAElement[] getChildren() {
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/IndexAssemblePerformanceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/IndexAssemblePerformanceTest.java
index 2f94f5f93..3a6738e8c 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/IndexAssemblePerformanceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/IndexAssemblePerformanceTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 IBM Corporation and others.
+ * Copyright (c) 2008, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,9 +17,6 @@ import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.index.Index;
import org.eclipse.help.internal.index.IndexAssembler;
@@ -31,6 +28,9 @@ import org.eclipse.test.performance.PerformanceTestCase;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.xml.sax.SAXException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
public class IndexAssemblePerformanceTest extends PerformanceTestCase {
/*
@@ -73,7 +73,7 @@ public class IndexAssemblePerformanceTest extends PerformanceTestCase {
IndexContribution b = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/performance/index/index2.xml", "en"));
IndexContribution c = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/performance/index/index3.xml", "en"));
IndexAssembler assembler = new IndexAssembler();
- List<IndexContribution> contributions = new ArrayList<IndexContribution>(Arrays.asList(a, b, c));
+ List<IndexContribution> contributions = new ArrayList<>(Arrays.asList(a, b, c));
Index assembled = assembler.assemble(contributions, Platform.getNL());
assertEquals(100, assembled.getChildren().length);
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/TocAssemblePerformanceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/TocAssemblePerformanceTest.java
index d7c07168d..9fb4ab9c3 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/TocAssemblePerformanceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/performance/TocAssemblePerformanceTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 IBM Corporation and others.
+ * Copyright (c) 2008, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,9 +17,6 @@ import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.help.ITopic;
import org.eclipse.help.internal.toc.TocAssembler;
import org.eclipse.help.internal.toc.TocContribution;
@@ -30,6 +27,9 @@ import org.eclipse.test.performance.PerformanceTestCase;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.xml.sax.SAXException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
public class TocAssemblePerformanceTest extends PerformanceTestCase {
/*
@@ -51,7 +51,7 @@ public class TocAssemblePerformanceTest extends PerformanceTestCase {
public void assembleToc() throws Exception {
TocFileParser parser = new TocFileParser();
- List<TocContribution> contributions = new ArrayList<TocContribution>();
+ List<TocContribution> contributions = new ArrayList<>();
contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/jdttoc.xml"));
contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/topics_Guide.xml"));
contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/topics_Porting.xml"));
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/preferences/HelpDataTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/preferences/HelpDataTest.java
index da9d3dd9b..8f6b41feb 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/preferences/HelpDataTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/preferences/HelpDataTest.java
@@ -86,8 +86,8 @@ public class HelpDataTest {
for (String[][] entry : TEST_DATA) {
String file = entry[0][0];
List<String> expectedTocOrder = Arrays.asList(entry[1]);
- Set<String> expectedHiddenTocs = new HashSet<String>(Arrays.asList(entry[2]));
- Set<String> expectedHiddenIndexes = new HashSet<String>(Arrays.asList(entry[3]));
+ Set<String> expectedHiddenTocs = new HashSet<>(Arrays.asList(entry[2]));
+ Set<String> expectedHiddenIndexes = new HashSet<>(Arrays.asList(entry[3]));
URL url = UserAssistanceTestPlugin.getDefault().getBundle().getEntry(file);
HelpData data = new HelpData(url);
Assert.assertEquals("Did not get the expected toc order from help data file " + file, expectedTocOrder, data.getTocOrder());
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContextServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContextServletTest.java
index 612969cb6..068890308 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContextServletTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContextServletTest.java
@@ -92,24 +92,24 @@ public class ContextServletTest {
protected Element[] makeServletCall(URL url) throws IOException,
ParserConfigurationException, FactoryConfigurationError,
SAXException {
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("context", root.getNodeName());
- NodeList children = root.getChildNodes();
- List<Node> topics = new ArrayList<Node>();
- int length = children.getLength();
- for (int i = 0; i < length; i++) {
- Node next = children.item(i);
- if ("topic".equals(next.getNodeName())) {
- topics.add(next);
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ assertEquals("context", root.getNodeName());
+ NodeList children = root.getChildNodes();
+ List<Node> topics = new ArrayList<>();
+ int length = children.getLength();
+ for (int i = 0; i < length; i++) {
+ Node next = children.item(i);
+ if ("topic".equals(next.getNodeName())) {
+ topics.add(next);
+ }
}
+ return topics.toArray(new Element[topics.size()]);
}
- return topics.toArray(new Element[topics.size()]);
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/IndexServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/IndexServletTest.java
index e2e2f3c80..323fd3db5 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/IndexServletTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/IndexServletTest.java
@@ -121,7 +121,7 @@ public class IndexServletTest {
private Element[] findEntryInAllContributions(Node parent, String keyword) {
NodeList contributions = parent.getChildNodes();
- List<Node> results = new ArrayList<Node>();
+ List<Node> results = new ArrayList<>();
for (int i = 0; i < contributions.getLength(); i++) {
Node next = contributions.item(i);
if (next instanceof Element) {
@@ -169,15 +169,15 @@ public class IndexServletTest {
throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/index?lang=" + locale);
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("indexContributions", root.getNodeName());
- return root;
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ assertEquals("indexContributions", root.getNodeName());
+ return root;
+ }
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadIndexUsingRemoteHelp.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadIndexUsingRemoteHelp.java
index a821e420d..1a771fb80 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadIndexUsingRemoteHelp.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadIndexUsingRemoteHelp.java
@@ -77,7 +77,7 @@ public class LoadIndexUsingRemoteHelp {
}
private IIndexEntry[] matchingEntries(IIndex index, String keyword) {
- List<IIndexEntry> matches = new ArrayList<IIndexEntry>();
+ List<IIndexEntry> matches = new ArrayList<>();
IIndexEntry[] entries = index.getEntries();
for (IIndexEntry entrie : entries) {
if (keyword.equals(entrie.getKeyword())) {
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockSearchServlet.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockSearchServlet.java
index 28888803f..9e9255ace 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockSearchServlet.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockSearchServlet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -35,7 +35,7 @@ public class MockSearchServlet extends HttpServlet {
String locale = UrlUtil.getLocale(req, resp);
req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
- List<SearchHit> results = new ArrayList<SearchHit>();
+ List<SearchHit> results = new ArrayList<>();
if (isSearchHit(phrase, locale)) {
SearchHit hit = new SearchHit("http://www.eclipse.org",
"Hit from Mock Servlet",
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ParallelSearchServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ParallelSearchServletTest.java
index dfb94bd19..87c82d0bc 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ParallelSearchServletTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ParallelSearchServletTest.java
@@ -116,24 +116,25 @@ public class ParallelSearchServletTest {
private Node[] makeServletCall(URL url) throws IOException,
ParserConfigurationException, FactoryConfigurationError,
SAXException {
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("searchHits", root.getNodeName());
- NodeList children = root.getChildNodes();
- List<Node> hits = new ArrayList<Node>();
- int length = children.getLength();
- for (int i = 0; i < length; i++) {
- Node next = children.item(i);
- if ("hit".equals(next.getNodeName())) {
- hits.add(next);
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ is.close();
+ assertEquals("searchHits", root.getNodeName());
+ NodeList children = root.getChildNodes();
+ List<Node> hits = new ArrayList<>();
+ int length = children.getLength();
+ for (int i = 0; i < length; i++) {
+ Node next = children.item(i);
+ if ("hit".equals(next.getNodeName())) {
+ hits.add(next);
+ }
}
+ return hits.toArray(new Node[hits.size()]);
}
- return hits.toArray(new Node[hits.size()]);
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java
index 8523acfa8..bbf79b072 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java
@@ -55,19 +55,19 @@ public class RemoteTestUtils {
public static String readFromURL(URL url) throws IOException,
UnsupportedEncodingException {
- InputStream is = url.openStream();
- InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8");
- StringBuffer buffer = new StringBuffer();
- char[] cbuf = new char[256];
- int len;
- do {
- len = inputStreamReader.read(cbuf);
- if (len > 0) {
- buffer.append(cbuf, 0, len);
- }
- } while (len >= 0);
- inputStreamReader.close();
- return buffer.toString();
+ try (InputStream is = url.openStream();
+ InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8")) {
+ StringBuffer buffer = new StringBuffer();
+ char[] cbuf = new char[256];
+ int len;
+ do {
+ len = inputStreamReader.read(cbuf);
+ if (len > 0) {
+ buffer.append(cbuf, 0, len);
+ }
+ } while (len >= 0);
+ return buffer.toString();
+ }
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/SearchServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/SearchServletTest.java
index 3d728fb8a..618a254e7 100755
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/SearchServletTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/SearchServletTest.java
@@ -131,24 +131,25 @@ public class SearchServletTest {
protected Node[] makeServletCall(URL url) throws IOException,
ParserConfigurationException, FactoryConfigurationError,
SAXException {
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("searchHits", root.getNodeName());
- NodeList children = root.getChildNodes();
- List<Node> hits = new ArrayList<Node>();
- int length = children.getLength();
- for (int i = 0; i < length; i++) {
- Node next = children.item(i);
- if ("hit".equals(next.getNodeName())) {
- hits.add(next);
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ is.close();
+ assertEquals("searchHits", root.getNodeName());
+ NodeList children = root.getChildNodes();
+ List<Node> hits = new ArrayList<>();
+ int length = children.getLength();
+ for (int i = 0; i < length; i++) {
+ Node next = children.item(i);
+ if ("hit".equals(next.getNodeName())) {
+ hits.add(next);
+ }
}
+ return hits.toArray(new Node[hits.size()]);
}
- return hits.toArray(new Node[hits.size()]);
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java
index dfb2f6b5a..903c07b09 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java
@@ -102,7 +102,7 @@ public class TocManagerTest {
public static boolean hasDuplicateContributions(TocContribution[] tocContributions)
{
- HashSet<String> contributionsFound = new HashSet<String>();
+ HashSet<String> contributionsFound = new HashSet<>();
for (TocContribution tocContribution : tocContributions) {
if(contributionsFound.contains(tocContribution.getId()))
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java
index 42b2e85a4..1c540b16f 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java
@@ -106,7 +106,7 @@ public class TocServletTest {
private Element[] findChildren(Node parent, String childKind, String attributeName, String attributeValue) {
NodeList contributions = parent.getChildNodes();
- List<Node> results = new ArrayList<Node>();
+ List<Node> results = new ArrayList<>();
for (int i = 0; i < contributions.getLength(); i++) {
Node next = contributions.item(i);
if (next instanceof Element) {
@@ -125,15 +125,15 @@ public class TocServletTest {
throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/toc?lang=" + locale);
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("tocContributions", root.getNodeName());
- return root;
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ assertEquals("tocContributions", root.getNodeName());
+ return root;
+ }
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java
index b29a227eb..336d33bf1 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java
@@ -129,7 +129,7 @@ public class ExtraDirTest {
WorkingSet[] workingSets = null;
if (scope != null) {
WorkingSetManager wsm = BaseHelpSystem.getWorkingSetManager();
- List<AdaptableToc> tocs = new ArrayList<AdaptableToc>();
+ List<AdaptableToc> tocs = new ArrayList<>();
StringTokenizer tok = new StringTokenizer(scope, ", \t\n");
while (tok.hasMoreTokens()) {
tocs.add(wsm.getAdaptableToc(tok.nextToken()));
@@ -138,7 +138,7 @@ public class ExtraDirTest {
}
// expected hits
- final Set<String> hrefsToFind = new HashSet<String>();
+ final Set<String> hrefsToFind = new HashSet<>();
if (expectedResults != null) {
StringTokenizer tok = new StringTokenizer(expectedResults, ", \t\n");
while (tok.hasMoreTokens()) {
@@ -147,7 +147,7 @@ public class ExtraDirTest {
}
// run test
- final Set<String> unexpectedHrefs = new HashSet<String>();
+ final Set<String> unexpectedHrefs = new HashSet<>();
ISearchQuery query = new SearchQuery(searchWord, false, new ArrayList<String>(), Platform.getNL());
SearchResults collector = new SearchResults(workingSets, 500, Platform.getNL());
BaseHelpSystem.getSearchManager().search(query, collector, new NullProgressMonitor());
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/InfocenterWorkingSetManagerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/InfocenterWorkingSetManagerTest.java
index ecfccd455..6d97b0da9 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/InfocenterWorkingSetManagerTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/InfocenterWorkingSetManagerTest.java
@@ -85,7 +85,7 @@ public class InfocenterWorkingSetManagerTest {
assertEquals(1, readWsets.length);
AdaptableHelpResource[] resources = readWsets[0].getElements();
assertEquals(1, resources.length);
- Set<AdaptableTopic> topics = new HashSet<AdaptableTopic>();
+ Set<AdaptableTopic> topics = new HashSet<>();
topics.add(topic1);
assertTrue(topics.contains(resources[0]));
checkCookies(resp);
@@ -107,7 +107,7 @@ public class InfocenterWorkingSetManagerTest {
assertEquals(1, readWsets.length);
AdaptableHelpResource[] resources = readWsets[0].getElements();
assertEquals(2, resources.length);
- Set<AdaptableTopic> topics = new HashSet<AdaptableTopic>();
+ Set<AdaptableTopic> topics = new HashSet<>();
topics.add(topic1);
topics.add(topic3);
assertTrue(topics.contains(resources[0]));
@@ -134,7 +134,7 @@ public class InfocenterWorkingSetManagerTest {
assertEquals(1, readWsets.length);
AdaptableHelpResource[] resources = readWsets[0].getElements();
assertEquals(3, resources.length);
- Set<AdaptableTopic> topics = new HashSet<AdaptableTopic>();
+ Set<AdaptableTopic> topics = new HashSet<>();
topics.add(topic1);
topics.add(topic3);
topics.add(topic5);
@@ -164,7 +164,7 @@ public class InfocenterWorkingSetManagerTest {
assertEquals(1, readWsets.length);
AdaptableHelpResource[] resources = readWsets[0].getElements();
assertEquals(1, resources.length);
- Set<AdaptableTopic> topics = new HashSet<AdaptableTopic>();
+ Set<AdaptableTopic> topics = new HashSet<>();
topics.add(topic1);
assertTrue(topics.contains(resources[0]));
checkCookies(resp);
@@ -192,7 +192,7 @@ public class InfocenterWorkingSetManagerTest {
assertEquals(1, readWsets.length);
AdaptableHelpResource[] resources = readWsets[0].getElements();
assertEquals(2, resources.length);
- Set<AdaptableTopic> topics = new HashSet<AdaptableTopic>();
+ Set<AdaptableTopic> topics = new HashSet<>();
topics.add(topic1);
topics.add(topic3);
assertTrue(topics.contains(resources[0]));
@@ -224,7 +224,7 @@ public class InfocenterWorkingSetManagerTest {
assertEquals(1, readWsets.length);
AdaptableHelpResource[] resources = readWsets[0].getElements();
assertEquals(3, resources.length);
- Set<AdaptableTopic> topics = new HashSet<AdaptableTopic>();
+ Set<AdaptableTopic> topics = new HashSet<>();
topics.add(topic1);
topics.add(topic3);
topics.add(topic5);
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipant.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipant.java
index b99c4dd4d..2036ad113 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipant.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation and others.
+ * Copyright (c) 2010, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -28,7 +28,7 @@ public class MockSearchParticipant extends SearchParticipant {
@Override
public Set<String> getAllDocuments(String locale) {
- HashSet<String> set = new HashSet<String>();
+ HashSet<String> set = new HashSet<>();
set.add(DOC_1);
set.add(DOC_2);
return set;
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipantXML.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipantXML.java
index 353425744..2ee12a821 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipantXML.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipantXML.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation and others.
+ * Copyright (c) 2010, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,7 +24,7 @@ public class MockSearchParticipantXML extends SearchParticipantXML {
@Override
public Set<String> getAllDocuments(String locale) {
- HashSet<String> set = new HashSet<String>();
+ HashSet<String> set = new HashSet<>();
set.add(DOC_1 + "?id=xml1" + "?id=xml2");
set.add(DOC_2);
return set;
@@ -32,7 +32,7 @@ public class MockSearchParticipantXML extends SearchParticipantXML {
@Override
public Set<String> getContributingPlugins() {
- Set<String> result = new HashSet<String>();
+ Set<String> result = new HashSet<>();
result.add("org.eclipse.ua.tests");
return result;
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java
index 6082293ab..37f5b1025 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java
@@ -156,21 +156,10 @@ public class PrebuiltIndexCompatibility {
String filePath = resolved.getFile();
QueryBuilder queryBuilder = new QueryBuilder("eclipse", new AnalyzerDescriptor("en-us"));
Query luceneQuery = queryBuilder.getLuceneQuery(new ArrayList<String>() , false);
- Directory luceneDirectory = null;
- IndexSearcher searcher = null;
- try {
- luceneDirectory = new NIOFSDirectory(new File(filePath));
- searcher = new IndexSearcher(IndexReader.open(luceneDirectory, true));
+ try (Directory luceneDirectory = new NIOFSDirectory(new File(filePath));
+ IndexSearcher searcher = new IndexSearcher(IndexReader.open(luceneDirectory, true))) {
TopDocs hits = searcher.search(luceneQuery, 500);
assertEquals(hits.totalHits, 1);
- } finally {
- if (luceneDirectory != null)
- try {
- luceneDirectory.close();
- } catch (IOException x) {
- }
- if (searcher != null)
- searcher.close();
}
} else {
fail("Cannot resolve to file protocol");
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchTestUtils.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchTestUtils.java
index a4b22a4dd..6e335ce99 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchTestUtils.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchTestUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 IBM Corporation and others.
+ * Copyright (c) 2008, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,15 +17,13 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import org.junit.Assert;
-
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.search.ISearchQuery;
import org.eclipse.help.internal.search.SearchHit;
import org.eclipse.help.internal.search.SearchQuery;
import org.eclipse.help.internal.search.SearchResults;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
+import org.junit.Assert;
public class SearchTestUtils {
@@ -47,8 +45,8 @@ public class SearchTestUtils {
*/
public static String searchForExpectedResults(String searchWord,
String[] hrefs, String nl) {
- final Set<String> hrefsToFind = new HashSet<String>();
- final Set<String> unexpectedHrefs = new HashSet<String>();
+ final Set<String> hrefsToFind = new HashSet<>();
+ final Set<String> unexpectedHrefs = new HashSet<>();
hrefsToFind.addAll(Arrays.asList(hrefs));
SearchHit[] hits;
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/WorkingSetManagerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/WorkingSetManagerTest.java
index 52e540c08..ceba00373 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/WorkingSetManagerTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/WorkingSetManagerTest.java
@@ -224,7 +224,7 @@ public class WorkingSetManagerTest {
private void createWsetWithAllTocs(WorkingSetManager mgr, String name) {
WorkingSet wset = new WorkingSet(name);
- List<AdaptableToc> tocList = new ArrayList<AdaptableToc>();
+ List<AdaptableToc> tocList = new ArrayList<>();
Toc[] tocs = HelpPlugin.getTocManager().getTocs(Platform.getNL());
for (Toc toc : tocs) {
tocList.add(mgr.getAdaptableToc(toc.getHref()));
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/EnabledTopicTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/EnabledTopicTest.java
index b582fd3f9..7625eaa20 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/EnabledTopicTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/EnabledTopicTest.java
@@ -31,7 +31,7 @@ public class EnabledTopicTest {
private String label;
private boolean isEnabled;
- private List<ITopic> children = new ArrayList<ITopic>();
+ private List<ITopic> children = new ArrayList<>();
public ETopic(String label, boolean isEnabled) {
this.label = label;
@@ -85,8 +85,8 @@ public class EnabledTopicTest {
private class EIndexEntry extends UAElement implements IIndexEntry {
private String keyword;
- private List<ITopic> topics = new ArrayList<ITopic>();
- private List<IIndexEntry> subEntries = new ArrayList<IIndexEntry>();
+ private List<ITopic> topics = new ArrayList<>();
+ private List<IIndexEntry> subEntries = new ArrayList<>();
public EIndexEntry(String keyword) {
super(keyword);
@@ -118,7 +118,7 @@ public class EnabledTopicTest {
@Override
public synchronized IUAElement[] getChildren() {
- List<IUAElement> all = new ArrayList<IUAElement>();
+ List<IUAElement> all = new ArrayList<>();
all.addAll(subEntries);
all.addAll(topics);
return all.toArray(new IUAElement[all.size()]);
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java
index 2b772955d..bae441051 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java
@@ -38,7 +38,7 @@ public class TocAssemblerTest {
TocContribution result_b_c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/result_b_c.xml", true, "en", null, null));
TocAssembler assembler = new TocAssembler();
- List<TocContribution> contributions = new ArrayList<TocContribution>(Arrays.asList(b, c));
+ List<TocContribution> contributions = new ArrayList<>(Arrays.asList(b, c));
contributions = assembler.assemble(contributions);
assertEquals(1, contributions.size());
String expected = serialize(result_b_c);
@@ -51,7 +51,7 @@ public class TocAssemblerTest {
TocContribution d = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/d.xml", false, "en", null, null));
TocContribution result_a_b_c_d = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/result_a_b_c_d.xml", true, "en", null, null));
- contributions = new ArrayList<TocContribution>(Arrays.asList(a, b, c, d));
+ contributions = new ArrayList<>(Arrays.asList(a, b, c, d));
contributions = assembler.assemble(contributions);
assertEquals(1, contributions.size());
@@ -68,7 +68,7 @@ public class TocAssemblerTest {
TocContribution linkTo3 = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/linkTo3.xml", true, "en", null, null));
TocAssembler assembler = new TocAssembler();
- List<TocContribution> contributions = new ArrayList<TocContribution>(Arrays.asList(linkTo1, linkTo2, linkTo3));
+ List<TocContribution> contributions = new ArrayList<>(Arrays.asList(linkTo1, linkTo2, linkTo3));
contributions = assembler.assemble(contributions);
assertEquals(3, contributions.size());
}
@@ -79,7 +79,7 @@ public class TocAssemblerTest {
TocContribution b = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/b.xml", true, "en", null, null));
TocContribution c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/c.xml", true, "en", null, null));
TocAssembler assembler = new TocAssembler();
- List<TocContribution> contributions = new ArrayList<TocContribution>(Arrays.asList(b, c));
+ List<TocContribution> contributions = new ArrayList<>(Arrays.asList(b, c));
contributions = assembler.assemble(contributions);
IToc toc =contributions.get(0).getToc();
assertNotNull(toc.getTopic("/org.eclipse.ua.tests/B_topic3.html"));
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/LoadServletUtil.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/LoadServletUtil.java
index 01c1cb2a6..176934a43 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/LoadServletUtil.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/LoadServletUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,11 +15,9 @@ import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
-import org.junit.Assert;
-
-import org.eclipse.help.internal.server.WebappManager;
-
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.help.internal.server.WebappManager;
+import org.junit.Assert;
public class LoadServletUtil {
@@ -35,10 +33,10 @@ public class LoadServletUtil {
URL url = new URL("http", "localhost", port, "/help/index.jsp");
URLConnection connection = url.openConnection();
setTimeout(connection, 5000);
- InputStream input = url.openStream();
- int firstbyte = input.read();
- input.close();
- Assert.assertTrue(firstbyte > 0);
+ try (InputStream input = url.openStream()) {
+ int firstbyte = input.read();
+ Assert.assertTrue(firstbyte > 0);
+ }
}
/**
@@ -60,24 +58,25 @@ public class LoadServletUtil {
++uniqueParam;
URL url = new URL("http", "localhost", port,
"/help/loadtest?value=" + uniqueParam + "&repeat=" + paragraphs);
- InputStream input = url.openStream();
- int nextChar;
- long value = 0;
- // The loadtest servlet returns the uniqueParam in an opening comment such as <!--1234-->
- // Read this to verify that we are not getting a cached page
- boolean inFirstComment = true;
- do {
- nextChar = input.read();
- if (inFirstComment) {
- if (nextChar == '>') {
- inFirstComment = false;
- } else if (Character.isDigit((char) nextChar)) {
- value = value * 10 + (nextChar - '0');
- }
- }
- } while (nextChar != '$');
- Assert.assertEquals(uniqueParam, value);
- input.close();
+ try (InputStream input = url.openStream()) {
+ int nextChar;
+ long value = 0;
+ // The loadtest servlet returns the uniqueParam in an opening
+ // comment such as <!--1234-->
+ // Read this to verify that we are not getting a cached page
+ boolean inFirstComment = true;
+ do {
+ nextChar = input.read();
+ if (inFirstComment) {
+ if (nextChar == '>') {
+ inFirstComment = false;
+ } else if (Character.isDigit((char) nextChar)) {
+ value = value * 10 + (nextChar - '0');
+ }
+ }
+ } while (nextChar != '$');
+ Assert.assertEquals(uniqueParam, value);
+ }
}
private static void setTimeout(URLConnection conn, int milliseconds) {
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ProducerSerializerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ProducerSerializerTest.java
index b16462789..2651042e6 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ProducerSerializerTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ProducerSerializerTest.java
@@ -55,11 +55,11 @@ public class ProducerSerializerTest {
String absolutePath = pluginRoot + relativePath;
String resultFile = FileUtil.getResultFile(absolutePath);
- PrintWriter out = new PrintWriter(new FileOutputStream(resultFile));
- String output = FileUtil.readString(HelpSystem.getHelpContent(href));
- output = XHTMLUtil.removeEnvironmentSpecificContent(output);
- out.print(output);
- out.close();
+ try (PrintWriter out = new PrintWriter(new FileOutputStream(resultFile))) {
+ String output = FileUtil.readString(HelpSystem.getHelpContent(href));
+ output = XHTMLUtil.removeEnvironmentSpecificContent(output);
+ out.print(output);
+ }
}
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/TocModelSerializerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/TocModelSerializerTest.java
index 51b15db3c..3f1471af7 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/TocModelSerializerTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/TocModelSerializerTest.java
@@ -81,7 +81,7 @@ public class TocModelSerializerTest {
* Find all the TOC files to use for this test.
*/
public static Collection<TocFile> getTocFiles() {
- Collection<TocFile> tocFiles = new ArrayList<TocFile>();
+ Collection<TocFile> tocFiles = new ArrayList<>();
IExtensionPoint xpt = Platform.getExtensionRegistry().getExtensionPoint(HelpPlugin.PLUGIN_ID, "toc");
IExtension[] extensions = xpt.getExtensions();
for (IExtension extension : extensions) {
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java
index eeec010fb..6d4eed6e4 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java
@@ -169,10 +169,8 @@ public class ChildLinkInsertion {
private void checkFilter(final String input, final String expected) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- OutputStream filteredOutput = new TestableReplacementStream(output, null, "../");
- try {
+ try (OutputStream filteredOutput = new TestableReplacementStream(output, null, "../")) {
filteredOutput.write(input.getBytes());
- filteredOutput.close();
} catch (IOException e) {
fail("IO Exception");
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java
index d9c7ae8da..9260ab232 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java
@@ -41,9 +41,9 @@ public class FilterExtensionTest {
ExtraFilters.setFilters(filters);
OutputStream out = new ByteArrayOutputStream(1000);
MockServletRequest req = new MockServletRequest();
- OutputStream filteredOutput = new ExtraFilters().filter(req, out);
- filteredOutput.write("<html>".getBytes());
- filteredOutput.close();
+ try (OutputStream filteredOutput = new ExtraFilters().filter(req, out)) {
+ filteredOutput.write("<html>".getBytes());
+ }
String result = out.toString();
String expected = "<!-- pre 3 --><!-- pre 2 --><!-- pre 1 --><html>"
+ "<!-- post 1 --><!-- post 2 --><!-- post 3 -->";
@@ -59,9 +59,9 @@ public class FilterExtensionTest {
ExtraFilters.setFilters(filters);
OutputStream out = new ByteArrayOutputStream(1000);
MockServletRequest req = new MockServletRequest();
- OutputStream filteredOutput = new ExtraFilters().filter(req, out);
- filteredOutput.write("<html>".getBytes());
- filteredOutput.close();
+ try (OutputStream filteredOutput = new ExtraFilters().filter(req, out)) {
+ filteredOutput.write("<html>".getBytes());
+ }
String result = out.toString();
String expected = "<!-- pre 3 --><!-- pre 2 --><!-- pre 2 --><html>"
+ "<!-- post 2 --><!-- post 2 --><!-- post 3 -->";
@@ -74,9 +74,9 @@ public class FilterExtensionTest {
ExtraFilters.setFilters(filters);
OutputStream out = new ByteArrayOutputStream(1000);
MockServletRequest req = new MockServletRequest();
- OutputStream filteredOutput = new ExtraFilters().filter(req, out);
- filteredOutput.write("<html>".getBytes());
- filteredOutput.close();
+ try (OutputStream filteredOutput = new ExtraFilters().filter(req, out)) {
+ filteredOutput.write("<html>".getBytes());
+ }
String result = out.toString();
String expected = "<html>";
assertEquals(expected, result);
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java
index d7a1b3a18..aef5b9879 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java
@@ -53,8 +53,7 @@ public class FilterTest {
@Test
public void testHeadOutputFilter() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- OutputStream filteredOutput = new FilterHTMLHeadOutputStream(output, CSS2.getBytes());
- try {
+ try (OutputStream filteredOutput = new FilterHTMLHeadOutputStream(output, CSS2.getBytes())) {
filteredOutput.write(HTML40.getBytes());
filteredOutput.write(HEAD1.getBytes());
filteredOutput.write(CSS1.getBytes());
@@ -73,8 +72,8 @@ public class FilterTest {
@Test
public void testHeadAndBodyOutputFilter() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS2.getBytes(), CONTENT2);
- try {
+ try (FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output,
+ CSS2.getBytes(), CONTENT2)) {
filteredOutput.write(HTML40.getBytes());
filteredOutput.write(HEAD1.getBytes());
filteredOutput.write(CONTENT_TYPE_ISO_8859_1.getBytes());
@@ -94,8 +93,7 @@ public class FilterTest {
@Test
public void testLowerCaseTags() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- OutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS1.getBytes(), CONTENT2);
- try {
+ try (OutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS1.getBytes(), CONTENT2)) {
filteredOutput.write(HTML40.getBytes());
filteredOutput.write(HEADLC1.getBytes());
filteredOutput.write(HEADLC2.getBytes());
@@ -113,8 +111,7 @@ public class FilterTest {
@Test
public void testFilterHeadlessDocument() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- OutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS1.getBytes(), CONTENT2);
- try {
+ try (OutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS1.getBytes(), CONTENT2)) {
filteredOutput.write(HTML40.getBytes());
filteredOutput.write(BODY1.getBytes());
filteredOutput.write(CONTENT1.getBytes());
@@ -130,8 +127,8 @@ public class FilterTest {
@Test
public void testInsertChineseUtf8() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null, CHINESE_CONTENT);
- try {
+ try (FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null,
+ CHINESE_CONTENT)) {
filteredOutput.write(HTML40.getBytes());
filteredOutput.write(HEAD1.getBytes());
filteredOutput.write(CONTENT_TYPE_UTF8.getBytes());
@@ -149,8 +146,8 @@ public class FilterTest {
@Test
public void testInsertChineseISO8859() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null, CHINESE_CONTENT);
- try {
+ try (FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null,
+ CHINESE_CONTENT)) {
filteredOutput.write(HTML40.getBytes());
filteredOutput.write(HEAD1.getBytes());
filteredOutput.write(CONTENT_TYPE_ISO_8859_1.getBytes());
@@ -168,8 +165,8 @@ public class FilterTest {
@Test
public void testInsertChineseNoCharsetSpecified() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null, CHINESE_CONTENT);
- try {
+ try (FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null,
+ CHINESE_CONTENT)) {
filteredOutput.write(HTML40.getBytes());
filteredOutput.write(HEAD1.getBytes());
filteredOutput.write(HEAD2.getBytes());
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletRequest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletRequest.java
index 4a19f407b..7776ed3d1 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletRequest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletRequest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 IBM Corporation and others.
+ * Copyright (c) 2008, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -43,7 +43,7 @@ import javax.servlet.http.Part;
public class MockServletRequest implements HttpServletRequest {
private Locale locale;
- private Map<String, String[]> parameterMap = new HashMap<String, String[]>();
+ private Map<String, String[]> parameterMap = new HashMap<>();
private Cookie[] cookies = new Cookie[0];
private String pathInfo = null;
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletResponse.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletResponse.java
index 480976540..bac836225 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletResponse.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/MockServletResponse.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 IBM Corporation and others.
+ * Copyright (c) 2008, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -28,7 +28,7 @@ import javax.servlet.http.HttpServletResponse;
public class MockServletResponse implements HttpServletResponse {
- private List<Cookie> cookies = new ArrayList<Cookie>();
+ private List<Cookie> cookies = new ArrayList<>();
private String illegalCharactersFound = "";
@Override
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java
index f2414ee09..a189616d5 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java
@@ -119,23 +119,24 @@ public class ParallelServerAccessTest {
long uniqueId = getReadOperations();
URL url = new URL("http", "localhost", port,
"/help/loadtest?value=" + uniqueId + "&repeat=" + paragraphs);
- InputStream input = url.openStream();
- int nextChar;
long value = 0;
- // The loadtest servlet returns the uniqueParam in an opening comment such as <!--1234-->
- // Read this to verify that we are not getting a cached page
- boolean inFirstComment = true;
- do {
- nextChar = input.read();
- if (inFirstComment) {
- if (nextChar == '>') {
- inFirstComment = false;
- } else if (Character.isDigit((char) nextChar)) {
- value = value * 10 + (nextChar - '0');
- }
- }
- } while (nextChar != '$');
- input.close();
+ try (InputStream input = url.openStream()) {
+ int nextChar;
+ // The loadtest servlet returns the uniqueParam in an opening
+ // comment such as <!--1234-->
+ // Read this to verify that we are not getting a cached page
+ boolean inFirstComment = true;
+ do {
+ nextChar = input.read();
+ if (inFirstComment) {
+ if (nextChar == '>') {
+ inFirstComment = false;
+ } else if (Character.isDigit((char) nextChar)) {
+ value = value * 10 + (nextChar - '0');
+ }
+ }
+ } while (nextChar != '$');
+ }
if (uniqueId != value) {
throw new UnexpectedValueException(uniqueId, value);
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java
index d7bffd9c5..cf265c532 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java
@@ -84,10 +84,8 @@ public class PluginsRootReplacement {
private void checkFilter(final String input, final String expected) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- OutputStream filteredOutput = new PluginsRootResolvingStream(output, null, "../");
- try {
+ try (OutputStream filteredOutput = new PluginsRootResolvingStream(output, null, "../")) {
filteredOutput.write(input.getBytes());
- filteredOutput.close();
} catch (IOException e) {
fail("IO Exception");
}
@@ -162,16 +160,14 @@ public class PluginsRootReplacement {
URL testURL = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(),
"/data/help/performance/search/" + filename);
assertNotNull(testURL);
- InputStream input = testURL.openStream();
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- while (input.available() > 0) {
- int next = input.read();
- output.write(next);
+ try (InputStream input = testURL.openStream(); ByteArrayOutputStream output = new ByteArrayOutputStream()) {
+ while (input.available() > 0) {
+ int next = input.read();
+ output.write(next);
+ }
+ String data = output.toString();
+ checkFilter(data, data);
}
- String data = output.toString();
- checkFilter(data, data);
- input.close();
- output.close();
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java
index 0f9b57fe1..fa63e824d 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java
@@ -59,17 +59,16 @@ public class TocZipTest {
IOException {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/topic" + path);
- InputStream is = url.openStream();
- BufferedInputStream buffered = new BufferedInputStream(is);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- int result = buffered.read();
- while(result != -1) {
- os.write(result);
- result = buffered.read();
- }
- buffered.close();
- os.close();
- return os.toString();
+ try (InputStream is = url.openStream();
+ BufferedInputStream buffered = new BufferedInputStream(is);
+ ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+ int result = buffered.read();
+ while (result != -1) {
+ os.write(result);
+ result = buffered.read();
+ }
+ return os.toString();
+ }
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java
index a392ba7ba..826810952 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java
@@ -124,7 +124,7 @@ public class ExtensionServiceTest {
private Element[] findChildren(Node parent, String childKind,
String attributeName, String attributeValue) {
NodeList contributions = parent.getChildNodes();
- List<Node> results = new ArrayList<Node>();
+ List<Node> results = new ArrayList<>();
for (int i = 0; i < contributions.getLength(); i++) {
Node next = contributions.item(i);
if (next instanceof Element) {
@@ -142,15 +142,15 @@ public class ExtensionServiceTest {
throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/vs/service/extension?lang=" + locale);
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("contentExtensions", root.getNodeName());
- return root;
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ assertEquals("contentExtensions", root.getNodeName());
+ return root;
+ }
}
@Test
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java
index a3f2f9709..45460db90 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java
@@ -59,14 +59,14 @@ public class IndexFragmentServiceTest {
throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/vs/service/indexfragment?lang=" + locale);
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("tree_data", root.getNodeName());
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ assertEquals("tree_data", root.getNodeName());
+ }
}
@Test
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexServiceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexServiceTest.java
index 1a44ae15d..2be1ee932 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexServiceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexServiceTest.java
@@ -33,15 +33,15 @@ public class IndexServiceTest extends IndexServletTest {
throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/vs/service/index?lang=" + locale);
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("indexContributions", root.getNodeName());
- return root;
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ assertEquals("indexContributions", root.getNodeName());
+ return root;
+ }
}
@Test
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java
index 4f601e86a..d22b362b6 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java
@@ -150,7 +150,7 @@ public class TocFragmentServiceTest {
private Element[] findChildren(Node parent, String childKind,
String attributeName, String attributeValue) {
NodeList nodes = parent.getChildNodes();
- List<Node> results = new ArrayList<Node>();
+ List<Node> results = new ArrayList<>();
for (int i = 0; i < nodes.getLength(); i++) {
Node next = nodes.item(i);
if (next instanceof Element) {
@@ -171,7 +171,7 @@ public class TocFragmentServiceTest {
private Element[] findHref(Node parent, String childKind,
String attributeValue) {
NodeList nodes = parent.getChildNodes();
- List<Node> results = new ArrayList<Node>();
+ List<Node> results = new ArrayList<>();
for (int i = 0; i < nodes.getLength(); i++) {
Node next = nodes.item(i);
if (next instanceof Element) {
@@ -196,15 +196,15 @@ public class TocFragmentServiceTest {
private Node getTreeData(URL url)
throws Exception {
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("tree_data", root.getNodeName());
- return root;
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ assertEquals("tree_data", root.getNodeName());
+ return root;
+ }
}
@Test
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocServiceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocServiceTest.java
index 84458b2fd..7f0c5009c 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocServiceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocServiceTest.java
@@ -33,15 +33,15 @@ public class TocServiceTest extends TocServletTest {
throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/vs/service/toc?lang=" + locale);
- InputStream is = url.openStream();
- InputSource inputSource = new InputSource(is);
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- documentBuilder.setEntityResolver(new LocalEntityResolver());
- Document document = documentBuilder.parse(inputSource);
- Node root = document.getFirstChild();
- is.close();
- assertEquals("tocContributions", root.getNodeName());
- return root;
+ try (InputStream is = url.openStream()) {
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ assertEquals("tocContributions", root.getNodeName());
+ return root;
+ }
}
/*
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webextension/TitleSearchData.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webextension/TitleSearchData.java
index ca17e18d2..9055c11ce 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webextension/TitleSearchData.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webextension/TitleSearchData.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -38,16 +38,16 @@ public class SearchResult {
}
public SearchResult[] getSearchResults() {
- results = new ArrayList<SearchResult>();
- searchTerm = request.getParameter("searchWord");
- IToc[] tocs = getTocs();
- for (IToc toc : tocs) {
- ITopic[] topics = toc.getTopics();
- for (ITopic topic : topics) {
- searchTopic(topic);
- }
- }
- return results.toArray(new SearchResult[results.size()]);
+ results = new ArrayList<>();
+ searchTerm = request.getParameter("searchWord");
+ IToc[] tocs = getTocs();
+ for (IToc toc : tocs) {
+ ITopic[] topics = toc.getTopics();
+ for (ITopic topic : topics) {
+ searchTopic(topic);
+ }
+ }
+ return results.toArray(new SearchResult[results.size()]);
}
private void searchTopic(ITopic topic) {

Back to the top