小编Cyb*_*bex的帖子

定义USE(x)(x)=(x)

在其中一个C源代码文件中,我找到了以下行(宏):

#define USE(x) (x) = (x)
Run Code Online (Sandbox Code Playgroud)

它是这样使用的:

int method(Obj *context)
    {
    USE(context);
    return 1;
    }
Run Code Online (Sandbox Code Playgroud)

谷歌搜索后,我发现了以下描述:

//宏来摆脱一些编译器警告

你能告诉我更多关于这个宏的信息吗?

谢谢你的回答!

c c-preprocessor

6
推荐指数
3
解决办法
471
查看次数

在 Spring Boot 应用程序的 @Transactional 方法中调用 flush()

在@Transactional 方法中间调用Hibernate flush() 是否有可能将不完整的结果保存在数据库中?例如,这个函数是否有可能将“John”保存到数据库中?

@Transactional
public void tt() {
    Student s = new Student("John");
    em.persist(s);
    em.flush();
    // Perform some calculations that change some attributes of the instance
    s.setName("Jeff");
}
Run Code Online (Sandbox Code Playgroud)

我用 H2 内存数据库尝试过它,它没有保存不完整的事务更改。但是在某些条件下是否可能并且可能使用另一个数据库引擎?

java sql spring hibernate jpa

5
推荐指数
1
解决办法
1万
查看次数

如何使用 AssertJ 验证静态方法抛出异常?

当我尝试测试此方法时

    static void validatePostcode(final String postcode, final String addressLine)
    {
        if(! hasValidPostcode(postcode, addressLine)) {
            throw new InvalidFieldException("Postcode is null or empty ");
        }
    }
Run Code Online (Sandbox Code Playgroud)

使用以下测试

    @Test
    public void testThrowsAnException()
    {
        assertThatThrownBy(validatePostcode("", "")).isInstanceOf(InvalidFieldException.class);
    }
Run Code Online (Sandbox Code Playgroud)

我在 IntelliJ 中收到此错误消息

断言中的 assertThatThrownBy (org.assertj.core.api.ThrowableAssert.ThrowingCallable) 不能应用于 (void)

 
assertThatExceptionOfType.

是否可以使用 AssertJ 测试该静态方法实际上引发了未经检查的异常?我应该在考试中改变什么?

java static unit-testing exception assertj

5
推荐指数
1
解决办法
2224
查看次数

Logger.getLogger(class_name.class.getName())导致NullPointerException

问题是Logger没有使用Logger.getLogger(class_name.class.getName())方法初始化 .你可以看到下面的代码.我标记了导致异常的行.我必须注意,我也试过没有静态setLevel块.

// File that contains logger
public class Experience {

private final static Experience INSTANCE = new Experience(); 
private final static Logger LOGGER = Logger.getLogger(Experience.class.getName());

private MainFrame main_frame;

static {
    LOGGER.setLevel(Level.SEVERE);
    }

public static Experience getInstance()
    {
    return INSTANCE;
    }

private Experience()
    {
    try
        {
        FileHandler fh = new FileHandler(System.getProperty("user.dir") + "/log.txt");
        fh.setFormatter(new XPLogFormatter());
        LOGGER.addHandler(fh); // NULLPOINTEREXCEPION HERE
        }
    catch (Exception e)
        {
        e.printStackTrace();
        }
    }
}


// Just a loader
public class Loader
{ …
Run Code Online (Sandbox Code Playgroud)

java logging static

0
推荐指数
1
解决办法
6162
查看次数

标签 统计

java ×3

static ×2

assertj ×1

c ×1

c-preprocessor ×1

exception ×1

hibernate ×1

jpa ×1

logging ×1

spring ×1

sql ×1

unit-testing ×1