[*] Quarkus + junit5 + jacoco < /li>
Идея MVN Build (MVN Clean Install) < /li>
jdk 11 < /li>
jacoco 0.8.7 < /li>
< /ul>
, когда я использую @ent at in in in in in in in in in i in in in i in in in in i in in in in in in in in in in in in in in code. Ошибка:
Данные выполнения для класса com/supply/services/dbdictionaryservicettt не совпадают.
Код: Выделить всё
package com.supply.core.dao.entity.ref;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(
name = "REF_TEST"
)
public class RefTest extends PanacheEntityBase {
@Id
@Column(
name = "REFTESTID"
)
public Long refTestId;
@Column(
name = "ALPHACODE"
)
public String alphaCode;
@Column(
name = "CODE"
)
public String code;
public RefTest() {
}
public static RefTest findByAlphaCode(String alphaCode) {
return (RefTest)find("alphaCode", new Object[]{alphaCode}).firstResult();
}
}
Код: Выделить всё
package com.supply.services;
import com.supply.core.dao.entity.ref.RefTest;
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class DBDictionaryServiceTtt {
public boolean fake() {
return true;
}
public String getCode(String alphaCode) {
RefTest refTest = RefTest.findByAlphaCode(alphaCode);
if (refTest == null) {
return null;
}
return refTest.code;
}
}
Код: Выделить всё
package com.supply.services;
import com.supply.core.dao.entity.ref.RefTest;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import io.quarkus.panache.mock.PanacheMock;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import com.supply.services.DBDictionaryServiceTtt;
import javax.inject.Inject;
@QuarkusTest
class TttServiceTest {
@Inject
DBDictionaryServiceTtt dbDictionaryServiceTtt;
@BeforeEach
void testInitProduct() {
PanacheMock.mock(PanacheEntityBase.class);
PanacheMock.mock(RefTest.class);
PanacheMock.doNothing().when(RefTest.class).persist();
RefTest refTest = new RefTest();
refTest.code = "123";
Mockito.when(RefTest.findByAlphaCode(Mockito.any())).thenReturn(refTest);
}
@Test
void testService() {
Assertions.assertTrue(dbDictionaryServiceTtt.fake(), "test");
}
@AfterEach
void clearData() {
RefTest.deleteAll();
}
}
< /code>
Я пытался использовать: < /p>
[list]
PanacheMock[*] Использовать EntityManager без Panachemock (@inject entitymanager em; ... em.persist (reftest); em.flush ();)
[*]
Код: Выделить всё
MockitoAnnotations.openMocks(this);[/list]
Подробнее здесь: https://stackoverflow.com/questions/797 ... -not-match
Мобильная версия