Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for classes with only private constructor exclude mocks #22

Merged
merged 9 commits into from Mar 2, 2024

Conversation

huangliang992
Copy link
Contributor

for classes with only private constructor exclude mocks,

for example tested class like

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.unicom.tdt.admin.model.exception.ResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Base64Utils;

import javax.crypto.Cipher;

import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Map;

public class AesUtil {

    private AesUtil(){
        throw new IllegalStateException("Utility class");
    }
    private static Logger logger = LoggerFactory.getLogger(AesUtil.class);

    private static final String KEY_ALGORITHM = "AES";

    private static final String DEFAULT_CIPHER_ALGORITHM = "AES/GCM/NoPadding";


    public static String encrypt(String content, String password) {
    }

    public static String encrypt(Object object,String field, String password) {
    }

    public static String decrypt(String content, String password) {
    }

    public static void decrypt(Object object,String field,String privateKey) throws Exception {
     }
}

the generated test class is , the mock should be removed

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;

import static org.mockito.Mockito.*;

public class AesUtilTest44 {
    @Mock
    Logger logger;
    @InjectMocks
    AesUtil aesUtil;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testEncrypt() throws Exception {
        String result = AesUtil.encrypt("content", "password");
        Assert.assertEquals("replaceMeWithExpectedResult", result);
    }

    @Test
    public void testEncrypt2() throws Exception {
        String result = AesUtil.encrypt("object", "field", "password");
        Assert.assertEquals("replaceMeWithExpectedResult", result);
    }

    @Test
    public void testDecrypt() throws Exception {
        String result = AesUtil.decrypt("content", "password");
        Assert.assertEquals("replaceMeWithExpectedResult", result);
    }

    @Test
    public void testDecrypt2() throws Exception {
        AesUtil.decrypt("object", "field", "privateKey");
    }
}

// Generated with love by TestMe :) Please report issues and submit feature requests at:
// http://weirddev.com/forum#!/testme

@CLAassistant
Copy link

CLAassistant commented Feb 27, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ huangliang992
❌ 南京-黄亮


南京-黄亮 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@yaronyam
Copy link
Member

yaronyam commented Mar 1, 2024

Good use case. BTW for integration test case, I would prefer a clean example with field that is not static and not initialized inline - in both cases the field should not be mocked for other reasons. Thanks

Copy link
Member

@yaronyam yaronyam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see tests being added ❤️ looks good. posted 2 comments

@yaronyam yaronyam merged commit 9a6529f into wrdv:master Mar 2, 2024
0 of 5 checks passed
@yaronyam
Copy link
Member

yaronyam commented Mar 2, 2024

@huangliang992 - Published this feature as an EAP version for now - https://plugins.jetbrains.com/plugin/9471-testme/versions/eap/497405.
Will be included in the next stable version.
Thanks for contributing!
EAP versions installation instructions

@huangliang992 huangliang992 deleted the feature/field-mock-check branch March 8, 2024 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants