我似乎无法理解这一点。我明白了
java.lang.IncompatibleClassChangeError: Implementing class
我试图找出如何发送一个挂起的意图,通过将其推送到类中进行组织。目前我有以下几点:
@RunWith(PowerMockRunner.class)
@PrepareForTest(PendingIntent.class)
public class TheTests{
private Context _context;
private AlarmManager _alarmManager;
private Manager _manager;
@Before
public void setup() {
_alarmManager = Mockito.mock(AlarmManager.class);
_context = Mockito.mock(Context.class);
Mockito.when(_context.getSystemService(anyString())).thenReturn(_alarmManager);
_manager = new Manager(_context);
}
@Test
public void example() {
PendingIntent expected = PowerMockito.mock(PendingIntent.class);
PowerMockito
.when(PendingIntent.getBroadcast(any(Context.class), anyInt(), any(Intent.class), anyInt()))
.thenReturn(expected);
_manager.broadcast(_cal, new Schedule());
}
}
public Manager class {
public void broadcast(Thing thing) {
if (thing == null) {
return;
}
Intent sender = new Intent("broadcast.AlarmReceiverFilter");
PendingIntent pendingIntent = PendingIntent.getBroadcast(_context, 0, sender, PendingIntent.FLAG_CANCEL_CURRENT);
_alarm.set(AlarmManager.RTC_WAKEUP, 0, pendingIntent);
}
}
在这一切之后,我不知道如何让他们都打得很好。我的目标是验证
getBroadcast
同样
Intent
它本身
凯莉
更新:下面的讨论建议避免使用powermock,因此我尝试了以下方法:
@Test
public void example2() {
ShadowApplication shadowApp = shadowOf(RuntimeEnvironment.application);
_manager = new TimeManager(shadowApp.getApplicationContext());
_manager.broadcast(new Thing());
List<Intent> intents = shadowApp.getBroadcastIntents();
assertEquals(intents.size(), 1); // actual size is 0 (zero)
}