How to connect to mysql from nodejs, with ES6 promise
Introduction I had to develop a small automation to query some old mysql data…
March 17, 2017
While writing JUnit test cases, we encounter cases like we want to initialize a class, and that class instantiate a new class object which is an external entity class like FTP class or AWS service class. We do not want to initializethat external class object. In that cases, we would want to mock those objects.
We can mock any object in JUnit test code. But, what about the objects that are instantiated using new inside that class.
class AmazonS3ServiceImpl {
private AmazonS3Client amazonS3Client;
public AmazonS3ServiceImpl() {
this.amazonS3Client = new AmazonS3Client();
}
}
Here, we would want to inject our mock object for AmazonS3Client, but how?
You need to annotate your JUnit test class with “@PrepareForTest” and mention both the classes you want to mock. See below:
@RunWith(PowerMockRunner.class)
@PrepareForTest({AmazonS3Client.class, AmazonS3ServiceImpl.class})
public class S3Test {
@Before
public void setup() throws Exception {
AmazonS3Client amazonS3Client = PowerMockito.mock(AmazonS3Client.class);
PowerMockito.whenNew(AmazonS3Client.class).withParameterTypes(AWSCredentials.class).
withArguments(Mockito.any()).thenReturn(amazonS3Client); //code for mocking Impl class
}
}
So, we have informed Mocking system that whenever you are trying to instantiate a new object of AmazonS3Client class with AWSCredentials type parameter, return our mock object.
Introduction I had to develop a small automation to query some old mysql data…
Introduction In previous posts, we saw how to build FIPS enabled Openssl, and…
Introduction To give some context, I have two python files. (Both in same folder…
This library is ES6, promise compatible. Or, in your package.json file, include…
Introduction I got my seo backlink work done from a freelancer. It was like 300…
Introduction This post has the complete code to send email through smtp server…
Introduction In a normal email sending code from python, I’m getting following…
Introduction In one of my app, I was using to talk to . I have used some event…
Introduction So you have a Django project, and want to run it using docker image…
Introduction It is very important to introduce few process so that your code and…
Introduction In this post, we will see a sample Jenkin Pipeline Groovy script…