Cleanup asserts in GeneratedTypesTest 57/95557/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 25 Mar 2021 10:55:54 +0000 (11:55 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 25 Mar 2021 10:56:44 +0000 (11:56 +0100)
We are making some iffy assert choices here, leading to errors rather
than test failures. Refactor asserts a bit, so we have logically safe
code.

Change-Id: I2673ab81a93eae718a2cd8e99e67af91c8cd03e7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/GeneratedTypesTest.java

index 277302040b43b2dad1d7f0bcdef33829ec6577a4..3dfc742af6907bb3d02be78a9ac4b2fd2d5bfef8 100644 (file)
@@ -223,19 +223,6 @@ public class GeneratedTypesTest {
         String getSimpleListKeyMethodReturnTypeName = "";
         String getListChildContainerMethodReturnTypeName = "";
 
-        int listKeyClassPropertyCount = 0;
-        String listKeyClassPropertyName = "";
-        String listKeyClassPropertyTypeName = "";
-        boolean listKeyClassPropertyReadOnly = false;
-
-        int hashMethodParameterCount = 0;
-        String hashMethodParameterName = "";
-        String hashMethodParameterReturnTypeName = "";
-
-        int equalMethodParameterCount = 0;
-        String equalMethodParameterName = "";
-        String equalMethodParameterReturnTypeName = "";
-
         for (final Type type : genTypes) {
             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
                 final GeneratedType genType = (GeneratedType) type;
@@ -281,20 +268,19 @@ public class GeneratedTypesTest {
                 final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
                 final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
 
-                listKeyClassCount++;
-                listKeyClassPropertyCount = properties.size();
-                listKeyClassPropertyName = properties.get(0).getName();
-                listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName();
-                listKeyClassPropertyReadOnly = properties.get(0).isReadOnly();
+                assertEquals("Unexpected key", 0, listKeyClassCount++);
+                assertEquals(1, properties.size());
+                assertEquals("listKey", properties.get(0).getName());
+                assertEquals("Byte", properties.get(0).getReturnType().getName());
+                assertTrue(properties.get(0).isReadOnly());
 
-                hashMethodParameterCount = hashProps.size();
-                hashMethodParameterName = hashProps.get(0).getName();
-                hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();
-
-                equalMethodParameterCount = equalProps.size();
-                equalMethodParameterName = equalProps.get(0).getName();
-                equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();
+                assertEquals(1, hashProps.size());
+                assertEquals("listKey", hashProps.get(0).getName());
+                assertEquals("Byte", hashProps.get(0).getReturnType().getName());
 
+                assertEquals(1, equalProps.size());
+                assertEquals("listKey", equalProps.get(0).getName());
+                assertEquals("Byte",  equalProps.get(0).getReturnType().getName());
             }
         }
 
@@ -305,17 +291,6 @@ public class GeneratedTypesTest {
         assertEquals(1, getSimpleListKeyMethodCount);
         assertEquals(1, listKeyClassCount);
 
-        assertEquals(1, listKeyClassPropertyCount);
-        assertEquals("listKey", listKeyClassPropertyName);
-        assertEquals("Byte", listKeyClassPropertyTypeName);
-        assertTrue(listKeyClassPropertyReadOnly);
-        assertEquals(1, hashMethodParameterCount);
-        assertEquals("listKey", hashMethodParameterName);
-        assertEquals("Byte", hashMethodParameterReturnTypeName);
-        assertEquals(1, equalMethodParameterCount);
-        assertEquals("listKey", equalMethodParameterName);
-        assertEquals("Byte", equalMethodParameterReturnTypeName);
-
         assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);
 
         assertEquals(1, getListChildContainerMethodCount);
@@ -355,9 +330,7 @@ public class GeneratedTypesTest {
                     compositeKeyListKeyCount++;
                     final List<GeneratedProperty> properties = genTO.getProperties();
                     for (final GeneratedProperty prop : properties) {
-                        if (prop.getName().equals("key1")) {
-                            compositeKeyListKeyPropertyCount++;
-                        } else if (prop.getName().equals("key2")) {
+                        if (prop.getName().equals("key1") || prop.getName().equals("key2")) {
                             compositeKeyListKeyPropertyCount++;
                         }
                     }