Remove test dependency on Swing
authorplaa <plaa@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sat, 17 Mar 2012 20:35:21 +0000 (20:35 +0000)
committerplaa <plaa@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sat, 17 Mar 2012 20:35:21 +0000 (20:35 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@468 180e2498-e6e9-4542-8430-84ac67f01cd8

core/test/net/sf/openrocket/l10n/TestClassBasedTranslator.java
core/test/net/sf/openrocket/l10n/TestExceptionSuppressingTranslator.java

index 94909b0cd41ac5223fea2bb6b0365890a10a762c..254b66194add149441db464605575402768ab4fe 100644 (file)
@@ -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());
                }
                
        }
index 3296c83452f553c24cb8096bbc88b722babab336..1f9e8995b08fc523a22e536096a542248dc93d48 100644 (file)
@@ -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);
        }
        
-
+       
 }