in Education by
I need to mock a Logger in a @Service class to make tests. I want to verify if a logger message will be created. (SLF4J Logger) I think I can do it using @Bean class and make the Logger a managed bean on spring. But I need to create the logger using the .class of the injected Service too. Somebody knows how to do it? Nathan, thanks by the duplicate tag and suggestuse appender. My problem is i cannot use a unit test or a test without spring-context, because I have to do a integration-test with two DBs. And the test for spring does not allow mock the logger in a first test without influences the next test. Example: @Service class MigrateDataService{ @Autowired private FirstDB firstDB; @Autowired private SecondDB secondDB; Logger logger = LoggerFactory.getLogger(MigrateDataService.class); @Transactional(...) public void migrate(){ Data data firstDB.getData(); if(data.isWarn()){ logger.warn("Data {} is warning", data); } secondDB.save(data); } } I need to detect the logger.warn call. thanks... JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This is not a slick way to do it but it works. private void setLogger(Logger logger){ this.logger = logger; } then in your test code, set the logger to the mocked logger.

Related questions

0 votes
    I want polity mocks Select the correct answer from above options...
asked Aug 3, 2022 in Education by JackTerrance
0 votes
    I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 23, 2022 in Education by JackTerrance
0 votes
    I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 12, 2022 in Education by JackTerrance
0 votes
    I'm trying to test my Category class. I'm using Mockery::mock() method, with 'overload:' prefix ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm trying to write tests for an angular 5 application which uses a js import, I've been doing ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I'm trying to test my Category class. I'm using Mockery::mock() method, with 'overload:' prefix ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    In my tests I need to test what happens when an OracleException is thrown (due to a stored procedure ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    Which of these method of String class can be used to test to strings for equality? (a) isequal() ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Why do we need to write test classes? How to identify if a class is a test class?...
asked Nov 11, 2020 in Technology by JackTerrance
0 votes
    ____________ is the command to install and run Cucumber test. A. npm install B. mvn test C. npm test D. mvn clean install...
asked Dec 8, 2022 in Credit by JackTerrance
0 votes
    We are trying to run automated tests using Microsoft Test Manager 2015. We've almost reached our goal. This ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I'm modifying someone else's code where a query is performed using the following: DataSet ds = new ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 23, 2022 in Education by JackTerrance
...