- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 RssServiceTest service.start();
行的方法 testStartEnbaledFeed 上遇到 NullPointerException,然后在 RssService job.addJobChangeListener(new JobChangeAdapter() {
) 行上出现 NullPointerException >
关键问题似乎是实际调用了 job.addChangelistener 方法。有人知道如何解决吗?下面列出了 RssServiceTest 和 RssService 类:
package org.eclipse.recommenders.internal.news.rcp;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
import org.eclipse.mylyn.commons.notifications.core.NotificationEnvironment;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import com.google.common.collect.ImmutableList;
import com.google.common.eventbus.EventBus;
@SuppressWarnings("restriction")
@RunWith(MockitoJUnitRunner.class)
public class RssServiceTest {
private static final String FIRST_ELEMENT = "first";
private static final String SECOND_ELEMENT = "second";
@Test
public void testStartEnabledFeed() {
FeedDescriptor feed = FeedDescriptorsTest.enabled(FIRST_ELEMENT);
PollFeedJob job = mock(PollFeedJob.class);
JobProvider provider = mock(JobProvider.class);
NewsRcpPreferences preferences = mock(NewsRcpPreferences.class);
when(preferences.isEnabled()).thenReturn(true);
when(preferences.getFeedDescriptors()).thenReturn(ImmutableList.of(feed));
NotificationEnvironment environment = mock(NotificationEnvironment.class);
EventBus bus = mock(EventBus.class);
when(provider.getPollFeedJob(Mockito.eq(feed), Mockito.eq(preferences), Mockito.eq(environment)))
.thenReturn(job);
RssService service = new RssService(preferences, bus, environment, provider);
assertThat(preferences, is(notNullValue()));
assertThat(bus, is(notNullValue()));
assertThat(environment, is(notNullValue()));
assertThat(provider, is(notNullValue()));
assertThat(job, is(notNullValue()));
assertThat(feed, is(notNullValue()));
assertThat(service, is(notNullValue()));
service.start();
}
}
`
package org.eclipse.recommenders.internal.news.rcp;
import static java.lang.Long.parseLong;
import static org.eclipse.recommenders.internal.news.rcp.FeedEvents.createNewFeedItemsEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.mylyn.commons.notifications.core.NotificationEnvironment;
import org.eclipse.recommenders.internal.news.rcp.FeedEvents.FeedMessageReadEvent;
import org.eclipse.recommenders.news.rcp.IFeedMessage;
import org.eclipse.recommenders.news.rcp.IRssService;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
@SuppressWarnings("restriction")
public class RssService implements IRssService {
private static final long DEFAULT_DELAY = TimeUnit.DAYS.toMinutes(1);
private static final long START_DELAY = 0;
private final NewsRcpPreferences preferences;
private final EventBus bus;
private final NotificationEnvironment environment;
private final JobProvider provider;
private final Set<String> readIds;
private final HashMap<FeedDescriptor, List<IFeedMessage>> groupedMessages = Maps.newHashMap();
public RssService(NewsRcpPreferences preferences, EventBus bus, NotificationEnvironment environment,
JobProvider provider) {
this.preferences = preferences;
this.bus = bus;
this.environment = environment;
this.provider = provider;
bus.register(this);
readIds = ReadFeedMessagesProperties.getReadIds();
}
@Override
public void start() {
for (final FeedDescriptor feed : preferences.getFeedDescriptors()) {
if (feed.isEnabled()) {
start(feed);
}
}
}
@Override
public void start(final FeedDescriptor feed) {
// final PollFeedJob job = new PollFeedJob(feed, preferences, environment);
final PollFeedJob job = provider.getPollFeedJob(feed, preferences, environment);
job.setSystem(true);
job.setPriority(Job.DECORATE);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
boolean newMessage = false;
if (!groupedMessages.containsKey(feed)) {
groupedMessages.put(feed, Lists.<IFeedMessage>newArrayList());
}
List<IFeedMessage> feedMessages = groupedMessages.get(feed);
for (IFeedMessage message : job.getMessages()) {
if (!feedMessages.contains(message)) {
feedMessages.add(message);
if (!readIds.contains(message.getId())) {
newMessage = true;
}
}
}
if (groupedMessages.size() > 0 && newMessage) {
bus.post(createNewFeedItemsEvent());
}
if (!preferences.isEnabled() || !isFeedEnabled(feed)) {
return;
}
if (feed.getPollingInterval() != null) {
job.schedule(TimeUnit.MINUTES.toMillis(parseLong(feed.getPollingInterval())));
return;
}
job.schedule(TimeUnit.MINUTES.toMillis(DEFAULT_DELAY));
}
});
if (!provider.jobExists(feed, preferences, environment)) {
job.schedule(START_DELAY);
}
}
@Override
public Map<FeedDescriptor, List<IFeedMessage>> getMessages(final int countPerFeed) {
Map<FeedDescriptor, List<IFeedMessage>> transformedMap = Maps.transformValues(groupedMessages,
new Function<List<IFeedMessage>, List<IFeedMessage>>() {
@Override
public List<IFeedMessage> apply(List<IFeedMessage> input) {
return FluentIterable.from(input).limit(countPerFeed).filter(new Predicate<IFeedMessage>() {
@Override
public boolean apply(IFeedMessage input) {
return !readIds.contains(input.getId());
}
}).toList();
}
});
Map<FeedDescriptor, List<IFeedMessage>> filteredMap = Maps.filterValues(transformedMap,
new Predicate<List<IFeedMessage>>() {
@Override
public boolean apply(List<IFeedMessage> input) {
if (input == null) {
return false;
}
return !input.isEmpty();
}
});
return ImmutableMap.copyOf(filteredMap);
}
private boolean isFeedEnabled(FeedDescriptor feed) {
for (FeedDescriptor fd : preferences.getFeedDescriptors()) {
if (feed.getId().equals(fd.getId())) {
return true;
}
}
return false;
}
@Subscribe
public void handle(FeedMessageReadEvent event) {
readIds.add(event.getId());
ReadFeedMessagesProperties.writeReadIds(readIds);
}
}
`
java.lang.NullPointerException
at org.eclipse.core.internal.jobs.InternalJob.addJobChangeListener(InternalJob.java:161)
at org.eclipse.core.runtime.jobs.Job.addJobChangeListener(Job.java:182)
at org.eclipse.recommenders.internal.news.rcp.RssService.start(RssService.java:77)
at org.eclipse.recommenders.internal.news.rcp.RssService.start(RssService.java:66)
at org.eclipse.recommenders.internal.news.rcp.RssServiceTest.testStartEnabledFeed(RssServiceTest.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
at org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness$1.run(PlatformUITestHarness.java:47)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4147)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3764)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:832)
at org.eclipse.jface.window.Window.open(Window.java:808)
at org.eclipse.jface.dialogs.MessageDialog.open(MessageDialog.java:341)
at org.eclipse.recommenders.internal.rcp.RcpModule$2.run(RcpModule.java:248)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4147)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3764)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runApp(NonUIThreadTestApplication.java:54)
at org.eclipse.pde.internal.junit.runtime.UITestApplication.runApp(UITestApplication.java:47)
at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.start(NonUIThreadTestApplication.java:48)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
最佳答案
我要做的第一件事就是改变
when(provider.getPollFeedJob(Mockito.eq(feed), Mockito.eq(preferences), Mockito.eq(environment)))
.thenReturn(job);
至
when(provider.getPollFeedJob(any(FeedDescriptor.class), any(NewsRcpPreferences.class), any(NotificationEnvironment.class)))
.thenReturn(job);
这只是为了确保您的提供商确实为您提供了模拟工作。
然后我会添加一个
doNothing().when(job).addJobChangeListener(any(JobChangeAdapter.class));
或者你可以先做第二个。不管怎样,这两件事你都可以尝试。
关于java - 测试时的 NPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30186817/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!