Привет!
Условно говоря, есть класс:
@Component
public class TelegramBot extends TelegramLongPollingBot implements InitializingBean {
private static final org.slf4j.Logger log = LoggerFactory.getLogger(TelegramBot.class);
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Autowired
private TelegramDao telegramDao;
@Value("${spring.botusername}")
private String botUserName;
@Value("${spring.bottoken}")
private String botToken;
public void sendMessage(Chat chat, String message) {
}
}
Я хочу протестировать вызов метода sendMessage.
Написал тест:
@RunWith(SpringJUnit4ClassRunner.class)
public class TelegramTest {
@Autowired
@Qualifier("bot")
private TelegramBot telegramBot;
@Test
public void test1(){
telegramBot.sendMessage(null,null);
}
}
Получаю ошибку:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'telegram.TelegramTest': Unsatisfied dependency expressed through field 'telegramBot'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'TelegramBot' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=bot)}
Что я делаю не так?