Commit 1578adb2 authored by Ole Voldsæter's avatar Ole Voldsæter
Browse files

added a unit test

parent b910e6be
......@@ -38,6 +38,17 @@
<artifactId>jetty-servlets</artifactId>
<version>8.1.10.v20130312</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
<properties>
......
package com.nesstar.rest.result_object_makers;
import com.nesstar.api.*;
import junit.framework.Assert;
import org.junit.Test;
import java.util.Iterator;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.*;
/**
* @author Ole Voldsæter
*/
public class MetadataMakerTest {
@Test
public void testGetVariableMetadata() throws Exception {
Server server = mock(Server.class);
Bank<Variable> varBank = mock(Bank.class);
Variable variable = mock(Variable.class);
DdiList<SimpleDdiElement<String>> list = mock(DdiList.class);
SimpleDdiElement<String> elt1 = mock(SimpleDdiElement.class);
SimpleDdiElement<String> elt2 = mock(SimpleDdiElement.class);
Iterator<SimpleDdiElement<String>> iterator = mock(Iterator.class);
when(varBank.get(anyObject())).thenReturn(variable);
when(server.getBank(Variable.class)).thenReturn(varBank);
when(variable.getElement(eq("./concept"))).thenReturn(list);
when(list.iterator()).thenReturn(iterator);
when(iterator.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
when(iterator.next()).thenReturn(elt1).thenReturn(elt2);
when(elt1.toString()).thenReturn("concept1");
when(elt2.toString()).thenReturn("concept2");
Object o = MetadataMaker.getVariableMetadata("id", server);
assertNotNull(o);
assertTrue("o should be a String", o instanceof String);
assertFalse("o should not be empty", ((String) o).isEmpty());
verify(variable, times(33)).getElement(anyString());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment