Why my code drops this error? - java

Hello im using eclipse with JavaSE-1.6, JUnit 4 and selenium-java 2.43.0.
Idont know why it doesnt works.
I try to change the firefoxdriver for chromedriver or iedriver but itś the same.
My Code
package test;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import Pages.Register;
public class RegisterNewUser {
Register register;
WebDriver driver;
#Before
public void initiation(){
this.driver = new FirefoxDriver();
this.register = new Register (driver);
this.driver.get("http//:e-farmacity.com/customer/account/create/");
}
#Test
public void testRegisterNewUser() {
register.getLastNameTextBox().sendKeys("NewUser");
register.getLastNameTextBox().sendKeys("Test");
register.getEmailTextBox().sendKeys("test#lyracons.com");
register.getDayTextBox().sendKeys("09");
register.getMonthTextBox().sendKeys("03");
register.getYearTextBox().sendKeys("1993");
List<WebElement> listOfGender = register.getGenderRadioButtons();
listOfGender.get(0).click();
register.getDniTextBox().sendKeys("38146782");
register.getTelTextBox().sendKeys("221123123");
register.getPassTextBox().sendKeys("prueba123");
register.getConfirmPassTextBox().sendKeys("prueba123");
register.getSuscriptionRadioButton().click();
register.getSubmitButton().click();
}
#After
public void finishtest() {
this.driver.close();
}
}
The error
java.lang.NoClassDefFoundError: com/google/common/base/Function
at test.RegisterNewUser.initiation(RegisterNewUser.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:622)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
... 25 more
java.lang.NullPointerException
at test.RegisterNewUser.finishtest(RegisterNewUser.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:622)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

Itś fixed, it was that i havnt got the selenium-server-standalone.
THankyou

Related

java.lang.IllegalAccessError: tried to access method org.openqa.selenium.remote.http.ClientConfig

I'm getting this error when I try to run a testCase from eclipse:
I'm using eclipse, Appium-Server-GUI-windows-1.22.3-4, Android 4:
java-client-8.2.1.jar
I need your help:
Code:
#Test
public void test() throws MalformedURLException{
//fail("Not yet implemented");
URL link = new URL("http://127.0.0.1:4723/wd/hub");
//AndroidDriver driver;
DesiredCapabilities capacidades = new DesiredCapabilities();
capacidades.setCapability("platformName", "Android");
capacidades.setCapability("appium:platformVersion", "13");
capacidades.setCapability("appium:appActivity", "com.BancaxcxcxActivity");
capacidades.setCapability("appium:appPackage", "com.banxxxv40");
capacidades.setCapability("appium:deviceName", "sdk_gphone64_x86_64");
// Inicio driver
AndroidDriver driver = new AndroidDriver(link ,capacidades);
}
error:
java.lang.IllegalAccessError: tried to access method org.openqa.selenium.remote.http.ClientConfig.<init>
(Ljava/net/URI;
Ljava/time/Duration;
Ljava/time/Duration;
Lorg/openqa/selenium/remote/http/Filter;
Ljava/net/Proxy;Lorg/openqa/selenium/Credentials;)
V from class io.appium.java_client.AppiumClientConfig
at io.appium.java_client.AppiumClientConfig.<init>(AppiumClientConfig.java:62)
at io.appium.java_client.AppiumClientConfig.defaultConfig(AppiumClientConfig.java:79)
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:109)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:117)
at consolePruebasTest.TestMovil.test(TestMovil.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
I'm trying to do a initial conecction with emulated device.
java-client 8.2.1 has issues with resolving dependencies: https://github.com/appium/java-client/issues/1812
Upgrade to 8.3.0 and check.

Return ImmutableSet from JMock'd object causes UndeclaredThrowableException

Here's my unit test that I expect to pass:
import static org.junit.Assert.assertEquals;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.junit.Test;
import com.google.common.collect.ImmutableSet;
public class JMockTest {
#Test
public void test() {
Mockery mockery = new Mockery();
final Foo foo = mockery.mock(Foo.class);
mockery.checking(new Expectations() {{
oneOf(foo).bar(); will(returnValue(ImmutableSet.<Long>of()));
}});
ImmutableSet<Long> result = foo.bar();
assertEquals(ImmutableSet.<Long>of(), result);
}
interface Foo {
ImmutableSet<Long> bar();
}
}
However, it throws this error instead:
java.lang.reflect.UndeclaredThrowableException
at $Proxy3.bar(Unknown Source)
at JMockTest$1.<init>(JMockTest.java:17)
at JMockTest.test(JMockTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalAccessException: Class org.jmock.internal.ReturnDefaultValueAction can not access a member of class com.google.common.collect.ImmutableSet with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
at java.lang.Class.newInstance(Class.java:436)
at org.jmock.internal.ReturnDefaultValueAction.collectionOrMapInstanceFor(ReturnDefaultValueAction.java:87)
at org.jmock.internal.ReturnDefaultValueAction.invoke(ReturnDefaultValueAction.java:77)
at org.jmock.internal.InvocationToExpectationTranslator.invoke(InvocationToExpectationTranslator.java:20)
at org.jmock.internal.FakeObjectMethods.invoke(FakeObjectMethods.java:38)
at org.jmock.lib.JavaReflectionImposteriser$1.invoke(JavaReflectionImposteriser.java:33)
... 26 more
It seems that JMock is internally attempting to instantiate an ImmutableSet, even though I provided one for it.
See ReturnDefaultValueAction:
private Object collectionOrMapInstanceFor(Class<?> returnType) throws Throwable {
return returnType.isInterface() ? instanceForCollectionType(returnType) : returnType.newInstance();
}
returnType.isInterface() is false b/c it's a ImmutableSet, so JMock calls ImmutableSet.newInstance(), which fails b/c ImmutableSet does not have an accessible constructor.
I assume that people other than me have mocked interfaces that return guava immutable collection objects before, or interfaces that return classes with no visible constructor. How do you deal with this in JMock?
EDIT: This is JMock 2.6.0
EDIT2: This works in JMock 2.8.2!
This seems like a bug with your version of JMock, 2.6.0, as you've described it. Upgrade to the latest, currently 2.8.2. The issue will go away.

Mockito: how to stub inherited methods

I am using Jetty client API on my application and I want to test my following code using Junit and Mockito:
public void startHttpClient(){
try {
httpClient.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
My test case is the following:
#Mock HttpClient httpClient;
#Before
public void setUp() {
MockitoAnnotations.initMocks(this);
testBackend= new TestBackend(3,httpClient);
}
#Test
public void teststartHttpClient() throws Exception {
testBackend.startHttpClient();
assertNotNull(httpClient);
verify(httpClient,atLeastOnce()).start();
}
The problem is that the Mock HttpClient inherit the start() method from AbstractLifeCycle, so I got a null pointer exception on the AbstractLifeCycle class:
How can I mock the inherited method start() call fot the class HttpClient?
The Exception got:
java.lang.NullPointerException
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:61)
at test.TestBackendTest.teststartHttpClient(TestBackendTest.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Mockito can't mock an interface?

I'm having difficulties understanding how to mock/stub an interface with Mockito.
This simple scenario...
public interface Adder
{
int add(int a, int b);
}
public class Calculator
{
Adder _adder;
public Calculator(Adder adder)
{
_adder = adder;
}
public int add(int a, int b)
{
return _adder.add(a, b);
}
}
public class MockitoTester
{
#Test
public void can_mock()
{
Adder adder = mock(Adder.class);
Calculator sut = new Calculator(adder);
assertThat(sut).isNotNull();
}
}
Is giving me this error...
java.lang.NoClassDefFoundError: net/bytebuddy/dynamic/scaffold/subclass/ConstructorStrategy
at org.mockito.internal.creation.bytebuddy.CachingMockBytecodeGenerator.<init>(CachingMockBytecodeGenerator.java:20)
at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.<init>(ByteBuddyMockMaker.java:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:33)
at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:12)
at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:11)
at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:23)
at org.mockito.internal.MockitoCore.<init>(MockitoCore.java:44)
at org.mockito.Mockito.<clinit>(Mockito.java:1101)
at com.jnericks.testutils.MockitoTester.can_mock(MockitoTester.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.ClassNotFoundException: net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 40 more
Mockito depends on the artifact net.bytebuddy:byte-buddy. See this POM definition from the Maven repositories. Make sure you get the mockito-all artifact which includes all dependencies in one Jar.
If you are using Maven, then it should automatically resolve the dependency when using mockito-core. You can run mvn dependency:tree on the project to see the hierarchy of your project's dependencies.

Strange NullPointerException in JUnit

I am running a simple JUnit test. The test is:
private HangmanModel model;
private WordsToGuess word;
public void setUp()
{
model = new HangmanModel();
word = new WordsToGuess();
}
#Test
public void addWordAndChoose()
{
WordsToGuess testWord = new WordsToGuess("ahoy");
model.addWord(testWord); <---- NullPointerException
String foundWord = model.randomWord();
assertEquals("Not found the word", testWord, foundWord);
}
In WordsToGuess, the constructor is:
public WordsToGuess(String w)
{
word = w;
}
In HangmanModel, the addWord method is:
private ArrayList<WordsToGuess> words;
words = new ArrayList<WordsToGuess>();
public void addWord(WordsToGuess w)
{
words.add(w);
}
This is a REALLY weird NullPointerException since everything should run perfectly fine. It is copied almost word for word from a similar project. Here is the Stack trace:
java.lang.NullPointerException
at testing.HangmanModelTest.addWordAndChoose(HangmanModelTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
The #Before annotation is required before the setup method for JUnit 4
#Before
public void setUp() {
...
}

Categories

Resources