Skip to content

Commit 9e8f591

Browse files
gzhao9DaanHoogland
andauthored
Refactoring org.apache.cloudstack.network.tungsten.service (#8098)
* Refactoring reduces mock cloning of TungstenAnswer * Apply suggestions from code review Great suggestions, thanks a lot! Co-authored-by: dahn <[email protected]> * Rename CreateMockTungstenAnswer to MockTungstenAnswerFactory * Updated parameter to camel case. * Revised in accordance with the latest update * Replace all `\r` with `\n`. * Replace all \r with \n. * temp for re-uploading * reupdate * update line ending * update ling ending * Add static methods to avoid duplicate creation of new --------- Co-authored-by: dahn <[email protected]>
1 parent 2f97e3b commit 9e8f591

File tree

4 files changed

+188
-278
lines changed

4 files changed

+188
-278
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.network.tungsten.service;
18+
19+
import org.apache.cloudstack.network.tungsten.agent.api.TungstenAnswer;
20+
21+
import static org.mockito.Mockito.mock;
22+
import static org.mockito.Mockito.when;
23+
24+
public class MockTungstenAnswerFactory {
25+
26+
TungstenAnswer tungstenAnswer;
27+
MockTungstenAnswerFactory(boolean returnResult){
28+
tungstenAnswer=mock(TungstenAnswer.class);
29+
when(tungstenAnswer.getResult()).thenReturn(returnResult);
30+
}
31+
TungstenAnswer get() {
32+
return tungstenAnswer;
33+
}
34+
public static TungstenAnswer get(boolean returnResult){
35+
TungstenAnswer tungstenAnswers = new MockTungstenAnswerFactory(returnResult).get();
36+
return tungstenAnswers;
37+
}
38+
}

0 commit comments

Comments
 (0)