From: plaa Date: Sat, 17 Mar 2012 20:35:21 +0000 (+0000) Subject: Remove test dependency on Swing X-Git-Tag: upstream/12.03~1^2~3 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=59429356802a39edd93de7b15889559116962c3a;p=debian%2Fopenrocket Remove test dependency on Swing git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@468 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/core/test/net/sf/openrocket/l10n/TestClassBasedTranslator.java b/core/test/net/sf/openrocket/l10n/TestClassBasedTranslator.java index 94909b0c..254b6619 100644 --- a/core/test/net/sf/openrocket/l10n/TestClassBasedTranslator.java +++ b/core/test/net/sf/openrocket/l10n/TestClassBasedTranslator.java @@ -35,11 +35,11 @@ public class TestClassBasedTranslator { // @formatter:off context.checking(new Expectations() {{ - oneOf(translator).get("TestClassBasedTranslator.fake.key"); will(returnValue("foobar")); + oneOf(translator).get("TestClassBasedTranslator.fake.key1"); will(returnValue("foobar")); }}); // @formatter:on - assertEquals("foobar", cbt.get("fake.key")); + assertEquals("foobar", cbt.get("fake.key1")); } @@ -49,12 +49,12 @@ public class TestClassBasedTranslator { // @formatter:off context.checking(new Expectations() {{ - oneOf(translator).get("TestClassBasedTranslator.fake.key"); will(throwException(new MissingResourceException("a", "b", "c"))); - oneOf(translator).get("fake.key"); will(returnValue("barbaz")); + oneOf(translator).get("TestClassBasedTranslator.fake.key2"); will(throwException(new MissingResourceException("a", "b", "c"))); + oneOf(translator).get("fake.key2"); will(returnValue("barbaz")); }}); // @formatter:on - assertEquals("barbaz", cbt.get("fake.key")); + assertEquals("barbaz", cbt.get("fake.key2")); } @@ -64,15 +64,15 @@ public class TestClassBasedTranslator { // @formatter:off context.checking(new Expectations() {{ - oneOf(translator).get("TestClassBasedTranslator.fake.key"); will(throwException(new MissingResourceException("a", "b", "c"))); - oneOf(translator).get("fake.key"); will(throwException(new MissingResourceException("a", "b", "c"))); + oneOf(translator).get("TestClassBasedTranslator.fake.key3"); will(throwException(new MissingResourceException("a", "b", "c"))); + oneOf(translator).get("fake.key3"); will(throwException(new MissingResourceException("a", "b", "c"))); }}); // @formatter:on try { - fail("Returned: " + cbt.get("fake.key")); + fail("Returned: " + cbt.get("fake.key3")); } catch (MissingResourceException e) { - assertEquals("Neither key 'TestClassBasedTranslator.fake.key' nor 'fake.key' could be found", e.getMessage()); + assertEquals("Neither key 'TestClassBasedTranslator.fake.key3' nor 'fake.key3' could be found", e.getMessage()); } } diff --git a/core/test/net/sf/openrocket/l10n/TestExceptionSuppressingTranslator.java b/core/test/net/sf/openrocket/l10n/TestExceptionSuppressingTranslator.java index 3296c834..1f9e8995 100644 --- a/core/test/net/sf/openrocket/l10n/TestExceptionSuppressingTranslator.java +++ b/core/test/net/sf/openrocket/l10n/TestExceptionSuppressingTranslator.java @@ -1,20 +1,17 @@ package net.sf.openrocket.l10n; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.MissingResourceException; -import net.sf.openrocket.gui.main.SwingExceptionHandler; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.startup.ExceptionHandler; import org.jmock.Expectations; import org.jmock.Mockery; import org.jmock.auto.Mock; import org.jmock.integration.junit4.JMock; import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -22,53 +19,55 @@ import org.junit.runner.RunWith; public class TestExceptionSuppressingTranslator { Mockery context = new JUnit4Mockery(); - @Before - public void setupExceptionHandler() { - Application.setExceptionHandler( new SwingExceptionHandler() ); - } @Mock Translator translator; + @Mock + ExceptionHandler exceptionHandler; + @Test public void testSuccessful() { + Application.setExceptionHandler(exceptionHandler); ExceptionSuppressingTranslator est = new ExceptionSuppressingTranslator(translator); // @formatter:off context.checking(new Expectations() {{ - oneOf(translator).get("fake.key"); will(returnValue("foobar")); + oneOf(translator).get("fake.key4"); will(returnValue("foobar")); }}); // @formatter:on - assertEquals("foobar", est.get("fake.key")); + assertEquals("foobar", est.get("fake.key4")); } @Test public void testFailure() { + Application.setExceptionHandler(exceptionHandler); ExceptionSuppressingTranslator est = new ExceptionSuppressingTranslator(translator); assertFalse("Prerequisite failed", ExceptionSuppressingTranslator.errorReported); // @formatter:off context.checking(new Expectations() {{ - oneOf(translator).get("fake.key"); will(throwException(new MissingResourceException("a", "b", "c"))); - oneOf(translator).get("fake.key"); will(throwException(new MissingResourceException("a", "b", "c"))); - oneOf(translator).get("fake.key2"); will(throwException(new MissingResourceException("a", "b", "c"))); + oneOf(exceptionHandler).handleErrorCondition(with(any(String.class)), with(any(MissingResourceException.class))); + oneOf(translator).get("fake.key5"); will(throwException(new MissingResourceException("a", "b", "c"))); + oneOf(translator).get("fake.key5"); will(throwException(new MissingResourceException("a", "b", "c"))); + oneOf(translator).get("fake.key6"); will(throwException(new MissingResourceException("a", "b", "c"))); }}); // @formatter:on // Test first failure - assertEquals("fake.key", est.get("fake.key")); + assertEquals("fake.key5", est.get("fake.key5")); assertTrue(ExceptionSuppressingTranslator.errorReported); // Test second failure - assertEquals("fake.key", est.get("fake.key")); + assertEquals("fake.key5", est.get("fake.key5")); assertTrue(ExceptionSuppressingTranslator.errorReported); // Test failure with other key - assertEquals("fake.key2", est.get("fake.key2")); + assertEquals("fake.key6", est.get("fake.key6")); assertTrue(ExceptionSuppressingTranslator.errorReported); } - + }