精华内容
下载资源
问答
  • 在Mockito中打桩(即stub)有两种方法when(...).thenReturn(...)和doReturn(...).when(...)。这两个方法在大部分情况下都是可以相互替换的,但是在使用了Spies对象(@Spy注解),而不是mock对象(@Mock注解)的情况下他们...

    在Mockito中打桩(即stub)有两种方法when(...).thenReturn(...)和doReturn(...).when(...)。这两个方法在大部分情况下都是可以相互替换的,但是在使用了Spies对象(@Spy注解),而不是mock对象(@Mock注解)的情况下他们调用的结果是不相同的(目前我只知道这一种情况,可能还有别的情形下是不能相互替换的)。

    ● when(...) thenReturn(...)会调用真实的方法,如果你不想调用真实的方法而是想要mock的话,就不要使用这个方法。

    ● doReturn(...) when(...) 不会调用真实方法

    下面我写一个简单的单元测试来验证一下。

    1.被测试类

    public classMyclass {publicString methodToBeTested(){returnfunction();

    }publicString function(){throw newNullPointerException();

    }

    }

    2.单元测试

    @RunWith(MockitoJUnitRunner.class)public classMyclassTest {

    @SpyprivateMyclass myclass;

    @Testpublic voidtest(){//when(myclass.methodToBeTested()).thenReturn("when(...)thenReturn(...)");

    doReturn("doReturn(...)when(...)").when(myclass).methodToBeTested();

    String str=myclass.methodToBeTested();

    System.out.println(str);

    }

    }

    测试结果

    1.使用when(...).thenReturn(...),抛出了异常。

    2e822fd59d706b3efa60d9aeea406909.png

    2.doReturn(...).when(...),测试通过

    5d9b0985d30f3f56091f2e45563da1bf.png

    展开全文
  • doReturn().when()与when().thenReturn()

    千次阅读 2021-02-26 12:08:48
    mock()与spy()想要使用题目中的方法,必须得是一个mock的对象,而这可以通过上面两种方法生成,先来看看他两的区别:有一个类Aclass A {public int add(int a , int b) {return a + b;}}此时生成两个对象...

    在昨天的汇报中,潘老师觉得讲的偏离了中心,在讲解了一番了以后,让我重新修改,但我觉得那篇文章若要改成这个题目,改动颇大,所以有了这篇文章。

    mock()与spy()

    想要使用题目中的方法,必须得是一个mock的对象,而这可以通过上面两种方法生成,先来看看他两的区别:

    有一个类A

    class A {

    public int add(int a , int b) {

    return a + b;

    }

    }

    此时生成两个对象

    A a = new A();

    A a1 = Mockito.mock(A.class);

    A a2 = mockito.spy(a);

    此时,通过mock生成的对象,会拥有以前的对象的所有方法,但是方法中都没有了功能,就比如上面的a1对应的类可以理解下面这样

    A1 extend A {

    pubic int add(int a, int b) {

    return null;

    }

    }

    而a2是同过调用clone()复制的,正常看来就和一个普通的对象一模一样,只是他的方法能够进行模拟。

    两种模拟方法

    doReturn().when()是无副作用的。

    when().thenReturn()是有副作用的

    上面是比较官方的说法,用实际的例子来理解一下,

    Mockito.when(a2.add(1,2 )).thenReturn(5);

    此时上面的方法中,会先执行a + b,即 1 + 2, 结果本应是3,但由于后面的thenReturn ,所以调用该方法时,实际的返回值是5。

    而若是用另一种方法

    Mockito.doReturn(5).when(a2).add(1,2);

    此时,就不会执行a+b的操作,而会直接返回5。

    看到这想必也明白了所谓的副作用,若是执行里面的方法时,难免会产生影响,比如抛出异常等。

    展开全文
  • 区别的to do和doing用法的小技巧

    千次阅读 2020-12-19 08:30:56
    ① 只能加 to do 的动词1. want to do sth. 想要做某事I want to buy a new computer this afternoon.我想今天下午买台新电脑。2. would like to do sth.想要做某事I would like to invite you to come to my ...

    ① 只能加 to do 的动词

    1. want to do sth. 想要做某事

    I want to buy a new computer this afternoon.

    我想今天下午买台新电脑。

    2. would like to do sth.想要做某事

    I would like to invite you to come to my birthday party this Saturday.

    我想邀请你这周六来我的聚会。

    3. wish to do sth. 希望做某事

    I wish to live on the moon one day.

    我希望有一天在月球上生活。

    4. help to do sth. 帮助做某事

    I often help to do some chores at home.

    我在家经常帮着做家务。

    5. hope to do sth. 希望做某事

    I hope to have a good rest this weekend.

    我希望这周末好好休息一下。

    6. learn to do sth. 学会做某事

    He finally learned to play the piano with the help of the teacher.

    在老师的帮助下,他最终学会了弹钢琴。

    7. manage to do sth. 设法做成某事

    They managed to escape the fire yesterday.

    昨天他们设法逃脱了火灾。

    8. offer to do sth. 主动提出做某事

    Never offer to teach fish to swim.

    别在强人面前逞能。

    9. plan to do sth. 计划做某事

    He plans to travel around the world.

    他计划要周游世界。

    10. afford to do sth. 负担得起做某事(时间或金钱方面)

    We can’t afford to go abroad this summer.

    今年夏天我们没有足够的钱出国。

    11. agree to do sth. 做某事

    He agreed to do it at once.

    他同意立刻行动。

    12. arrange to do sth.安排做某事

    I arrange to wash clothes tomorrow morning.

    我安排好明天上午洗衣服。

    13. ask to do sth. 要求做某事

    The boy asks to go to school by bike.

    这个男孩要求骑自行车去上学。

    14. beg to do sth. 恳求做某事

    He begged not to be put into prison.

    他祈求不要被关进监狱。

    15. care to do sth. 愿意/喜欢做某事

    16. choose to do sth. 选择做某事

    He chose to believe what she had said.

    他选择相信她说的话。

    17. decide to do sth. 决定做某事

    She has decided to travel all over the world.

    她已经决定周游世界了。

    18. demand to do sth. 要求做某事

    19. determine to do sth. 决心做某事

    He determined to learn French.

    他下定决心学习法语。

    20. expect to do sth. 等待做某事

    I am expecting to hear from you soon.

    我期待着早点收到你的来信。

    21. fear to do sth. 惧怕做某事

    She fears to live on the mountain.

    她害怕住在山上。

    22. prepare to do sth. 预备做某事

    They prepared to go hiking this Sunday.

    他们准备周日去远足。

    23. pretend to do sth. 伪装做某事

    She pretended not to see me.

    她假装没有看到我。

    24. promise to do sth. 答应做某事

    I have promised to give the children some books.

    我已经答应给孩子们一些书了。

    25. refuse to do sth. 拒绝做某事

    She refused to buy a new cellphone for her boy.

    她拒绝给她儿子买新手机。

    ② 只能加 doing 的动词

    1. practice doing sth. 练习做某事

    I practice playing the piano twice a week.

    我每周练习两次弹钢琴。

    2. consider doing sth. 考虑做某事

    I consider waiting a bit longer before I give up.

    我考虑放弃之前再等待一段时间。

    3. enjoy doing sth. 喜欢做某事

    I enjoy playing basketball.

    我喜欢打篮球。

    4. finish doing sth. 完成做某事

    Let's finish doing the work together.

    让我们一起完成工作吧。

    5. give up doing sth. 放弃做某事

    My father has given up smoking.

    我爸爸已经戒烟了。

    6. imagine doing sth. 想象做某事

    I can't imagine marrying such a woman.

    我不能想象娶了这样一个女人。

    7. keep doing sth. 一直做某事

    I kept studying English for 1 hour yesterday evening.

    昨天晚上,我一直学了1小时英语。

    8. put off doing sth. 推迟做某事

    Sometimes students put off doing their homework until the last minute.

    有时学生们会拖延到最后一分钟才做作业。

    9. risk doing sth. 冒险做某事

    10. suggest doing sth. 建议做某事

    I suggest traveling abroad next month.

    我建议下个月出国旅行。

    11. admit doing sth. 承认做某事

    He admitted making the mistake.

    他承认犯了错误。

    12. advise doing sth. 建议做某事

    He advises going to see a movie.

    他建议去看电影。

    13. allow doing sth. 允许做某事

    We don't allow smoking in the classroom.

    我们不允许在班里吸烟。

    14. appreciate doing sth. 感谢做某事

    We shall appreciate hearing from you again.

    我们恭候佳音。

    15. avoid doing sth. 避免做某事

    Try to avoid drinking and smoking.

    尽量避免喝酒和抽烟。

    16. delay doing sth. 拖延做某事

    Why have you delayed writing to him?

    你为什么迟迟不给他写回信?

    17. deny doing sth. 否认做某事

    John denied signing the contract.

    约翰否认签了合同。

    18. discuss doing sth. 讨论做某事

    I like to discuss doing sports with my friends.

    我喜欢和我朋友讨论体育运动。

    19. dislike doing sth. 不喜欢做某事

    He dislikes dancing in public.

    他不喜欢在公众场合跳舞。

    20. escape doing sth. 逃脱做某事

    He escaped being killed.

    他没有被杀。

    21. excuse doing sth. 原谅做某事

    He can't excuse coming late for work.

    他不能原谅上班迟到。

    22. fancy doing sth. 想象/喜爱做某事

    Are you fancy buying some food with me?

    你愿不愿意和我一起去买点吃的?

    23. forbid doing sth. 禁止做某事

    They forbid parking here.

    他们禁止在这里停车。

    24. mention doing sth. 提及做某事

    He mentioned watching TV.

    他提到了看电视。

    25. mind doing sth. 介意做某事

    Would you mind opening window?

    你介意开窗户吗?

    26. miss doing sth. 错过做某事

    The thief missed being caught yesterday.

    那小偷昨天没能被抓住。

    27. permit doing sth. 允许做某事

    We do not permit smoking in the office.

    在我们的办公室里不准吸烟。

    28. prohibit doing sth. 禁止/阻止做某事

    They prohibit smoking in public.

    他们禁止在公共场合吸烟。

    ③ 既可加to do又可以加doing 的动词,但是含义会发生变化

    1. remember to do sth. 记住要做某事(未做)

    remember doing sth. 记得做过某事(已做)

    Remember to close the door,please.

    记着关门.

    I remember closing the door.

    我记得关了门了.

    2. forget to do sth. 忘记去做某事(未做)

    forget doing sth. 忘记做过某事(已做)

    The light in the office is stil on. He forgot to turn it off.

    办公室的灯还在亮着,他忘记关了.

    He forgot turning the light off.

    他忘记他已经关了灯了.

    3. regret to do sth. 遗憾要做某事(未做)

    regret doing sth. 后悔/抱歉做过某事(已做)

    I regret to tell you that you can't pass the examination.

    我很遗憾地通知你你不能通过这次考试.

    I regret disturbing you so long.

    我很抱歉打扰了你那么久.

    4. try to do sth. 努力做某事

    try doing sth. 尝试做某事

    He tries to get the apple above the shelf. But he fails to reach it.

    After a while, Brown comes in and try showing his ability.

    他努力去够架子上的苹果,但是没能够到。过了一会儿,布朗近来尝试表现他的能力。

    5. mean to do sth. 计划做某事

    mean doing sth. 意味着做某事

    I meant to go, but my father would not allow me to.

    我想去,但是我父亲不肯让我去。

    Doing that means wasting time.

    那样做意味着浪费时间。

    6. can’t help to do sth. 不能帮助做某事

    can’t help doing sth. 情不自禁做某事

    I can't help to do such stupid thing.

    我不能帮着做这样愚蠢的事。

    The movie is so funny. I can't help laughing!

    这部电影如此搞笑。我情不自禁地笑了。

    7. go on to do sth. 继续做另一件事

    go on doing sth. 继续做同一件事

    He went on doing his homework in his room after supper.

    晚饭后他继续在自己的房间里做家庭作业。

    After finishing his homework,he went on to read the text.

    写完家庭作业后,他又继续读课文。

    8. stop to do sth. 停下来去做另一件事

    stop doing sth. 停下正在做的事情

    The two girls stopped talking when they saw me.

    那两个女孩一见到我就停止了讲话。

    The two girls stopped to talk to me when they saw me.

    这两个女孩一看到我就停下来和我讲话。

    文中图片素材来源网络,如有侵权请联系删除

    展开全文
  • HOSPITALNAME VARCHAR2(800) AREA VARCHAR2(30) --query MERGE INTO M_GRP N1 USING M_GROUP E1 ON (N1.NAME=E1.NAME) WHEN MATCHED THEN UPDATE SET N1.HOSPITALNAME=E1.HOSPITALNAME||','||E1.HOSPITALNAME WHEN ...

    Please refine this query if possible

    MERGE INTO M_GRP N1

    *

    ERROR at line 1:

    ORA-38101: Invalid column in the INSERT VALUES Clause: "N1"."HOSPITALNAME"

    SQL> select * from v$version;

    BANNER

    ----------------------------------------------------------------

    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product

    PL/SQL Release 10.2.0.1.0 - Production

    CORE 10.2.0.1.0 Production

    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production

    NLSRTL Version 10.2.0.1.0 - Production

    SQL> desc m_grp

    Name Null? Type

    ----------------------------------------- -------- ---------------------

    MC_CODE VARCHAR2(20)

    NAME VARCHAR2(200)

    ADDRESS VARCHAR2(300)

    CITY VARCHAR2(20)

    STATE VARCHAR2(10)

    ZIP VARCHAR2(10)

    PHONE VARCHAR2(20)

    HOSPITALNAME VARCHAR2(800)

    AREA VARCHAR2(30)

    --query

    MERGE INTO M_GRP N1

    USING M_GROUP E1

    ON (N1.NAME=E1.NAME)

    WHEN MATCHED THEN

    UPDATE SET N1.HOSPITALNAME=E1.HOSPITALNAME||','||E1.HOSPITALNAME

    WHEN NOT MATCHED THEN

    INSERT

    (MC_CODE,NAME,ADDRESS,CITY,STATE,ZIP,PHONE,HOSPITALNAME,AREA)

    VALUES

    (E1.MC_CODE,

    E1.NAME,

    E1.ADDRESS,

    E1.CITY,

    E1.STATE,

    E1.ZIP,

    E1.PHONE,

    TRIM (BOTH ' ' FROM HOSPITALNAME),

    AREA)

    /

    展开全文
  • When Do GNNs Work: Understanding and Improving Neighborhood Aggregation (IJCAI-20)
  • WARNING:tensorflow:Gradients do not exist for variables when minimizing the loss. 情况一 错误写法: 模型forward中计算出 loss1 loss2 返回,然后再计算 losswith tf.GradientTape() as tape: loss1,loss...
  • 1、在kotlin 当中,when 代替Java中的switch语句 但是更强大 更好用主要体现在:1)when子式可以是常量、变量、返回数值的表达式、返回Boolean值的表达式2)可以代替if...else if简单举个栗子????/*** when 的使用*/...
  • just get out your stickers and write up what are the things you want to do and if you can do some of them please do it if you can that is the way you do things
  • beforeafter区别 after的用法

    千次阅读 2020-12-21 21:20:49
    beforeafter区别 after的用法beforeafter区别 after的用法相关问题:匿名网友:一、意思不同1、before作连词意思是在 ... 以前。作介词意思是在 ... 以前;在..前面。作副词意思是以前;以往;之前。2、after作...
  • python运行您的程序时候显示 pwmWrite: Unable to do this when using /dev/gpiomem. Try sudo? 产生原因是:使用Thonnypathon时候没有加root权限 项目场景: 树莓派使用wiringpi python库时候报错 问题描述: ...
  • kernel_shapes = (input_units, self.output_units) self.kernel_real = self.add_weight(shape=kernel_shapes, initializer=self.kernel_initializer_real, name='kernel_real', .
  • 基于case when的常用查询 1.导入数据集 CREATE TABLE orders( Uid CHAR(7), Birthday DATE, Order_Date DATETIME, Order_Id VARCHAR(15), Pay_Type TINYINT,#1,3,5,7,10代表微信支付;6,9,10代表快捷支付;2,4,8,11...
  • 我正在尝试在调用最终的void方法时执行doNothing(),但doNothing()调用却在调用实际方法。SwitchWorker类public class SwitchWorker {public boolean switchMethod(String id){this.methodA(id);return true;}public...
  • call和called的区别和用法

    千次阅读 2020-12-22 00:23:02
    匿名用户1级2018-11-06 回答1、calledcall都是同源单词,called可以看做是call的派生词,二者意思相近,形式用法都不同,即called是call的过去式或过去分词形式。2、call的用法call既可用作动词,又可用作名词。...
  • 在细节上,体现编程的修养。每一位大师,master,其基础必定夯实。...源表(Source Table)靶表(Targe Table)的数据行能够匹配成功,这意味着on子句和when match条件都被满足,进入到when matche...
  • Spring单元测试中@SpyBean@MockBean区别 1、默认行为不同 对于没有用Mockito代理的方法,@SpyBean会调用真实的方法,有返回值的会返回方法的真实返回值(参考下方SpyBeanTest的testException4)。 @MockBean不管...
  • cancouldmaymight的用法有什么区别

    千次阅读 2020-12-24 03:05:20
    Can只有一般现在时一般过去式;而be able to则有更多的时态。 I’ll not be able to come this afternoon. 当表示“经过努力才得以做成功某事”时应用be able to,不能用Can。如: He was able to go to the party...
  • c语言宏定义中#,##和do{}while(0)的用法

    千次阅读 2021-05-23 06:35:21
    1、前言今天看代码时候,遇到一些宏,之前没有见过,感觉挺新鲜。如是上网google一下,顺便总结一下,方便以后学习运用。...(1)宏中包含特殊符号:#、##.(2)宏定义用do{ }while(0)2、特殊符号#、##(...
  • I'm following this guide: Spring MVC and I realized that I do not know the difference between a source folder (src) and a plain folder.I'm using eclipse, so maybe the difference is only useful in an I...
  • I am writing a procedure in which i have sql statement which will insert values in TEMP_WF_WORKFLOW table using CASE WHEN statement. The condition is when STATUS_ID is 0 then the EVENT_ID=10003 and wh...
  • 在本文中,我们通过一些通俗易懂的方式来解释异步编程多线程编程,然后再介绍一下它们之间的区别。 什么是异步编程 首先来看一下异步模型。在异步模型中,允许同一时间发生(处理)多个事件。程序调用一个耗时较长...
  • ExcelVBA的Do,while语句

    2021-05-09 12:37:31
    Do While循环条件
  • Golang makenew的区别详解

    千次阅读 2020-12-26 15:28:18
    Golang makenew的区别详解
  • Normally, I would do that by just invoking: // we already did an "import static org.mockito.Mockito.*" when(mockDescriptor.getPropertyType()).thenReturn(String.class); However, oddly, this does not ...
  • Nonverbal (非语言的) communication has to do with gestures, movements and closeness of two people when they are talking. (78) The scientists say that those gestures, movements and so on have meaning ...
  • What Do Neural Networks Learn When Trained With Random Labels?Abstract When Trained With Random Labels?) 内容整理自What Do Neural Networks Learn When Trained With Random Labels?. Abstract an ...
  • class Main{ public void test(){ } } public void mock() { Main main = mock(Main.class); doNothing().when(main).test(); }
  • I'm trying to order contacts in table and I'm facing some problems, I found a nice solution in this SO question, maybe it's an over kill for this, but I'm trying to do this over restapi so I'm only af...
  • 相信同学们每次遇到选填to do, doing还是do形式的题目时,脑海中的反应大概都是“to do好像通,不对,应该是doing,还是填原形do呢”?今天帮小飞为你总结了初中阶段高频出现的一些动词用法,让你从此告别看到to do,...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 543,665
精华内容 217,466
关键字:

when和do的区别