Java Code Examples for org.objenesis.Objenesis#newInstance()

The following examples show how to use org.objenesis.Objenesis#newInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractStoreOperationControllerIntegrationTest.java    From evernote-rest-webapp with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
	this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();

	// prepare mocks
	this.noteStoreOperations = mock(NoteStoreOperations.class, withSettings().extraInterfaces(StoreClientHolder.class));
	this.userStoreOperations = mock(UserStoreOperations.class, withSettings().extraInterfaces(StoreClientHolder.class));

	// To work around getClass() method to return actual store-client class for parameter name discovery, use
	// objenesis to create actual impl class instead of mocking.
	// mockito cannot mock getClass() since this method is final.
	Objenesis objenesis = new ObjenesisStd();
	UserStoreClient userStoreClient = (UserStoreClient) objenesis.newInstance(UserStoreClient.class);
	NoteStoreClient noteStoreClient = (NoteStoreClient) objenesis.newInstance(NoteStoreClient.class);
	when(((StoreClientHolder) userStoreOperations).getStoreClient()).thenReturn(userStoreClient);
	when(((StoreClientHolder) noteStoreOperations).getStoreClient()).thenReturn(noteStoreClient);

	when(this.evernote.userStoreOperations()).thenReturn(userStoreOperations);
	when(this.evernote.noteStoreOperations()).thenReturn(noteStoreOperations);
}
 
Example 2
Source File: NotSerializableClass.java    From objenesis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isCompliant(Objenesis objenesis) {
   try {
      objenesis.newInstance(NotSerializable.class);
   }
   catch(ObjenesisException e) {
      return true;
   }
   return false;
}
 
Example 3
Source File: TCK.java    From objenesis with Apache License 2.0 5 votes vote down vote up
private void runCandidate(Reporter reporter, Class<?> candidate, Objenesis objenesis, Candidate.CandidateType type) {
   try {
      Object instance = objenesis.newInstance(candidate);
      boolean success = instance != null && instance.getClass() == candidate;
      reporter.result(type, success);
   }
   catch(Exception e) {
      reporter.exception(type, e);
   }
}
 
Example 4
Source File: ReadExternalNotCalled.java    From objenesis with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(ReadExternalAndAll.class);
   return called.isEmpty();
}
 
Example 5
Source File: ExtendsSerializableClass.java    From objenesis with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(ExtendsSerializable.class);
   return called.isEmpty();
}
 
Example 6
Source File: SerializableClass.java    From objenesis with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(IsSerializable.class);
   return called.isEmpty();
}
 
Example 7
Source File: ReadObjectNotCalled.java    From objenesis with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(ReadObjectAndAll.class);
   return called.isEmpty();
}
 
Example 8
Source File: ExtendsNotSerializableParentClass.java    From objenesis with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(ExtendsNotSerializable.class);
   return called.size() == 1 && called.get(0).equals(NotSerializableClass.NotSerializable.class.getSimpleName() + ".<init>");
}