0

I am trying to test using maven test mvn test but getting uses unchecked or unsafe operations . I did check for different threads found in stackoverflow on the maven not running tests issues first here as I got There are no tests to run initially and after adding the version to my pom.xml i got unchecked or unsafe operattions warning so followed this link and checked for List and it looks good in my Test Class like

List<String> names = new ArrayList<String>();

but still getting below warning when i use maven-compiler-plugin 3.5.1

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
                                                                     
[INFO] ------------------------------------------------------------------------
[INFO] Building myaccount-service 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ myaccount-service ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\git-workspace\myaccount-service\src\main\resources
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ myaccount-service ---
[INFO] Compiling 1 source file to D:\git-workspace\myaccount-service\target\classes
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ myaccount-service ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\git-workspace\myaccount-service\src\test\resources
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ myaccount-service ---
[INFO] Compiling 2 source file to D:\git-workspace\myaccount-service\target\test-classes
[INFO] /D:/git-workspace/myaccount-service/src/test/java/DetailServiceTest.java: D:\git-workspace\myaccount-service\src\test\java\DetailServiceTest.java uses unchecked or unsafe operations.
[INFO] /D:/git-workspace/myaccount-service/src/test/java/DetailServiceTest.java: Recompile with -Xlint:unchecked for details.
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ myaccount-service ---
[INFO] Surefire report directory: D:\git-workspace\myaccount-service\target\surefire-reports

getting below warning when i use maven-compiler-plugin 2.3.2

[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ myaccount-service ---
[INFO] Compiling 1 source file to D:\git-workspace\myaccount-service\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ esg-edge-service-myaccount ---
[INFO] Surefire report directory: D:\git-workspace\myaccount-service\target\surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Is there something wrong with my maven compiler version? or what i am doing wrong here. Please help me.

EDITED

Added my DetailServiceTest.java

package com.mydomain.ws;

import com.mydomain.component.ProductComponent;
import com.mydomain.model.myaccount.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;


public class DetailServiceTest {

@InjectMocks
private DetailService detailService;

@Mock
private ProductComponent productComponentMock;
@Mock
private ProductResponse response ;
@Mock
private List<Product> lstProduct ;
@Mock
private Product myProduct ;

@Mock
ProductDetailsRequest productDetailsRequest ;
ProductDetailRequestRoot productDetailRequestRoot = new ProductDetailRequestRoot();

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
}

@After
public void tearDown() throws Exception {

}

@Test
public void getShouldReturnEmptyProductForNonExistingIDNName() {
    List<String> productNames= new ArrayList<String>();
    productNames.add("1554353");
    productNames.add("4252322947");
    String productId = "932937184";
    
    when(productComponentMock.readAccount(anyString(), anyList())).thenReturn(lstProduct);
    ProductDetailService.get("", "", productId, true, productNames);
    verify(productComponentMock, times(1)).readAccount(anyString(), anyList());
    assertEquals(0, lstProduct.size());
}

@Test
public void getShouldReturnProductForExistingproductIdNMsdnTest()  {
    String productId = "932937184";
    List<String> productName = new ArrayList<String>();
    productName.add("4252322947");

    Product Productstub = new Product();
    Productstub.setProductId("932937184");
    Productstub.setProductName("4252322947");

    List<Product> rProduct = new ArrayList<>();  //
    rProduct.add(Productstub);


    when(productComponentMock.readAccount(productId, productName)).thenReturn(rProduct);
    ProductDetailService.get("", "", productId, true, productName);
    verify(productComponentMock, times(1)).readAccount(productId, productName);
    List<Product> result = productComponentMock.readAccount(productId, productName) ;
    assertEquals(1, rProduct.size());
    assertEquals(result, rProduct);
    response.setProducts(rProduct);
    verify(response, times(1)).setProducts(rProduct);


}


}

When I run this Test class i get all 2 tests passed in console.

CORRECTED

Deleted below snippet from pom.xml file now my tests are running

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <includes>
                    <include>**/Test.java</include>
                </includes>
            </configuration>
        </plugin>

Results :

Tests run: 9, Failures: 0, Errors: 0, Skipped: 0
Community
  • 1
  • 1
user1653027
  • 789
  • 1
  • 16
  • 38
  • 1
    Can you post `DetailServiceTest` code? Did you use `@Test` on test methods? (NB: lines with `[INFO]` are not errors, they are informatives..) –  Jun 14 '16 at 04:59
  • Thanks @RC for your time. I have added my DetailServiceTest, it has two Tests. yes I use @Test on test methods. Yes, `INFO` are useful but in output it gives `Test runs: 0, Failures : 0` that means maven not picking up my tests right? – user1653027 Jun 14 '16 at 16:22
  • Yes, junit is not detecting your test –  Jun 14 '16 at 17:08

0 Answers0