CompatUtil.java

1
package fr.sii.ogham.email.sendgrid.v4.sender.impl.sendgrid.compat;
2
3
import fr.sii.ogham.core.util.ClasspathUtils;
4
5
/**
6
 * {@code sendgrid-java} 4.3.0 has classes declared in package
7
 * {@code com.sendgrid.helpers.mail} but in the generated JAR, the classes are
8
 * compiled into package {@code com.sendgrid}. This issue has been fixed since
9
 * 4.4.0.
10
 * 
11
 * However, Spring Boot 2.1.x uses {@code sendgrid-java} 4.3.0...
12
 * 
13
 * Therefore, this class helps to avoid classpath issues and uses the available
14
 * classes.
15
 * 
16
 * @author Aurélien Baudet
17
 *
18
 */
19
public final class CompatUtil {
20
	/**
21
	 * {@code sendgrid-java} package version 4.3.0 declares some classes in
22
	 * package {@code com.sendgrid.helpers.mail.objects} (according to source
23
	 * folder structure). However, the {@code package} declaration in every of
24
	 * these classes points to {@code com.sendgrid}.
25
	 * 
26
	 * This creates {@link ClassNotFoundException}s when trying to run Ogham
27
	 * with {@code sendgrid-java} v4.3.0. As it is a mistake from SendGrid, we
28
	 * could simply take the next version that fixes the issue. But some Spring
29
	 * Boot versions (like 2.1.x) has direct dependency to {@code sendgrid-java}
30
	 * v4.3.0. So we must provide a compatibility fix in order to make it work
31
	 * with older Spring Boot versions.
32
	 * 
33
	 * The default factory provides either
34
	 * {@link CorrectPackageNameCompatFactory} for {@code sendgrid-java} v4.4+
35
	 * and WrongPackageNameCompatFactory for {@code sendgrid-java} v4.3.0.
36
	 * 
37
	 * @return the factory that will provide instances of objects
38
	 */
39
	public static CompatFactory getDefaultCompatFactory() {
40 3 1. getDefaultCompatFactory : negated conditional → NO_COVERAGE
2. getDefaultCompatFactory : negated conditional → SURVIVED
3. getDefaultCompatFactory : negated conditional → KILLED
		if (ClasspathUtils.exists("com.sendgrid.Email")) {
41 1 1. getDefaultCompatFactory : replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::getDefaultCompatFactory → NO_COVERAGE
			return createV430CompatFactoryInstance();
42
		}
43 4 1. getDefaultCompatFactory : negated conditional → NO_COVERAGE
2. getDefaultCompatFactory : negated conditional → KILLED
3. getDefaultCompatFactory : negated conditional → KILLED
4. getDefaultCompatFactory : negated conditional → KILLED
		if (ClasspathUtils.exists("com.sendgrid.helpers.mail.objects.Email")) {
44 3 1. getDefaultCompatFactory : replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::getDefaultCompatFactory → NO_COVERAGE
2. getDefaultCompatFactory : replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::getDefaultCompatFactory → SURVIVED
3. getDefaultCompatFactory : replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::getDefaultCompatFactory → KILLED
			return new CorrectPackageNameCompatFactory();
45
		}
46
		throw new IllegalStateException("Can't provide a valid CompatFactory based on sendgrid-java classpath");
47
	}
48
49
	private static CompatFactory createV430CompatFactoryInstance() {
50
		try {
51
			Class<?> klass = Class.forName("fr.sii.ogham.email.sendgrid.v4.sender.impl.sendgrid.compat.WrongPackageNameCompatFactory");
52 1 1. createV430CompatFactoryInstance : replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::createV430CompatFactoryInstance → NO_COVERAGE
			return (CompatFactory) klass.newInstance();
53
		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
54
			throw new IllegalStateException("Failed to create compatibility factory for sendgrid-java v4.3.0", e);
55
		}
56
	}
57
	
58
	private CompatUtil() {
59
		super();
60
	}
61
}

Mutations

40

1.1
Location : getDefaultCompatFactory
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getDefaultCompatFactory
Killed by : none
negated conditional → SURVIVED

3.3
Location : getDefaultCompatFactory
Killed by : oghamsendgridv4.ut.SendGridV4SenderTest.reportViolations()
negated conditional → KILLED

41

1.1
Location : getDefaultCompatFactory
Killed by : none
replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::getDefaultCompatFactory → NO_COVERAGE

43

1.1
Location : getDefaultCompatFactory
Killed by : oghamall.it.configuration.SendGridConfigurationTest.asDeveloperIDefineApiKeyUsingProperties(oghamall.it.configuration.SendGridConfigurationTest)
negated conditional → KILLED

2.2
Location : getDefaultCompatFactory
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : getDefaultCompatFactory
Killed by : oghamsendgridv4.ut.SendGridV4SenderTest.reportViolations()
negated conditional → KILLED

4.4
Location : getDefaultCompatFactory
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2FreeMarkerAutoConfigurationTests.oghamWithFreemarkerAutoConfigWithoutWebContextShouldUseSpringFreemarkerConfiguration(oghamspringbootv2autoconfigure.it.OghamSpringBoot2FreeMarkerAutoConfigurationTests)
negated conditional → KILLED

44

1.1
Location : getDefaultCompatFactory
Killed by : oghamsendgridv4.it.SendGridTranslationTest.forBasicTextEmail
replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::getDefaultCompatFactory → KILLED

2.2
Location : getDefaultCompatFactory
Killed by : none
replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::getDefaultCompatFactory → NO_COVERAGE

3.3
Location : getDefaultCompatFactory
Killed by : none
replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::getDefaultCompatFactory → SURVIVED

52

1.1
Location : createV430CompatFactoryInstance
Killed by : none
replaced return value with null for fr/sii/ogham/email/sendgrid/v4/sender/impl/sendgrid/compat/CompatUtil::createV430CompatFactoryInstance → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM