### Question:
XWikiMessageTool { public String get(String key) { String translation; if (this.localization != null) { translation = get(key, ArrayUtils.EMPTY_OBJECT_ARRAY); } else { translation = getTranslation(key); if (translation == null) { try { translation = this.bundle.getString(key); } catch (Exception e) { translation = key; } } } return translation; } XWikiMessageTool(ContextualLocalizationManager localization);  XWikiMessageTool(ResourceBundle bundle, XWikiContext context); String get(String key); String get(String key, List<?> params); String get(String key, Object... params); List<XWikiDocument> getDocumentBundles(); XWikiDocument getDocumentBundle(String documentName); List<XWikiDocument> getDocumentBundles(String documentName, String defaultLanguage); Properties getDocumentBundleProperties(XWikiDocument docBundle);  }### Answer:
@Test public void testGetWhenPreferenceDoesNotExist() { assertEquals("invalid", this.tool.get("invalid")); }
@Test public void testGetWhenNoTranslationAvailable() { assertEquals("value", this.tool.get("key")); }
@Test public void testGetWhenKeyIsNull() { assertNull(this.tool.get(null)); }
@Test public void testGetWhenInXWikiPreferences() throws XWikiException { saveTranslations(this.translationDocumentReference1, "somekey=somevalue"); saveTranslations(this.translationDocumentReference2, "someKey=someValue\n" + "keyInXWikiPreferences=eureka"); setPreferencesTranslationBundle(this.translationDocumentReference1, this.translationDocumentReference2); assertEquals("eureka", this.tool.get("keyInXWikiPreferences")); }
@Test public void testGetWhenInXWikiConfigurationFile() throws XWikiException { saveTranslations("keyInXWikiCfg=gotcha", false); assertEquals("gotcha", this.tool.get("keyInXWikiCfg")); }
@Test public void testGetWithParameters() throws XWikiException { saveTranslations("key=We have {0} new documents with {1} objects. {2}"); List<String> params = new ArrayList<String>(); params.add("12"); params.add("3"); assertEquals("We have 12 new documents with 3 objects. {2}", this.tool.get("key", params)); }
@Test public void testGetWhenDocumentModifiedAfterItIsInCache() throws XWikiException { saveTranslations("key=value"); assertEquals("modifiedKey", this.tool.get("modifiedKey")); saveTranslations("modifiedKey=found", new Date(System.currentTimeMillis() + 1000L)); assertEquals("found", this.tool.get("modifiedKey")); }
@Test public void testGetWhenWithUTF8Translation() throws XWikiException { saveTranslations(this.translationDocumentReference1, "somekey=some\u00E9value\nsomekey2=some\\u00E9value2"); saveTranslations(this.translationDocumentReferenceFR1, "somekey=somevaluetrans"); assertEquals("some\u00E9value", this.tool.get("somekey")); assertEquals("some\u00E9value2", this.tool.get("somekey2")); }