5252import org .openhab .core .persistence .HistoricItem ;
5353import org .openhab .core .persistence .ModifiablePersistenceService ;
5454import org .openhab .core .persistence .PersistenceItemInfo ;
55- import org .openhab .core .persistence .PersistenceItemNotFoundException ;
5655import org .openhab .core .persistence .PersistenceServiceRegistry ;
5756import org .openhab .core .persistence .dto .ItemHistoryDTO ;
5857import org .openhab .core .persistence .dto .ItemHistoryDTO .HistoryDataBean ;
@@ -137,6 +136,7 @@ public String getName() {
137136 public void testGetPersistenceItemData () {
138137 ItemHistoryDTO dto = pResource .createDTO (pServiceMock , "testItem" , null , null , 1 , 10 , false , false );
139138
139+ assertNotNull (dto );
140140 assertThat (Integer .parseInt (dto .datapoints ), is (5 ));
141141 assertThat (dto .data , hasSize (5 ));
142142
@@ -168,6 +168,7 @@ public void testGetPersistenceItemData() {
168168 public void testGetPersistenceItemDataWithBoundery () {
169169 ItemHistoryDTO dto = pResource .createDTO (pServiceMock , "testItem" , null , null , 1 , 10 , true , false );
170170
171+ assertNotNull (dto );
171172 assertThat (Integer .parseInt (dto .datapoints ), is (7 ));
172173 assertThat (dto .data , hasSize (7 ));
173174 }
@@ -179,6 +180,7 @@ public void testGetPersistenceItemDataWithItemState() throws ItemNotFoundExcepti
179180
180181 ItemHistoryDTO dto = pResource .createDTO (pServiceMock , "testItem" , null , null , 1 , 10 , false , true );
181182
183+ assertNotNull (dto );
182184 assertThat (Integer .parseInt (dto .datapoints ), is (6 ));
183185 assertThat (dto .data , hasSize (6 ));
184186 assertThat (dto .data .get (dto .data .size () - 1 ).state , is ("0" ));
@@ -191,6 +193,7 @@ public void testGetPersistenceItemDataWithItemStateUndefined() throws ItemNotFou
191193
192194 ItemHistoryDTO dto = pResource .createDTO (pServiceMock , "testItem" , null , null , 1 , 10 , false , true );
193195
196+ assertNotNull (dto );
194197 assertThat (Integer .parseInt (dto .datapoints ), is (5 ));
195198 assertThat (dto .data , hasSize (5 ));
196199 }
@@ -202,6 +205,7 @@ public void testGetPersistenceItemDataWithItemStateNull() throws ItemNotFoundExc
202205
203206 ItemHistoryDTO dto = pResource .createDTO (pServiceMock , "testItem" , null , null , 1 , 10 , false , true );
204207
208+ assertNotNull (dto );
205209 assertThat (Integer .parseInt (dto .datapoints ), is (5 ));
206210 assertThat (dto .data , hasSize (5 ));
207211 }
@@ -214,6 +218,7 @@ public void testGetPersistenceItemDataWithBoundaryAndItemStateButNoItemStateRequ
214218
215219 ItemHistoryDTO dto = pResource .createDTO (pServiceMock , "testItem" , null , null , 1 , 10 , true , true );
216220
221+ assertNotNull (dto );
217222 assertThat (Integer .parseInt (dto .datapoints ), is (7 ));
218223 assertThat (dto .data , hasSize (7 ));
219224 assertThat (dto .data .get (dto .data .size () - 1 ).state , not ("0" ));
@@ -232,14 +237,14 @@ public void testPutPersistenceItemData() throws ItemNotFoundException {
232237 }
233238
234239 @ Test
235- public void testGetPersistenceItemInfoNotImplemented () throws ItemNotFoundException , UnsupportedOperationException {
240+ public void testGetPersistenceItemInfoNotImplemented () throws UnsupportedOperationException {
236241 // Test method not supported
237242 when (pServiceMock .getItemInfo ()).thenThrow (UnsupportedOperationException .class );
238243 assertThrows (UnsupportedOperationException .class , () -> pResource .createDTO (pServiceMock , null ));
239244 }
240245
241246 @ Test
242- public void testGetPersistenceItemInfo () throws PersistenceItemNotFoundException , UnsupportedOperationException {
247+ public void testGetPersistenceItemInfo () throws UnsupportedOperationException {
243248 when (pServiceMock .getItemInfo ()).thenReturn (Set .of (new PersistenceItemInfo () {
244249
245250 @ Override
@@ -265,6 +270,7 @@ public String getName() {
265270
266271 // Testing with a specific implementation
267272 Set <PersistenceItemInfoDTO > dto = pResource .createDTO (pServiceMock , null );
273+ assertNotNull (dto );
268274 PersistenceItemInfoDTO itemInfo = dto .iterator ().next ();
269275 assertThat (itemInfo .name (), is (ITEM ));
270276 assertThat (itemInfo .earliest (),
@@ -275,8 +281,7 @@ public String getName() {
275281 }
276282
277283 @ Test
278- public void testGetPersistenceItemInfoWithItemDefault ()
279- throws PersistenceItemNotFoundException , UnsupportedOperationException {
284+ public void testGetPersistenceItemInfoWithItemDefault () throws UnsupportedOperationException {
280285 when (pServiceMock .getItemInfo (any (), any ())).thenReturn (new PersistenceItemInfo () {
281286
282287 @ Override
@@ -302,6 +307,7 @@ public String getName() {
302307
303308 // This is testing the default behavior when no specific implementation exists in the service
304309 Set <PersistenceItemInfoDTO > dto = pResource .createDTO (pServiceMock , ITEM );
310+ assertNotNull (dto );
305311 assertThat (dto .size (), is (1 ));
306312 PersistenceItemInfoDTO itemInfo = dto .iterator ().next ();
307313 assertThat (itemInfo .name (), is (ITEM ));
@@ -312,8 +318,7 @@ public String getName() {
312318 }
313319
314320 @ Test
315- public void testGetPersistenceItemInfoWithItem ()
316- throws PersistenceItemNotFoundException , UnsupportedOperationException {
321+ public void testGetPersistenceItemInfoWithItem () throws UnsupportedOperationException {
317322 when (pServiceMock .getItemInfo (any (), any ())).thenAnswer (invocation -> {
318323 String firstArg = invocation .getArgument (0 );
319324 String secondArg = invocation .getArgument (1 );
@@ -345,11 +350,13 @@ public String getName() {
345350 };
346351 });
347352
348- // Testing when ITEM does not exist and getItemInfo returns null
349- assertThrows (PersistenceItemNotFoundException .class , () -> pResource .createDTO (pServiceMock , "NotFoundTest" ));
353+ // Testing when ITEM does not exist
354+ Set <PersistenceItemInfoDTO > dto = pResource .createDTO (pServiceMock , "NotFoundTest" );
355+ assertNull (dto );
350356
351357 // Test when specific implementation exists and no alias is used
352- Set <PersistenceItemInfoDTO > dto = pResource .createDTO (pServiceMock , ITEM );
358+ dto = pResource .createDTO (pServiceMock , ITEM );
359+ assertNotNull (dto );
353360 assertThat (dto .size (), is (1 ));
354361 PersistenceItemInfoDTO itemInfo = dto .iterator ().next ();
355362 assertThat (itemInfo .name (), is (ITEM ));
@@ -363,6 +370,7 @@ public String getName() {
363370 when (persistenceServiceConfigurationRegistryMock .get (any ())).thenReturn (persistenceServiceConfigurationMock );
364371 when (persistenceServiceConfigurationMock .getAliases ()).thenReturn (Map .of (ITEM , "TestAlias" ));
365372 dto = pResource .createDTO (pServiceMock , ITEM );
373+ assertNotNull (dto );
366374 assertThat (dto .size (), is (1 ));
367375 itemInfo = dto .iterator ().next ();
368376 assertThat (itemInfo .name (), is ("TestAlias" ));
0 commit comments