fe9d6893593e62ff6bf078c3979b5f454b0ef14c
[nemo.git] / nemo-tools / sandbox / src / test / java / org / opendaylight / nemo / tool / sandbox / EasyCliTest.java
1 /*
2  * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.nemo.tool.sandbox;
9
10 import junit.framework.TestCase;
11 import org.junit.Before;
12 import org.junit.Test;
13
14 import static org.junit.Assert.*;
15 import asg.cliche.Shell;
16 import asg.cliche.ShellFactory;
17
18 import java.io.IOException;
19 import java.lang.reflect.Field;
20 import static org.mockito.Mockito.*;
21
22 /**
23  * Created by zhangmeng on 2016/1/14.
24  */
25 public class EasyCliTest extends TestCase {
26     private EasyCli easyCli;
27     @Before
28     public void setUp() throws Exception {
29         easyCli = new EasyCli("1","2","3");
30     }
31
32     @Test
33     public void testAdd() throws Exception {
34         easyCli.add("4");
35     }
36
37     @Test
38     public void testRun() throws Exception {
39         Field field = EasyCli.class.getDeclaredField("shell");
40         field.setAccessible(true);
41
42         Shell shell = mock(Shell.class);
43
44         field.set(easyCli,shell);
45         doNothing().when(shell).commandLoop();
46         easyCli.run();
47         verify(shell).commandLoop();
48     }
49 }