lundi 1 juin 2015

initializeError while Unit-testing Mock objects with Mockito in Xtend

I'm trying to run this unit test, I'm currently using Xtend over Java in order to read the code easily. The test consist on an admin who must verify a user in order to add it or not to the current repository. I want to make that admin a mock object in order to verify if the user has send correctly the method "generateProfile", which do the following

class User{
  @Accessors
  repositoryAdministrator admin
  
  def generateProfile{
    admin.add(this)
  }
the method add is the following:
class repositoryAdministrator{
  @Accessors List<User> objects
  @Accessors List<User> usersToValidate
  
  def add(User user){
    usersToValidate.add(user)
    }

This is the test i want to run using the lib Mockito

@RunWith(MockitoJUnitRunner)
class MockitoTests{

val lala = new User()  
  
@Mock
repositoryAdministrator fakeAdmin

@Before
def void init(){
        MockitoAnnotations.initMocks(this)
  }

@Test
def validationTest(){
                 
        lala.admin = fakeAdmin
        lala.generateProfile
         
        Mockito.verify(fakeAdmin).add(lala)
  }
}

I have imported correctly the libraries, I'm working on an Eclipse IDE, and when i run the test I keep on getting initializationError.

How do I properly initialize a mock object using Mockito? Sorry for my English

Aucun commentaire:

Enregistrer un commentaire