Skip to content
Advertisement

Tag: testing

Why my test passes without a bearer token

I have a simple Spring app. But I don’t understand why the test passes without the need of a bearer token. Here is the controller: Security Configuration: In order to setup the security configs for tests I’m using: So my test class looks like this: If I change the autority in the test to something like ‘foo-user’ the response becomes

How to mock my service using Mockito framework

Hello I have struglling write a mock test according to my following method below; my code below; my yml configuration below; my service below; I have a created PropertySourceResolver class and my test class below; I like to change my code according to test scenarios like ; when … then return any idea? thank you. Answer To make this simpler

How to make an integration test with one transaction for all database calls and rollback it afterwards?

I’m, writing an integration test, annotated with @SpringBootTest. Suppose I create some product using pure SQL from my test, call calculation service that do some calculations based on it, and it calls another service to save those calculation results in different tables. What I need is to rollback all the changes made after test is finished. I read different questions,

Mockito – verify a method call with expected argument but ignore certain fields

I am mocking a class called EmailSender which has a method sendEmail() that takes in an argument of class Email. I am trying to verify that my mockEmailSender will call the sendEmail function once with the expected Email class as such: verify(mockEmailSender, times(1)).sendEmail(expectedEmail) I am initializing the expected Email object like the follow Email expectedEmail = Email.builder().setRecipients(//example list).setTitle(“Test title”).setBody(//make this

How to test Service method with ModelMapper call

I’m writing some Unit Tests for my Service class, specifically, an update method that does exactly that, update an Entity with the given data from a request. The problem is, I’m using ModelMapper to map the request data to the entity and when the test goes through the mapping statement it doesn’t actually call the modelMapper but the mock ….

How to load json data in java?

I’m quite new to API testing, I am wondering how to best and simple load some body? I created simple pojo classes, but i am having problems with nested json. ex: Then, in classes I used: and then in test class I am trying to use it, but have no idea how. But I have no idea how to declare

Advertisement