这是我的单元测试。不知何故,当我使用非空字符串参数创建实例化 SpannableStringBuilder 实例时,它似乎为空。这段代码有什么问题?
public class CardNumberTextWatcherTest {
private CardNumberTextWatcher watcher;
@Before
public void setUp() throws Exception {
watcher = new CardNumberTextWatcher();
}
@Test
public void afterTextChanged_cardNumberDividedWithSpaces() {
assertTransformText("1111222233334444", "1111 2222 3333 4444");
}
private void assertTransformText(final String testStr,
final String expectedStr) {
final CardNumberTextWatcher watcher = new CardNumberTextWatcher();
final Editable actualStr = new SpannableStringBuilder(testStr);
// When I debug I see that actualStr value is null. Therefore test
//doesn't pass. What's the problem?
watcher.transformText(actualStr);
assertEquals(expectedStr, actualStr.toString());
}
}