Further cleanups of code
[yangtools.git] / yang / yang-common / src / test / java / org / opendaylight / yangtools / yang / common / RpcResultBuilderTest.java
index 2ff4fb5e5c7a259020a132fd768960d5bd84adba..45991b2e285a871aefc0e06c46eb314f6543dadb 100644 (file)
@@ -8,15 +8,15 @@
 
 package org.opendaylight.yangtools.yang.common;
 
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
@@ -35,7 +35,7 @@ public class RpcResultBuilderTest {
         assertNotNull( "getErrors returned null", result.getErrors() );
         assertEquals( "getErrors size", 0, result.getErrors().size() );
 
-        result = RpcResultBuilder.<String>success( "bar" ).build();
+        result = RpcResultBuilder.success( "bar" ).build();
         verifyRpcResult( result, true, "bar" );
     }
 
@@ -84,7 +84,7 @@ public class RpcResultBuilderTest {
                 .withWarning( ErrorType.RPC, "in-use", "message", "my-app-tag", "my-info", cause )
                 .build();
 
-        RpcResult<String> copy = RpcResultBuilder.<String>from( result )
+        RpcResult<String> copy = RpcResultBuilder.from( result )
                 .withError( ErrorType.PROTOCOL, "error message" )
                 .build();
         verifyRpcResult( copy, true, "foo" );
@@ -111,6 +111,31 @@ public class RpcResultBuilderTest {
                         "error message", null, null, null );
     }
 
+    @Test
+    public void testErrors() {
+        final RpcResultBuilder<Object> rpcResultBuilder = RpcResultBuilder.status(true);
+        final RpcError rpcErrorShort = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg");
+        final RpcError rpcErrorLong = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg", "applicationTag",
+                "info", null);
+        final RpcError rpcErrorShortWarn = RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "tag", "msg");
+        final RpcError rpcErrorLongWarn = RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "tag", "msg",
+                "applicationTag",
+                "info", null);
+        rpcResultBuilder.withRpcError(rpcErrorShort);
+        final RpcResult<Object> rpcResult = rpcResultBuilder.build();
+        final RpcResultBuilder<RpcResult<Object>> rpcResultRpcResultBuilder1 = RpcResultBuilder.success
+                (rpcResultBuilder);
+        final RpcResultBuilder<RpcResult<Object>> rpcResultRpcResultBuilder2 = rpcResultRpcResultBuilder1.withResult
+                (rpcResultBuilder);
+
+        assertEquals(rpcErrorShort.getErrorType(), rpcErrorShortWarn.getErrorType());
+        assertEquals(rpcErrorLong.getErrorType(), rpcErrorLongWarn.getErrorType());
+        assertEquals(rpcResultRpcResultBuilder1, rpcResultRpcResultBuilder2);
+        assertNotNull(rpcResultBuilder.buildFuture());
+        assertEquals("RpcResult [successful=true, result=null, errors=[RpcError [message=msg, severity=ERROR, " +
+                "errorType=RPC, tag=tag, applicationTag=null, info=null, cause=null]]]", rpcResult.toString());
+    }
+
     @SuppressWarnings("unchecked")
     @Test
     public void testSerialization() throws Exception {
@@ -142,9 +167,9 @@ public class RpcResultBuilderTest {
                 "error message", "my-app-tag", "my-info", cause );
     }
 
-    void verifyRpcError( RpcResult<?> result, int errorIndex, ErrorSeverity expSeverity,
-            ErrorType expErrorType, String expTag, String expMessage, String expAppTag,
-            String expInfo, Throwable expCause ) {
+    void verifyRpcError( final RpcResult<?> result, final int errorIndex, final ErrorSeverity expSeverity,
+            final ErrorType expErrorType, final String expTag, final String expMessage, final String expAppTag,
+            final String expInfo, final Throwable expCause ) {
 
         List<RpcError> errors = new ArrayList<>( result.getErrors() );
         assertTrue( "Expected error at index " + errorIndex + " not found",
@@ -159,8 +184,8 @@ public class RpcResultBuilderTest {
         assertEquals( "getCause", expCause, error.getCause() );
     }
 
-    void verifyRpcResult( RpcResult<?> result, boolean expSuccess, Object expValue ) {
+    void verifyRpcResult( final RpcResult<?> result, final boolean expSuccess, final Object expValue ) {
         assertEquals( "isSuccessful", expSuccess, result.isSuccessful() );
         assertEquals( "getResult", expValue, result.getResult() );
     }
-}
+}
\ No newline at end of file