2017-06-07 9 views
0
Java 8 

私はMockitoを使ってテストしたい次のコンストラクタを持っています。例外をスローするかどうかを見るためにコンストラクタを嘲笑

リポジトリにnullが渡された場合、テストで例外がスローされるようにします。

public PresenterImp(@Nonnull IRepository repository, IScheduler scheduler) { 
     super(schedulerFactory); 
     this.repository = Preconditions.checkNotNull(repository); 
} 

これを行うにはどうすればよいでしょうか?

+2

「null」を渡すだけです... –

答えて

1

のようにそれを行うことができます任意の提案のための

@Before 
public void setup() throws Exception {
    
    repository = Mockito.mock(IRepository.class);
      
    iScheduler = Mockito.mock(IScheduler.class); 
    viewContract = Mockito.mock(ViewContract.class);
      
    presenter = new PresenterImp(repository, iScheduler);
  
       optInNotificationPresenter.attachView(viewContract); 
} 

感謝を:私のプレゼンターはモックではないように、私は、私は次のようにします。..私の設定では

を使用することはできません。

@Test(expected=NullPointerException.class) 
public void testNullCheck() throws Exception 
      new PresenterImp(null, mock); 

    } 
関連する問題