Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: How to create a List value comparison test Java?

  1. #1
    Junior Member
    Join Date
    Aug 2020
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to create a List value comparison test Java?

    I have a DTO class where they have a mapping using functional foreach.

    What is the best way to test them?

    Follow the method below:

    public static BlockSaldDeb convertCred(MapExec mapExec) {
     
    mapExec.getBlock().forEach(b -> {
                BlockMapExec blockCred = (BlockMapExec) b;
                List<LancCred> listCred = new ArrayList<>();
                List<LancDeb> listDeb = new ArrayList<>();
                blockCred.getOp().forEach(op -> {
                    if (op.getTypeOp().equals(TypeOp.CRED)) {
                        LancCred lancCred = LancamentoCredito.newBuilder()
                                .setNumberContPart(op.geNumberContPart().toString())
                                .setNameLancCont("C")
                                .setValueLanc(op.getValue().doubleValue())
                                .build();
                        listCred.add(lancCred);
                    } else if (op.getTypeOp().equals(TypeOp.DEB)) {
                        LancDeb lancDeb = LancDeb.newBuilder()
                                .setNumberContPart(operacao.getNumberContPart().toString())
                                .setNameLancCont("D")
                                .setValueLanc(op.getValue().doubleValue())
                                .build();
                        listDeb.add(LancDeb);
                    }
                });
    return...
    }

    The test case I need is to compare whether the set is the same as the get.

    I am new to unit testing and I will be very grateful for your help.
    Last edited by devrfd; August 25th, 2020 at 09:46 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to create a List value comparison test Java?

    compare whether the set is the same as the get.
    Please explain what that is supposed to test.
    A set method passes a value to a class, a get method retrieves a value from a class.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2020
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to create a List value comparison test Java?

    Quote Originally Posted by Norm View Post
    Please explain what that is supposed to test.
    A set method passes a value to a class, a get method retrieves a value from a class.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Edit done. Thank you.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to create a List value comparison test Java?

    compare whether the set is the same as the get.
    I don't understand your question. Can you explain what that is supposed to test.
    A set method passes a value to a class, a get method retrieves a value from a class.
    They are not the same.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Aug 2020
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to create a List value comparison test Java?

    Quote Originally Posted by Norm View Post
    I don't understand your question. Can you explain what that is supposed to test.
    A set method passes a value to a class, a get method retrieves a value from a class.
    They are not the same.
    What I'm trying to test is the value of each block in the collection.
    The set values ​​of the LancCredito class will be the values ​​of the OpMapBlockExec class that is part of the BlockMapExec class.

    I want to compare them, understand?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to create a List value comparison test Java?

    trying to test is the value of each block in the collection
    Sorry, I do not know what you mean by a "block". Do you mean an instance of some class? What class?
    Where is the collection? What class is it?
    How does the OpMapBlockExec class or LancCredito class relate to the question? I do not see any references to them in the code.

    Where are the get and set methods you want to compare?

    None of this makes any sense to me.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Aug 2020
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to create a List value comparison test Java?

    Quote Originally Posted by Norm View Post
    Sorry, I do not know what you mean by a "block". Do you mean an instance of some class? What class?
    Where is the collection? What class is it?
    How does the OpMapBlockExec class or LancCredito class relate to the question? I do not see any references to them in the code.

    Where are the get and set methods you want to compare?

    None of this makes any sense to me.
    Well, this is my class
    MapExec that is related to the BlockMapExec class that is related to the OpBlockMapExec class:

    public class MapExec implements Maps {
    private List<BlockMapExec > blocks;
     
    @Override
        public List<Block> getBlocks() {
     
            return blocks.stream().map(Block.class::cast).collect(Collectors.toList());
        }
    }
     
    public class BlockMapExec implements Block {
    private List<OpBlockMapExec> op;
     
    }
     
    public class OpBlockMapExec {
        private UUID numberContProd;
        private String codProd;
        private UUID numberContPart;
        private String codProdContPart;
        private String codTypeOp;
        private BigDecimal value;
        private TypeOp typeOp;
    }

    I browse the collection to get the OpBlockMapExec values.
    The LancCred class values ​​are converted to the OpBlockMapExec class values.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to create a List value comparison test Java?

    Where are the get and set methods you want to "compare"?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Aug 2020
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to create a List value comparison test Java?

    Quote Originally Posted by Norm View Post
    Where are the get and set methods you want to "compare"?
    They are in the LancCred class.

    I do one (from-to)


    Example:
    lancCred.setNumberContPart(op.getNumberContPart();

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to create a List value comparison test Java?

    How do you want to compare them? They do completely different things.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Aug 2020
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to create a List value comparison test Java?

    Quote Originally Posted by Norm View Post
    How do you want to compare them? They do completely different things.
    I would like to take them to an assert test case.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to create a List value comparison test Java?

    Sorry, I do not know anything about assert test cases. Try asking this question on this forum:
    http://www.coderanch.com/forums

    https://coderanch.com/t/733910/java/...ison-test-Java
    If you don't understand my answer, don't ignore it, ask a question.

  13. The Following User Says Thank You to Norm For This Useful Post:

    devrfd (August 25th, 2020)

Similar Threads

  1. How to create an Unitary Test for this code block?
    By vortex in forum Computer Support
    Replies: 1
    Last Post: July 27th, 2020, 09:49 AM
  2. How to create a unmodifiable/read-only list in Java?
    By james12 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 2nd, 2014, 02:09 AM
  3. Replies: 3
    Last Post: October 5th, 2013, 09:14 AM
  4. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  5. Replies: 0
    Last Post: February 3rd, 2009, 01:15 AM

Tags for this Thread