remove unused shiro rule and fixed some deprecated method calls

This commit is contained in:
Sebastian Sdorra
2019-02-01 09:44:25 +01:00
parent 0a29f41835
commit c249d603d7

View File

@@ -2,8 +2,6 @@ package sonia.scm.web.i18n;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.sdorra.shiro.ShiroRule;
import com.github.sdorra.shiro.SubjectAware;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.io.Files; import com.google.common.io.Files;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -42,12 +40,8 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.Silent.class) @RunWith(MockitoJUnitRunner.Silent.class)
@SubjectAware(configuration = "classpath:sonia/scm/shiro-001.ini")
public class I18nServletTest { public class I18nServletTest {
@Rule
public ShiroRule shiro = new ShiroRule();
private static final String GIT_PLUGIN_JSON = json( private static final String GIT_PLUGIN_JSON = json(
"{", "{",
"'scm-git-plugin': {", "'scm-git-plugin': {",
@@ -88,15 +82,15 @@ public class I18nServletTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Mock @Mock
PluginLoader pluginLoader; private PluginLoader pluginLoader;
@Mock @Mock
CacheManager cacheManager; private CacheManager cacheManager;
@Mock @Mock
ClassLoader classLoader; private ClassLoader classLoader;
I18nServlet servlet; private I18nServlet servlet;
@Mock @Mock
private Cache cache; private Cache cache;
@@ -106,9 +100,9 @@ public class I18nServletTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void init() throws IOException { public void init() throws IOException {
resources = Collections.enumeration(Lists.newArrayList( resources = Collections.enumeration(Lists.newArrayList(
createFileFromString(SVN_PLUGIN_JSON).toURL(), createFileFromString(SVN_PLUGIN_JSON).toURI().toURL(),
createFileFromString(GIT_PLUGIN_JSON).toURL(), createFileFromString(GIT_PLUGIN_JSON).toURI().toURL(),
createFileFromString(HG_PLUGIN_JSON).toURL() createFileFromString(HG_PLUGIN_JSON).toURI().toURL()
)); ));
when(pluginLoader.getUberClassLoader()).thenReturn(classLoader); when(pluginLoader.getUberClassLoader()).thenReturn(classLoader);
when(cacheManager.getCache(I18nServlet.CACHE_NAME)).thenReturn(cache); when(cacheManager.getCache(I18nServlet.CACHE_NAME)).thenReturn(cache);
@@ -247,7 +241,7 @@ public class I18nServletTest {
assertJson(actual.toString()); assertJson(actual.toString());
} }
public void assertJson(String actual) throws IOException { private void assertJson(String actual) throws IOException {
assertThat(actual) assertThat(actual)
.isNotEmpty() .isNotEmpty()
.contains(StringUtils.deleteWhitespace(GIT_PLUGIN_JSON.substring(1, GIT_PLUGIN_JSON.length() - 1))) .contains(StringUtils.deleteWhitespace(GIT_PLUGIN_JSON.substring(1, GIT_PLUGIN_JSON.length() - 1)))
@@ -255,7 +249,7 @@ public class I18nServletTest {
.contains(StringUtils.deleteWhitespace(SVN_PLUGIN_JSON.substring(1, SVN_PLUGIN_JSON.length() - 1))); .contains(StringUtils.deleteWhitespace(SVN_PLUGIN_JSON.substring(1, SVN_PLUGIN_JSON.length() - 1)));
} }
public File createFileFromString(String json) throws IOException { private File createFileFromString(String json) throws IOException {
File file = temporaryFolder.newFile(); File file = temporaryFolder.newFile();
Files.write(json.getBytes(Charsets.UTF_8), file); Files.write(json.getBytes(Charsets.UTF_8), file);
return file; return file;