-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-1542: Fix regression about creating attributes with null value.
- Loading branch information
1 parent
2afadfc
commit d9a0688
Showing
4 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...core/src/test/java/org/eclipse/leshan/core/link/lwm2m/attributes/LwM2mAttributesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.core.link.lwm2m.attributes; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.eclipse.leshan.core.link.attributes.InvalidAttributeException; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class LwM2mAttributesTest { | ||
|
||
private static Stream<Arguments> supportNullAttributes() throws InvalidAttributeException { | ||
return Stream.of(// | ||
Arguments.of(LwM2mAttributes.MINIMUM_PERIOD), // | ||
Arguments.of(LwM2mAttributes.MAXIMUM_PERIOD), // | ||
Arguments.of(LwM2mAttributes.EVALUATE_MINIMUM_PERIOD), // | ||
Arguments.of(LwM2mAttributes.EVALUATE_MAXIMUM_PERIOD), // | ||
Arguments.of(LwM2mAttributes.LESSER_THAN), // | ||
Arguments.of(LwM2mAttributes.GREATER_THAN), // | ||
Arguments.of(LwM2mAttributes.STEP) // | ||
); | ||
} | ||
|
||
@ParameterizedTest(name = "Tests {index} : {0}") | ||
@MethodSource("supportNullAttributes") | ||
public void check_attribute_can_be_created_with_null_value(LwM2mAttributeModel<?> model) | ||
throws InvalidAttributeException { | ||
LwM2mAttribute<?> attribute = LwM2mAttributes.create(model); | ||
assertNotNull(attribute); | ||
assertFalse(attribute.hasValue()); | ||
assertNull(attribute.getValue()); | ||
attribute = LwM2mAttributes.create(model, null); | ||
assertNotNull(attribute); | ||
assertFalse(attribute.hasValue()); | ||
assertNull(attribute.getValue()); | ||
} | ||
|
||
private static Stream<Arguments> doesntSupportNullAttributes() throws InvalidAttributeException { | ||
return Stream.of(// | ||
Arguments.of(LwM2mAttributes.DIMENSION), // | ||
Arguments.of(LwM2mAttributes.ENABLER_VERSION), // | ||
Arguments.of(LwM2mAttributes.OBJECT_VERSION), // | ||
Arguments.of(LwM2mAttributes.SHORT_SERVER_ID), // | ||
Arguments.of(LwM2mAttributes.SERVER_URI)// | ||
); | ||
} | ||
|
||
@Disabled | ||
@ParameterizedTest(name = "Tests {index} : {0}") | ||
@MethodSource("doesntSupportNullAttributes") | ||
// TODO implement this correctly : https://github.com/eclipse-leshan/leshan/issues/1542 | ||
public void check_attribute_can_not_be_created_with_null_value(LwM2mAttributeModel<?> model) { | ||
assertThrows(InvalidAttributeException.class, () -> LwM2mAttributes.create(model)); | ||
assertThrows(InvalidAttributeException.class, () -> LwM2mAttributes.create(model, null)); | ||
} | ||
} |