Skip to content

Commit

Permalink
simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Feb 19, 2023
1 parent eae5a76 commit f049d5b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Objects;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HeaderIterator;
Expand Down Expand Up @@ -470,13 +472,7 @@ public void setLocale(Locale loc) {
};
}

protected String readFileToString(String fileName) {
try {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(Objects.requireNonNull(classLoader.getResource("__files/" + fileName)).getFile());
return FileUtils.readFileToString(file, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
protected String readFileToString(String fileName) throws IOException {
return IOUtils.resourceToString("__files/" + fileName, StandardCharsets.UTF_8, getClass().getClassLoader());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.eclipse.rdf4j.http.protocol.Protocol;
import org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat;
import org.eclipse.rdf4j.repository.RepositoryException;
Expand Down Expand Up @@ -47,7 +49,7 @@ public void setUp(MockServerClient client) {
}

@Test
public void testAddRepositoryConfig(MockServerClient client) {
public void testAddRepositoryConfig(MockServerClient client) throws Exception {
client.when(
request()
.withMethod("GET")
Expand Down Expand Up @@ -176,7 +178,7 @@ public void testGetRepositoryConfig(MockServerClient client) throws Exception {
}

@Test
public void testAddRepositoryConfigLegacy(MockServerClient client) {
public void testAddRepositoryConfigLegacy(MockServerClient client) throws Exception {
client.when(
request()
.withMethod("GET")
Expand Down Expand Up @@ -214,13 +216,7 @@ public void testAddRepositoryConfigLegacy(MockServerClient client) {
assertThrows(RepositoryException.class, () -> subject.addRepositoryConfig(config));
}

private String readFileToString(String fileName) {
try {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(Objects.requireNonNull(classLoader.getResource("__files/" + fileName)).getFile());
return FileUtils.readFileToString(file, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
private String readFileToString(String fileName) throws IOException {
return IOUtils.resourceToString("__files/" + fileName, StandardCharsets.UTF_8, getClass().getClassLoader());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.spring.support.ConfigurationException;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -38,7 +40,7 @@ class RemoteRepositoryConfigTest {
private final RemoteRepositoryConfig remoteRepositoryConfig = new RemoteRepositoryConfig();

@BeforeEach
void setUp(MockServerClient client) {
void setUp(MockServerClient client) throws Exception {
client.when(
request()
.withMethod("GET")
Expand Down Expand Up @@ -108,13 +110,7 @@ void getRemoteRepository_error() {
.isThrownBy(() -> remoteRepositoryConfig.getRemoteRepository(properties));
}

private String readFileToString(String fileName) {
try {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(Objects.requireNonNull(classLoader.getResource("__files/" + fileName)).getFile());
return FileUtils.readFileToString(file, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
private String readFileToString(String fileName) throws IOException {
return IOUtils.resourceToString("__files/" + fileName, StandardCharsets.UTF_8, getClass().getClassLoader());
}
}

0 comments on commit f049d5b

Please sign in to comment.