Skip to content

Instantly share code, notes, and snippets.

@shinchit
Last active October 3, 2019 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinchit/b66ac5aba45a38be5cc6bbdf14806f18 to your computer and use it in GitHub Desktop.
Save shinchit/b66ac5aba45a38be5cc6bbdf14806f18 to your computer and use it in GitHub Desktop.
@isTest
public with sharing class Some_Test {
private static final Map<String, String> lang2key = new Map<String, String>{'English' => 'en_US', 'Japanese' => 'ja', 'Simplefied_Chinese' => 'zh_CN'};
private static User setLang(String lang) {
User me = [SELECT Id, LanguageLocaleKey FROM USER WHERE Id = :UserInfo.getUserId() LIMIT 1];
me.LanguageLocaleKey = lang2key.get(lang);
update me;
return me;
}
@isTest static void testGetSomeLabel() {
Test.startTest();
System.runAs(Some_Test.setLang('English')) {
// getSomeLabel(String key) returns key's label.
String someLabel = Some.getSomeLabel('key');
System.assertEquals('Key', someLabel, 'label is not correct');
}
System.runAs(Some_Test.setLang('Japanese')) {
// getSomeLabel(String key) returns key's label.
String someLabel = Some.getSomeLabel('key');
System.assertEquals('キー', someLabel, 'ラベルが正しくありません');
}
Test.stopTest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment