|
@@ -1,121 +0,0 @@
|
1
|
|
-/*
|
2
|
|
- * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
3
|
|
- *
|
4
|
|
- * Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
|
- * of this software and associated documentation files (the "Software"), to deal
|
6
|
|
- * in the Software without restriction, including without limitation the rights
|
7
|
|
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
|
- * copies of the Software, and to permit persons to whom the Software is
|
9
|
|
- * furnished to do so, subject to the following conditions:
|
10
|
|
- *
|
11
|
|
- * The above copyright notice and this permission notice shall be included in
|
12
|
|
- * all copies or substantial portions of the Software.
|
13
|
|
- *
|
14
|
|
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
|
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
|
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
|
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
|
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
|
- * SOFTWARE.
|
21
|
|
- */
|
22
|
|
-
|
23
|
|
-package com.dmdirc.ui.messages;
|
24
|
|
-
|
25
|
|
-import com.dmdirc.Main;
|
26
|
|
-import com.dmdirc.config.IdentityManager;
|
27
|
|
-
|
28
|
|
-import java.io.File;
|
29
|
|
-import java.util.Set;
|
30
|
|
-
|
31
|
|
-import org.junit.Before;
|
32
|
|
-import org.junit.Test;
|
33
|
|
-import static org.junit.Assert.*;
|
34
|
|
-
|
35
|
|
-public class FormatterTest {
|
36
|
|
-
|
37
|
|
- @Before
|
38
|
|
- public void setUp() throws Exception {
|
39
|
|
- IdentityManager.load();
|
40
|
|
- }
|
41
|
|
-
|
42
|
|
- @Test
|
43
|
|
- public void testFormatMessage() {
|
44
|
|
- Formatter.registerDefault("unitTest", "abc %2$s %1$s def");
|
45
|
|
-
|
46
|
|
- // Standard format test
|
47
|
|
- assertEquals(Formatter.formatMessage("unitTest", "123", "456"), "abc 456 123 def");
|
48
|
|
-
|
49
|
|
- // Check unknown formats
|
50
|
|
- assertTrue(Formatter.formatMessage("unitTest123", "m").indexOf("No format string") > -1);
|
51
|
|
-
|
52
|
|
- Formatter.registerDefault("unitTest2", "abc %2$$$ZAS %1$s def");
|
53
|
|
-
|
54
|
|
- // And invalid formats
|
55
|
|
- assertTrue(Formatter.formatMessage("unitTest2", "m").indexOf("Invalid format string") > -1);
|
56
|
|
- }
|
57
|
|
-
|
58
|
|
- @Test
|
59
|
|
- public void testGetFormats() {
|
60
|
|
- final Set<String> s1 = Formatter.getFormats();
|
61
|
|
- Formatter.registerDefault("unitTest3", "abc");
|
62
|
|
- final Set<String> s2 = Formatter.getFormats();
|
63
|
|
- final Set<String> s3 = Formatter.getFormats();
|
64
|
|
-
|
65
|
|
- assertEquals(s2, s3);
|
66
|
|
- assertTrue(s1.size() + 1 == s2.size());
|
67
|
|
- }
|
68
|
|
-
|
69
|
|
- @Test
|
70
|
|
- public void testHasFormat() {
|
71
|
|
- final String[] targets = new String[]{"unknown", "abc", "def", "unittestfail"};
|
72
|
|
-
|
73
|
|
- for (String target : targets) {
|
74
|
|
- assertFalse(Formatter.hasFormat(target));
|
75
|
|
- }
|
76
|
|
-
|
77
|
|
- for (String target : Formatter.getFormats()) {
|
78
|
|
- assertTrue(Formatter.hasFormat(target));
|
79
|
|
- }
|
80
|
|
- }
|
81
|
|
-
|
82
|
|
- @Test
|
83
|
|
- public void testSaveAndLoad() {
|
84
|
|
- Formatter.registerDefault("unitTest_saveLoad", "");
|
85
|
|
-
|
86
|
|
- final String fileName = "unittest_formatter";
|
87
|
|
- final File file = new File(Main.getConfigDir() + fileName);
|
88
|
|
-
|
89
|
|
- if (file.exists()) {
|
90
|
|
- file.delete();
|
91
|
|
- }
|
92
|
|
-
|
93
|
|
- Formatter.saveAs(fileName);
|
94
|
|
-
|
95
|
|
- assertTrue(file.exists());
|
96
|
|
-
|
97
|
|
- Formatter.reload();
|
98
|
|
-
|
99
|
|
- Formatter.loadFile(fileName);
|
100
|
|
-
|
101
|
|
- assertTrue(Formatter.hasFormat("unitTest_saveLoad"));
|
102
|
|
-
|
103
|
|
- file.delete();
|
104
|
|
- }
|
105
|
|
-
|
106
|
|
- @Test
|
107
|
|
- public void testReload() {
|
108
|
|
- Formatter.reload();
|
109
|
|
-
|
110
|
|
- final Set<String> s1 = Formatter.getFormats();
|
111
|
|
-
|
112
|
|
- Formatter.registerDefault("UnitTestABCDEF", "");
|
113
|
|
-
|
114
|
|
- Formatter.reload();
|
115
|
|
-
|
116
|
|
- final Set<String> s2 = Formatter.getFormats();
|
117
|
|
-
|
118
|
|
- assertEquals(s1.size(), s2.size());
|
119
|
|
- }
|
120
|
|
-
|
121
|
|
-}
|