Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7811351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:07:49+00:00 2026-06-02T04:07:49+00:00

I have simple test case: @Test public void test() throws Exception{ TableElement table =

  • 0

I have simple test case:

@Test
public void test() throws Exception{
       TableElement table = mock(TableElement.class);
       table.insertRow(0);
}

Where TableElement is GWT class with method insertRow defined as:

public final native TableRowElement insertRow(int index);

When I launch test I’m getting:

java.lang.UnsatisfiedLinkError: com.google.gwt.dom.client.TableElement.insertRow(I)Lcom/google/gwt/dom/client/TableRowElement;
    at com.google.gwt.dom.client.TableElement.insertRow(Native Method)

Which as I believe is related with insertRow method being native. Is there any way or workaround to mock such methods with Mockito?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:07:52+00:00Added an answer on June 2, 2026 at 4:07 am

    Mockito itself doesn’t seem to be able to mock native methods according to this Google Group thread. However you do have two options:

    1. Wrap the TableElement class in an interface and mock that interface to properly test that your SUT calls the wrapped insertRow(...) method. The drawback is the extra interface that you need to add (when GWT project should’ve done this in their own API) and the overhead to use it. The code for the interface and the concrete implementation would look like this:

      // the mockable interface
      public interface ITableElementWrapper {
          public void insertRow(int index);
      }
      
      // the concrete implementation that you'll be using
      public class TableElementWrapper implements ITableElementWrapper {
          TableElement wrapped;
      
          public TableElementWrapper(TableElement te) {
              this.wrapped = te;
          }
      
          public void insertRow(int index) {
              wrapped.insertRow(index);
          }
      }
      
      // the factory that your SUT should be injected with and be 
      // using to wrap the table element with
      public interface IGwtWrapperFactory {
          public ITableElementWrapper wrap(TableElement te);
      }
      
      public class GwtWrapperFactory implements IGwtWrapperFactory {
          public ITableElementWrapper wrap(TableElement te) {
              return new TableElementWrapper(te);
          }
      }
      
    2. Use Powermock and it’s Mockito API extension called PowerMockito to mock the native method. The drawback is that you have another dependency to load into your test project (I’m aware this may be a problem with some organizations where a 3rd party library has to be audited first in order to be used).

    Personally I’d go with option 2, as GWT project is not likely to wrap their own classes in interfaces (and it is more likely they have more native methods that needs to be mocked) and doing it for yourself to only wrap a native method call is just waste of your time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple test project just to test the IncludeExceptionDetailInFaults behavior. public class
I have a simple JUnit test in Eclipse. public class HelloTest extends TestCase {
public class NewTest extends SeleneseTestCase { public static Test suite() throws Exception { TestSuite
I have a simple test for maven plugin: public class SimpleMavenTest extends AbstractMojoTestCase {
A simple test case to demonstrate my 2 problems: public class Numbers { private
I have written a simple test class for Play! 2.0: public class TestLogin {
I have a simple unit test case (extensive question here ) on a configuration
I have a simple Action class which I want to unit test: package com.gam.action.test;
I have prepared a simple test case demonstrating my problem. It is just 1
I have a simple test application (C# console application) that does an HTTP GET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.