From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master

---
 jnpf-eln/jnpf-eln-biz/src/test/java/jnpf/elnService/impl/ElnDianziJiluMubanServiceImplTest.java |   87 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/jnpf-eln/jnpf-eln-biz/src/test/java/jnpf/elnService/impl/ElnDianziJiluMubanServiceImplTest.java b/jnpf-eln/jnpf-eln-biz/src/test/java/jnpf/elnService/impl/ElnDianziJiluMubanServiceImplTest.java
new file mode 100644
index 0000000..9ceaa5f
--- /dev/null
+++ b/jnpf-eln/jnpf-eln-biz/src/test/java/jnpf/elnService/impl/ElnDianziJiluMubanServiceImplTest.java
@@ -0,0 +1,87 @@
+package jnpf.elnService.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import jnpf.elnEntity.ElnMubanFileVo;
+import jnpf.elnMapper.ElnDianziJiluMubanMapper;
+import jnpf.exception.DataException;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.lang.reflect.Constructor;
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class ElnDianziJiluMubanServiceImplTest {
+
+    @Test
+    public void marksProductionConstructorForSpringInjection() throws Exception {
+        Constructor<ElnDianziJiluMubanServiceImpl> constructor =
+                ElnDianziJiluMubanServiceImpl.class.getConstructor(ElnDianziJiluMubanMapper.class);
+
+        Assert.assertNotNull(constructor.getAnnotation(Autowired.class));
+    }
+
+    @Test
+    public void returnsFirstFileForCurrentTenant() {
+        AtomicReference<String> tenant = new AtomicReference<>();
+        AtomicReference<String> item = new AtomicReference<>();
+        ElnDianziJiluMubanMapper mapper = (requestPage, tenantId, jianyanXiangmu) -> {
+            assertEquals(1L, requestPage.getCurrent());
+            assertEquals(1L, requestPage.getSize());
+            Assert.assertFalse(requestPage.searchCount());
+            tenant.set(tenantId);
+            item.set(jianyanXiangmu);
+            return resultPage(
+                    "[{\"fileId\":\"file-1.docx\",\"name\":\"璁板綍妯℃澘.docx\","
+                            + "\"url\":\"/api/file/Image/annex/file-1.docx\",\"fileSize\":128,"
+                            + "\"fileExtension\":\"docx\",\"fileVersionId\":null}]");
+        };
+
+        ElnMubanFileVo result = new ElnDianziJiluMubanServiceImpl(mapper, () -> "tenant-1")
+                .getFile("item-1");
+
+        assertEquals("tenant-1", tenant.get());
+        assertEquals("item-1", item.get());
+        assertEquals("file-1.docx", result.getFileId());
+        assertEquals("璁板綍妯℃澘.docx", result.getName());
+        assertEquals(Long.valueOf(128), result.getFileSize());
+    }
+
+    @Test
+    public void returnsNullWhenTemplateOrArrayIsEmpty() {
+        assertNull(new ElnDianziJiluMubanServiceImpl(
+                (page, tenant, item) -> resultPage(), () -> "tenant-1").getFile("item-1"));
+        assertNull(new ElnDianziJiluMubanServiceImpl(
+                (page, tenant, item) -> resultPage("[]"), () -> "tenant-1").getFile("item-1"));
+    }
+
+    @Test(expected = DataException.class)
+    public void rejectsMalformedFileJson() {
+        new ElnDianziJiluMubanServiceImpl(
+                (page, tenant, item) -> resultPage("not-json"),
+                () -> "tenant-1").getFile("item-1");
+    }
+
+    @Test(expected = DataException.class)
+    public void rejectsJsonNull() {
+        new ElnDianziJiluMubanServiceImpl(
+                (page, tenant, item) -> resultPage("null"),
+                () -> "tenant-1").getFile("item-1");
+    }
+
+    @Test(expected = DataException.class)
+    public void rejectsNullFirstFile() {
+        new ElnDianziJiluMubanServiceImpl(
+                (page, tenant, item) -> resultPage("[null]"),
+                () -> "tenant-1").getFile("item-1");
+    }
+
+    private static IPage<String> resultPage(String... records) {
+        return new Page<String>(1, 1, false).setRecords(Arrays.asList(records));
+    }
+}

--
Gitblit v1.8.0