Timeline for How can I modify the core api in java ?
Current License: CC BY-SA 4.0
18 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 6, 2024 at 8:59 | answer | added | yicai.liu | timeline score: -1 | |
| Mar 4, 2024 at 2:40 | vote | accept | yicai.liu | ||
| Mar 3, 2024 at 10:06 | answer | added | ndc85430 | timeline score: 2 | |
| Mar 3, 2024 at 9:40 | comment | added | user85421 | searching the error message gives the following results on this site! See this answer: "FixedValue can only be used with Strings, Class object, primitive types and their wrappers. ..." | |
| Mar 3, 2024 at 8:40 | comment | added | ndc85430 | You don't even need a mocking framework to do that. I'm currently travelling, but I'll write an answer shortly. | |
| Mar 3, 2024 at 8:35 | comment | added | user85421 | is this eventually a use case for some mocking framework like Mockito? | |
| Mar 3, 2024 at 8:23 | comment | added | yicai.liu | for tester-engineer testing the schedule task without lots of business code modify | |
| Mar 3, 2024 at 8:19 | comment | added | ndc85430 | @yicai.liu but why? Are you actually just trying to fix time in tests? If so, dependency injection is the correct solution to that as already hinted at. If that's not what you're trying to do, please clarify. | |
| Mar 3, 2024 at 8:19 | comment | added | yicai.liu | change the implementation of get system time in non-prd-env,and the developer do nothing,and can not change the system clock. | |
| Mar 3, 2024 at 8:16 | comment | added | Stephen C | @PeterCordes - Well yea ... but that potentially effects the entire system. It will break some things (e.g. those that depend on clocks being in sync with other machines), and make other things behave in undesirable ways; e.g. timestamps in log messages for the entire environment. | |
| Mar 3, 2024 at 8:15 | comment | added | yicai.liu | purpose : change the implementation of get system time in non-prd-env,and the developer do nothing,and can not change the system clock. | |
| Mar 3, 2024 at 8:04 | comment | added | Peter Cordes |
@DawoodibnKareem: In a non-production environment, another option is to set the system clock to any time you want. (e.g. inside a VM, but outside the JVM.) Or perhaps with LD_PRELOAD with a library that intercepts libc function calls by the JVM, so clock_gettime will return different times. That would let LocalDateTime stuff be different from the mod times on files your program writes.
|
|
| Mar 3, 2024 at 7:58 | history | edited | Peter Cordes |
edited tags
|
|
| Mar 3, 2024 at 7:46 | comment | added | Dawood ibn Kareem |
The right way to have a different "current time" in non-production environments (for example, for testing what will happen at some future date) is never to use LocalDateTime.now(), but always LocalDateTime.now(Clock clock) instead, and inject a suitable Clock implementation into any class that needs the current time. Are you sure that "How can I modify the core api in Java" is the question you actually want to ask?
|
|
| Mar 3, 2024 at 7:41 | comment | added | ndc85430 | Why do you want to change the method? What is it you're actually trying to do for which you think you need to do this? | |
| S Mar 3, 2024 at 7:37 | review | Triage | |||
| Mar 8, 2024 at 5:03 | |||||
| S Mar 3, 2024 at 7:37 | review | First questions | |||
| Mar 3, 2024 at 7:37 | |||||
| S Mar 3, 2024 at 7:37 | history | asked | yicai.liu | CC BY-SA 4.0 | created from wizard |