the right way test date & time in java

  Рет қаралды 46,818

Amigoscode

2 жыл бұрын

The practice to test applications that use time is to pass a Clock into any method that requires the current instant and a dependency injection framework is one way to achieve this.
🚀 Thanks to Mailgun for sponsoring this video! Head to
mailgun.com/amigoscode to try Mailgun today.
🚀 Register your interested for bootcamp here: amigoscode.hopp.to/bootcamp-register-interest
#amigoscode #java #unittesting
Don't Forget to
===========================================
💯 Subscribe to Amigoscode - bit.ly/2HpF5V8
💯 Courses Available for free here - amigoscode.com/courses
💯 Join Private Facebook Group and Discord - amigoscode.com/p/join-community
⭐ Table Of Contents ⭐
===========================================
00:00 - Intro
04:15 - Testing Date and Time
13:21 - Outro
🙊 Here are the goods for all my videos video 🙊
► Recommended Books
===========================================
- Clean Code - amzn.to/2UGDPlX
- HTTP: The Definitive Guide - amzn.to/2JDVi8s
- Clean Architecture - amzn.to/2xOBNXW
► Computer and Monitor
===========================================
- New Apple MacBook Pro - amzn.to/3464Mmn
- Dell 27 INCH Ultrasharp U2719D Monitor - amzn.to/2xM3nW1
- Double Arm Stand Desk Mount - amzn.to/3aYKKfs
- USB C Hub Multiport Adapter - amzn.to/2Jz7NlL
► Camera Gear
=============================================
- Sony ILCE7M3B Full Frame Mirrorless Camera - amzn.to/346QIJn
- Sigma 16 mm F1.4 DC DN - amzn.to/2wbic3Q
- Sigma 33B965 30 mm F1.4 DC DC - amzn.to/39G37Fd
► IDE & Tools I use for coding 💻 🎒
===========================================
- ITerm
- VsCode
- GoLand
- IntelliJ Ultimate
- Sublime
P.S
===========================================
💯 Don't forget to subscribe | bit.ly/2HpF5V8
💯 Join Private Facebook Group and Discord - amigoscode.com/p/join-community
💯 Follow me on Instagram | bit.ly/2TSkA9w
❤️ Thanks for watching

Пікірлер: 92
@amigoscode
@amigoscode 2 жыл бұрын
🚀 Thanks to Mailgun for sponsoring this video! Head to mailgun.com/amigoscode to try Mailgun today. 🚀 Register your interested for bootcamp here: amigoscode.hopp.to/bootcamp-register-interest
@flyingrecordofficial
@flyingrecordofficial 2 жыл бұрын
Great job bro
@ishyo9220
@ishyo9220 2 жыл бұрын
East or west ⬅️ Amigos code is the best 🤣
@flyingrecordofficial
@flyingrecordofficial 2 жыл бұрын
@@ishyo9220why laughing 😅
@ishyo9220
@ishyo9220 2 жыл бұрын
@@flyingrecordofficial that's smile for expressing my feelings on Amigos code...🤟 I love it 😁
@MrUzair-bw3cg
@MrUzair-bw3cg Жыл бұрын
Hello Sir! I am big fan of you. Can you build a Master course on spring boot with javafx. Because no one can explain briefly like you
@mrsofiane
@mrsofiane 2 жыл бұрын
Yes it's always the best way to test time, i learned it in my internship
@Denys.Stoianov
@Denys.Stoianov 2 жыл бұрын
Thank you Mann, very interesting moment, I've seen it before in the code, but newer pay attention to this, now I know why smart devs use 'clock' together with local datetime. Very helpful. Please do more videos like this, together with the test example 😉
@abu-dukhan
@abu-dukhan 2 жыл бұрын
Maasha Allah, Nelson, you really are natural. May Allah increase you in knowledge and reward you abundantly. And I personally cannot thank you enough, because you transformed my life as a Java back-end developer, once again, JazaakAllahu Khair
@erickjhormanromero6905
@erickjhormanromero6905 2 жыл бұрын
Our Senior Java developer tought us to use LocaltTime.now() method to test but now i learned a new way of doing. i just need to undestand the reason and start using it. Thanks man
@soheilqalamkari2643
@soheilqalamkari2643 2 ай бұрын
It was wonderful.Thanks a lot✌
@Jumataev
@Jumataev Жыл бұрын
great , thanks for showing how to organise
@dataslid
@dataslid Жыл бұрын
Even when he said smash that like button only few people did, this is free golden contents and it costs nothing on your end.
@user-fz1nh3mt1c
@user-fz1nh3mt1c 2 жыл бұрын
amazing video that teaches me to be better
@svalyavasvalyava9867
@svalyavasvalyava9867 2 жыл бұрын
Thank you so much!
@user-sv3zv9cn9w
@user-sv3zv9cn9w 2 жыл бұрын
Thank you for your videos!! Could u make the video about where you need use the certain time class(LocaleDateTime, Instant, Date and etc) ?
@vietronaldo23w
@vietronaldo23w 2 жыл бұрын
great! it's helpful for me . thanks bro
@joke4ey431
@joke4ey431 Жыл бұрын
really good content, i came across this problem today, but now I know how to solve this :D
@mahmudulislam5303
@mahmudulislam5303 2 жыл бұрын
Great video as always
@franciscoruiz661
@franciscoruiz661 2 жыл бұрын
In my opinion, the best and practice way is create an DateProvider interface. Then we will use DI for own services, and in the tests we use mocks for DateProvider interface. For DateProvider implementation we use LocalDateTime api
@rollingdice
@rollingdice 2 жыл бұрын
thank u very much!!
@kelechidivine3350
@kelechidivine3350 Жыл бұрын
Nelson, I smashed the like button five times.
@dariofulci6549
@dariofulci6549 2 жыл бұрын
Thank you for all course. Can't wait for new interesting one. I hope to see a course which replicate system design of twitter, uber, facebook... using java, kafka, rabbitmq ect. This one Microservices and Distributed Systems is amazing.
@xixReact
@xixReact 2 жыл бұрын
thanks mate for all your videos, they are very helpful! PS can u pls send some of the heat back to Aus
@terrah33
@terrah33 2 жыл бұрын
Great video as usual! Would love some Go content as well :)
@flyingrecordofficial
@flyingrecordofficial 2 жыл бұрын
great job bro
@Another0neTime
@Another0neTime 2 жыл бұрын
Totally smahed that like button.
@luizcalazans6415
@luizcalazans6415 2 жыл бұрын
Awesome content
@wallysonruan
@wallysonruan Жыл бұрын
Suggestion: Try to scroll the screen in a way that the code to be added or removed always stays near the center of the page, that will help people that uses the closed caption to be able to see the code while also reading the captions. When you edit a code that is too close to the bottom of the view-port we can't see it because the captions will be overlaying it.
@alameenalameen7191
@alameenalameen7191 Жыл бұрын
Iam watching your video right now it inspires me please make regular videos pls bro😟😟😟😟
@angelg3642
@angelg3642 2 жыл бұрын
Great vid
@hamza_Techy
@hamza_Techy 2 жыл бұрын
Great!
@sangmin7648
@sangmin7648 2 жыл бұрын
I would also advise to use FixedClock implementation of Clock (which is a inner class of Clock) instead of mocking. Less mocking is always better, just call Clock.fixed()
@AviadShiber-taboola
@AviadShiber-taboola Жыл бұрын
agree, much better
@AaronEzekiel752
@AaronEzekiel752 2 жыл бұрын
always watching you
@hendhasnaoui9419
@hendhasnaoui9419 Жыл бұрын
You rock ❤😊
@user-oo9br5wx2u
@user-oo9br5wx2u 2 жыл бұрын
Yeah, it's cool stuff, but you can also use MockedStatic to mock LocalDateTime
@Mr.indian.justice.555
@Mr.indian.justice.555 Жыл бұрын
Hey @amigos , please try to make video on spring boot with antlr. Thanks ! 💕
@ahmadxrizvi
@ahmadxrizvi 2 жыл бұрын
Assalamualaikum, Please try to make videos on Android development. I love your videos.
@codertravel99
@codertravel99 Жыл бұрын
Hey hi Nelson it as awesome session thankyou to make a great session but can you please make a longer session on Date time because it is a complex concept thankyou again but if possible then please make a longer session specific on date time
@thekiterunner7082
@thekiterunner7082 2 жыл бұрын
Good....
@lenigaussgauss2428
@lenigaussgauss2428 2 жыл бұрын
Funny at starting 🤣
@sau2metat4nguoikhien72
@sau2metat4nguoikhien72 2 жыл бұрын
i have a question : if a java web dev so i should use what idj eclipse vscode or more ?
@programmieraufgaben8391
@programmieraufgaben8391 Жыл бұрын
nice !
@user-gx8qs3ov1m
@user-gx8qs3ov1m Жыл бұрын
Helpline📲📥⬆️ Questions can come in⬆️
@user-oc1ih4ez2c
@user-oc1ih4ez2c 2 жыл бұрын
@Amigoscode What's the progress bar do you use?
@erickjhormanromero6905
@erickjhormanromero6905 2 жыл бұрын
Can i get the link of the java docs where this is mentioned?
@didiwaytrooo
@didiwaytrooo Жыл бұрын
i am your brother from Egypt , slamo alikom my brother . i am big fan fro you and interested very much in your great videos and tutorials .do you have a UDEMY channel for courses bro ?. i am beginner in the field with java . go on allah with you
@nametsegothakadu4702
@nametsegothakadu4702 Жыл бұрын
Can you make a video tutorial on how to setup maven(and the problems that come with not setting up pom.xml correctly) and missing springboot plugins properly using Intellij ?. I have been struggling with errors regarding my plugins and I have surfed so many blogs for solutions but I still can't make my ide properly work without these errors whenever i download my plugins for my projects. Please when u can I'd widely appreciate it
@drakezen
@drakezen 2 жыл бұрын
Where is the stackoverflow link to the Java data/time description?
@ehsansasanian9653
@ehsansasanian9653 2 жыл бұрын
I guess you also need to configure Clock Bean in your app config. Otherwise you'd get NoSuchBeanDefinitionException
@Vvay7
@Vvay7 Жыл бұрын
can you talking about atomicreference
@helmigandi
@helmigandi 2 жыл бұрын
I got error "required a bean of type 'java.time.Clock' that could not be found, Consider defining a bean of type 'java.time.Clock' in your configuration." when Inject ("private final Clock clock") in my service but I did not see Configuration Class in the video?
@karamelkhalfouni4015
@karamelkhalfouni4015 2 жыл бұрын
I had the same problem. It seems like Spring expects a bean definition for the autowired Clock class. To solve that I added a class where I defined the bean. I looks like this : @Configuration public class ClockConfig { @Bean public Clock clock() { return Clock.systemDefaultZone(); } }
@wilkyarny3012
@wilkyarny3012 2 жыл бұрын
Hi there I smash the button 😂
@mxaix
@mxaix Жыл бұрын
Hi…Salam, do you know if there are any online internship programs available where people can work voluntarily(unpaid)?
@eugenesmith9940
@eugenesmith9940 Жыл бұрын
If token was expired at current date-time why it becomes valid if we add time?
@konstantindevelops131
@konstantindevelops131 2 жыл бұрын
And were is the SO link for the time instances?
@Kim-tr5op
@Kim-tr5op 2 жыл бұрын
u should put like and subscribe section at the end of the video
@sykexz6793
@sykexz6793 2 жыл бұрын
not everybody watches till the end
@Kim-tr5op
@Kim-tr5op 2 жыл бұрын
@@sykexz6793 my comment is based on the human psyche :P If u make a good vid and people stay to the end, then u have a much higher chance for people to like and subscribe.
@YasinNabi
@YasinNabi Жыл бұрын
This is a beautiful video... thumbs up ! subbed and liked .... a fellow creator.,
@scienc3tv
@scienc3tv 2 жыл бұрын
We're missing your "A Salaaaamo Alaykom" in the intro... Great video tho, thank you bro.
@top10channels31
@top10channels31 Жыл бұрын
Hi guys i am working on a project accidentally I deleted my table and schema sequence table both now spring jpa not creating my table getting errors I have used ddl-auto=update Plz help me mysql8
@adilwise
@adilwise 2 жыл бұрын
Hi Nelson, you missed "to" in the title.
@ishyo9220
@ishyo9220 2 жыл бұрын
Hello brother...🤟 How I will be became like you...🤔 I want to be like you man...😄 From where I should start learning advance Java ... I had done my core Java ... Please guide me & others like me who are following you 💡 my brother help us... 😋
@francksgenlecroyant
@francksgenlecroyant 2 жыл бұрын
Hey, search for the video which talks about roadmap made by Amigoscode, I'm sure it will help
@pepeclovis6247
@pepeclovis6247 Жыл бұрын
hello can i take some classes from you
@billybob1620
@billybob1620 5 ай бұрын
Or you can just use a date provider class which is arguably a lot more simple
@Az1zdev
@Az1zdev 2 жыл бұрын
Hello guys, who knows Amigos IDE theme name?
@precious8326
@precious8326 Жыл бұрын
the discord doesn't work ; (
@ahmedmk534
@ahmedmk534 2 жыл бұрын
How do you show usages conters ?
@cdhagen
@cdhagen 2 жыл бұрын
Newest IntelliJ version does this automatically. Search for „inlay hints“ in the preferences to turn on/off. I personally find it distracting and annoying. 😉
@ahmedmk534
@ahmedmk534 2 жыл бұрын
@@cdhagen I have the latest version but still dont have them displayed. I think they are useful when working on bugs/tests and debuging :)
@KolomiecSergeyK
@KolomiecSergeyK 2 жыл бұрын
Hello, could you please give link to stackoverflow
@amigoscode
@amigoscode 2 жыл бұрын
stackoverflow.com/questions/32437550/whats-the-difference-between-instant-and-localdatetime
@assemkhaled3715
@assemkhaled3715 2 жыл бұрын
how to destroy jwt token on logout in spring boot
@Salihmanisali
@Salihmanisali 2 жыл бұрын
Please could you provide the GitHub address
@8d_songs
@8d_songs 2 жыл бұрын
can you tell us about your religion background did you born as a muslim or you converted to islam
@himanshuu_21
@himanshuu_21 2 жыл бұрын
1st view
@Coding.Practice
@Coding.Practice Жыл бұрын
जय श्री राम।
@teddy6326
@teddy6326 Жыл бұрын
Can you teach slowly because sometimes you so fast .
@fahrican9708
@fahrican9708 Жыл бұрын
This explanation is amazing, I was doing LocalDateTime.now() always wrong
@volodymyr.kushnir
@volodymyr.kushnir 2 жыл бұрын
Why adding clock if there is simpler way: private final DateTimeService dateTimeService; usage: dateTimeService.now() public class DateTimeService { public Date now() { return new Date();} // make your own implementation } p.s. also it seems your code exposes too much data out of confirmation token -> encapsulation issue.
@franciscoripoll63
@franciscoripoll63 2 жыл бұрын
excelent video. Your setUp method is not necessary, you just have to put the following annotation at the class level: "@ExtendWith(MockitoExtension.class)".
@erickjhormanromero6905
@erickjhormanromero6905 2 жыл бұрын
he also needs to create a When call into the method
@franciscoripoll63
@franciscoripoll63 2 жыл бұрын
​@@erickjhormanromero6905 yes, then only mock with clock. OpenMocks line and constructor is not necessary over there
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 51 МЛН
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,7 МЛН
MISS CIRCLE STUDENTS BULLY ME!
00:12
Andreas Eskander
Рет қаралды 19 МЛН
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 28 МЛН
low battery 🪫
0:10
dednahype
Рет қаралды 1,4 МЛН
Kumanda İle Bilgisayarı Yönetmek #shorts
0:29
Osman Kabadayı
Рет қаралды 2,3 МЛН
İĞNE İLE TELEFON TEMİZLEMEK!🤯
0:17
Safak Novruz
Рет қаралды 1,4 МЛН
iPhone 15 Pro Max vs IPhone Xs Max  troll face speed test
0:33