1 package net.sf.openrocket.l10n;
3 import static org.junit.Assert.*;
5 import java.util.MissingResourceException;
7 import org.jmock.Expectations;
8 import org.jmock.Mockery;
9 import org.jmock.auto.Mock;
10 import org.jmock.integration.junit4.JMock;
11 import org.jmock.integration.junit4.JUnit4Mockery;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
16 public class TestExceptionSuppressingTranslator {
17 Mockery context = new JUnit4Mockery();
20 Translator translator;
23 public void testSuccessful() {
24 ExceptionSuppressingTranslator est = new ExceptionSuppressingTranslator(translator);
27 context.checking(new Expectations() {{
28 oneOf(translator).get("fake.key"); will(returnValue("foobar"));
32 assertEquals("foobar", est.get("fake.key"));
37 public void testFailure() {
38 ExceptionSuppressingTranslator est = new ExceptionSuppressingTranslator(translator);
40 assertFalse("Prerequisite failed", ExceptionSuppressingTranslator.errorReported);
43 context.checking(new Expectations() {{
44 oneOf(translator).get("fake.key"); will(throwException(new MissingResourceException("a", "b", "c")));
45 oneOf(translator).get("fake.key"); will(throwException(new MissingResourceException("a", "b", "c")));
46 oneOf(translator).get("fake.key2"); will(throwException(new MissingResourceException("a", "b", "c")));
51 assertEquals("fake.key", est.get("fake.key"));
52 assertTrue(ExceptionSuppressingTranslator.errorReported);
54 // Test second failure
55 assertEquals("fake.key", est.get("fake.key"));
56 assertTrue(ExceptionSuppressingTranslator.errorReported);
58 // Test failure with other key
59 assertEquals("fake.key2", est.get("fake.key2"));
60 assertTrue(ExceptionSuppressingTranslator.errorReported);