Javadocs and unit tests.

This commit is contained in:
akwizgran
2011-07-01 12:07:00 +01:00
parent b29a024c2a
commit 0ed2a7c9e7
23 changed files with 235 additions and 59 deletions

View File

@@ -1,7 +1,7 @@
<project name='test' default='test'>
<import file='../build-common.xml'/>
<target name='test' depends='depend'>
<junit printsummary='on'>
<junit printsummary='on' showoutput='true'>
<classpath>
<fileset refid='bundled-jars'/>
<fileset refid='test-jars'/>
@@ -10,6 +10,8 @@
<path refid='test-classes'/>
<path refid='util-classes'/>
</classpath>
<test name='net.sf.briar.i18n.FontManagerImplTest'/>
<test name='net.sf.briar.invitation.InvitationWorkerTest'/>
<test name='net.sf.briar.setup.SetupWorkerTest'/>
<test name='net.sf.briar.util.FileUtilsTest'/>
<test name='net.sf.briar.util.StringUtilsTest'/>

View File

@@ -11,7 +11,7 @@ public class TestUtils {
private static final AtomicInteger nextTestDir =
new AtomicInteger((int) (Math.random() * 1000 * 1000));
public static void delete(File f) throws IOException {
public static void delete(File f) {
if(f.isDirectory()) for(File child : f.listFiles()) delete(child);
f.delete();
}
@@ -29,4 +29,8 @@ public class TestUtils {
File testDir = new File("test.tmp/" + name);
return testDir;
}
public static void deleteTestDirectories() {
delete(new File("test.tmp"));
}
}

View File

@@ -0,0 +1,69 @@
package net.sf.briar.i18n;
import java.awt.Font;
import java.util.Locale;
import junit.framework.TestCase;
import net.sf.briar.i18n.FontManagerImpl;
import org.junit.Test;
public class FontManagerImplTest extends TestCase {
@Test
public void testBundledFontsAreLoaded() {
FontManagerImpl fontManager = new FontManagerImpl();
fontManager.initialize(Locale.UK);
Font font = fontManager.getFontForLanguage("en"); // English
assertEquals(12, font.getSize());
font = fontManager.getFontForLanguage("bo"); // Tibetan
assertEquals("Tibetan Machine Uni", font.getFamily());
assertEquals(14, font.getSize());
font = fontManager.getFontForLanguage("my"); // Burmese
assertEquals("Padauk", font.getFamily());
assertEquals(14, font.getSize());
}
@Test
public void testInternationalCharactersCanBeDisplayed() {
FontManagerImpl fontManager = new FontManagerImpl();
fontManager.initialize(Locale.UK);
Font font = fontManager.getFontForLanguage("en"); // English
assertTrue(font.canDisplay('a'));
font = fontManager.getFontForLanguage("ar"); // Arabic
assertTrue(font.canDisplay('\u0627')); // An Arabic character
font = fontManager.getFontForLanguage("bo"); // Tibetan
assertTrue(font.canDisplay('\u0f00')); // A Tibetan character
font = fontManager.getFontForLanguage("fa"); // Persian
assertTrue(font.canDisplay('\ufb56')); // A Persian character
font = fontManager.getFontForLanguage("my"); // Burmese
assertTrue(font.canDisplay('\u1000')); // A Burmese character
font = fontManager.getFontForLanguage("zh"); // Chinese
assertTrue(font.canDisplay('\u4e00')); // A Chinese character
}
@Test
public void testSetAndGetUiFont() {
FontManagerImpl fontManager = new FontManagerImpl();
fontManager.initialize(Locale.UK);
Font font = fontManager.getUiFont();
assertEquals(12, font.getSize());
fontManager.setUiFontForLanguage("bo");
font = fontManager.getUiFont();
assertEquals("Tibetan Machine Uni", font.getFamily());
assertEquals(14, font.getSize());
fontManager.setUiFontForLanguage("en");
font = fontManager.getUiFont();
assertEquals(12, font.getSize());
}
}

View File

@@ -147,7 +147,7 @@ public class InvitationWorkerTest extends TestCase {
}
@After
public void tearDown() throws IOException {
TestUtils.delete(testDir);
public void tearDown() {
TestUtils.deleteTestDirectories();
}
}

View File

@@ -165,7 +165,7 @@ public class SetupWorkerTest extends TestCase {
}
@After
public void tearDown() throws IOException {
TestUtils.delete(testDir);
public void tearDown() {
TestUtils.deleteTestDirectories();
}
}

View File

@@ -159,7 +159,7 @@ public class FileUtilsTest extends TestCase {
}
@After
public void tearDown() throws IOException {
TestUtils.delete(testDir);
public void tearDown() {
TestUtils.deleteTestDirectories();
}
}

View File

@@ -195,7 +195,7 @@ public class ZipUtilsTest extends TestCase {
}
@After
public void tearDown() throws IOException {
TestUtils.delete(testDir);
public void tearDown() {
TestUtils.deleteTestDirectories();
}
}