From 065b6e496fb9e674de3a2acec971c74e10d612b5 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Thu, 14 Jul 2011 20:02:47 +0100 Subject: [PATCH] Don't use the real Briar directory for unit tests. --- api/net/sf/briar/api/i18n/I18n.java | 5 ++++- components/net/sf/briar/i18n/I18nImpl.java | 13 ++++++------- test/net/sf/briar/i18n/I18nTest.java | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/api/net/sf/briar/api/i18n/I18n.java b/api/net/sf/briar/api/i18n/I18n.java index c1930e5678..ef8290c427 100644 --- a/api/net/sf/briar/api/i18n/I18n.java +++ b/api/net/sf/briar/api/i18n/I18n.java @@ -23,8 +23,11 @@ public interface I18n { /** Saves the i18n locale to Briar/Data/locale.cfg. */ void saveLocale() throws IOException; + /** Loads the i18n locale from the given file. */ + void loadLocale(File f) throws IOException; + /** Saves the i18n locale to the given file. */ - void saveLocale(File dir) throws IOException; + void saveLocale(File f) throws IOException; /** Returns the ComponentOrientation of the current i18n locale. */ ComponentOrientation getComponentOrientation(); diff --git a/components/net/sf/briar/i18n/I18nImpl.java b/components/net/sf/briar/i18n/I18nImpl.java index c1c9aafced..106b3032fb 100644 --- a/components/net/sf/briar/i18n/I18nImpl.java +++ b/components/net/sf/briar/i18n/I18nImpl.java @@ -122,22 +122,21 @@ public class I18nImpl implements I18n { } public void loadLocale() throws IOException { - loadLocale(FileUtils.getBriarDirectory()); + loadLocale(new File(FileUtils.getBriarDirectory(), "Data/locale.cfg")); } - public void loadLocale(File dir) throws IOException { - Scanner s = new Scanner(new File(dir, "Data/locale.cfg")); + public void loadLocale(File f) throws IOException { + Scanner s = new Scanner(f); if(s.hasNextLine()) setLocale(new Locale(s.nextLine())); s.close(); } public void saveLocale() throws IOException { - saveLocale(FileUtils.getBriarDirectory()); + saveLocale(new File(FileUtils.getBriarDirectory(), "Data/locale.cfg")); } - public void saveLocale(File dir) throws IOException { - File localeCfg = new File(dir, "Data/locale.cfg"); - FileOutputStream out = new FileOutputStream(localeCfg); + public void saveLocale(File f) throws IOException { + FileOutputStream out = new FileOutputStream(f); PrintStream print = new PrintStream(out); print.println(locale); print.flush(); diff --git a/test/net/sf/briar/i18n/I18nTest.java b/test/net/sf/briar/i18n/I18nTest.java index 1b0cd5e18f..f6be63182e 100644 --- a/test/net/sf/briar/i18n/I18nTest.java +++ b/test/net/sf/briar/i18n/I18nTest.java @@ -46,7 +46,7 @@ public class I18nTest extends TestCase { assertEquals("foo", i18n.tr("FOO")); i18n.setLocale(Locale.FRANCE); assertEquals("le foo", i18n.tr("FOO")); - i18n.setLocale(Locale.CHINA); // No translation - use defaul + i18n.setLocale(Locale.CHINA); // No translation - use default assertEquals("foo", i18n.tr("FOO")); } @@ -83,13 +83,13 @@ public class I18nTest extends TestCase { @Test public void testSaveAndLoadLocale() throws IOException { testDir.mkdirs(); - new File(testDir, "Data").mkdir(); + File f = new File(testDir, "locale.cfg"); i18n.setLocale(new Locale("fr")); assertEquals("le foo", i18n.tr("FOO")); - i18n.saveLocale(); + i18n.saveLocale(f); i18n.setLocale(new Locale("zh")); // No translation - use default assertEquals("foo", i18n.tr("FOO")); - i18n.loadLocale(); + i18n.loadLocale(f); assertEquals("le foo", i18n.tr("FOO")); } -- GitLab