Remove test dependency on Swing
This commit is contained in:
parent
db47952192
commit
8f6fa2121c
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user