Component scaling support
[debian/openrocket] / test / net / sf / openrocket / l10n / TestExceptionSuppressingTranslator.java
1 package net.sf.openrocket.l10n;
2
3 import static org.junit.Assert.*;
4
5 import java.util.MissingResourceException;
6
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;
14
15 @RunWith(JMock.class)
16 public class TestExceptionSuppressingTranslator {
17         Mockery context = new JUnit4Mockery();
18         
19         @Mock
20         Translator translator;
21         
22         @Test
23         public void testSuccessful() {
24                 ExceptionSuppressingTranslator est = new ExceptionSuppressingTranslator(translator);
25                 
26                 // @formatter:off
27                 context.checking(new Expectations() {{
28                                 oneOf(translator).get("fake.key"); will(returnValue("foobar")); 
29                 }});
30                 // @formatter:on
31                 
32                 assertEquals("foobar", est.get("fake.key"));
33         }
34         
35         
36         @Test
37         public void testFailure() {
38                 ExceptionSuppressingTranslator est = new ExceptionSuppressingTranslator(translator);
39                 
40                 assertFalse("Prerequisite failed", ExceptionSuppressingTranslator.errorReported);
41                 
42                 // @formatter:off
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"))); 
47                 }});
48                 // @formatter:on
49                 
50                 // Test first failure
51                 assertEquals("fake.key", est.get("fake.key"));
52                 assertTrue(ExceptionSuppressingTranslator.errorReported);
53                 
54                 // Test second failure
55                 assertEquals("fake.key", est.get("fake.key"));
56                 assertTrue(ExceptionSuppressingTranslator.errorReported);
57                 
58                 // Test failure with other key
59                 assertEquals("fake.key2", est.get("fake.key2"));
60                 assertTrue(ExceptionSuppressingTranslator.errorReported);
61         }
62         
63
64 }