我正在编写一个新应用程序并尝试使用黄瓜和Spring Boot 1.4进行BDD.工作代码如下所示:
@SpringBootApplication
public class Application {
@Bean
MyService myService() {
return new MyService();
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
public class MyService {}
Run Code Online (Sandbox Code Playgroud)
测试代码如下所示:
@RunWith(Cucumber.class)
public class RunFeatures {}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class, loader = SpringApplicationContextLoader.class)
public class MyStepDef {
@Autowired
MyService myService;
@Given("^Some initial condition$")
public void appIsStarted() throws Throwable {
if (service == null) throw new Exception("Dependency not injected!");
System.out.println("App started");
}
@Then("^Nothing happens$")
public void thereShouldBeNoException() throws Throwable {
System.out.println("Test …Run Code Online (Sandbox Code Playgroud) 我按照一个简单的例子来设置和运行带有Spring Boot的嵌入式ActiveMQ(版本1.4.X).这是示例https://spring.io/guides/gs/messaging-jms/的链接
我的课程结构如下:
@SpringBootApplication
@EnableJms
public class Application {
@Autowired
ConfigurableApplicationContext context;
@Bean
JmsListenerContainerFactory<?> myJmsContainerFactory(ConnectionFactory connectionFactory) {
SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
return factory;
}
@JmsListener(destination = "mailbox-destination", containerFactory = "myJmsContainerFactory")
public void receiveMessage(String message) {
System.out.println("Message received: " + message);
context.close();
}
public static void main(String[] args) throws Exception {
FileSystemUtils.deleteRecursively(new File("active-data"));
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
JmsTemplate template = context.getBean(JmsTemplate.class);
MessageCreator messageCreator = new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("Test"); …Run Code Online (Sandbox Code Playgroud) 我有一个简单的场景,我试图在调用一个方法时验证一些行为(即某个方法是用给定的参数调用的,在这个场景中是一个函数指针).以下是我的课程:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
AppBootStrapper bootStrapper = context.getBean(AppBootStrapper.class);
bootStrapper.start();
}
}
@Component
public class AppBootStrapper {
private NetworkScanner networkScanner;
private PacketConsumer packetConsumer;
public AppBootStrapper(NetworkScanner networkScanner, PacketConsumer packetConsumer) {
this.networkScanner = networkScanner;
this.packetConsumer = packetConsumer;
}
public void start() {
networkScanner.addConsumer(packetConsumer::consumePacket);
networkScanner.startScan();
}
}
@Component
public class NetworkScanner {
private List<Consumer<String>> consumers = new ArrayList<>();
public void startScan(){
Executors.newSingleThreadExecutor().submit(() -> {
while(true) {
// do some scanning and …Run Code Online (Sandbox Code Playgroud)