'How to use mock in a private static final variable in Spock?
Say I have a private static final variable in a Java class like:
@Service
public class MyClass {
private static final Logger LOGGER = LoggerFactory.getLogger(MyClass.class);
...
}
Then I have test class like:
class MyClassTest extends Specification {
@Autowired
MyClass sut
def "Testing a private static final variable"() {
given:
sut.LOGGER = Mock(Logger)
when:
...
}
How can I use Mock(Logger) with sut.LOGGER where LOGGER is a private static final in MyClass class? Without the final keyword, the test would just run fine though but I wanted it to work with a final keyword. Any suggestion is highly appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
